简体   繁体   English

使用stat_smooth with method =“rlm”在ggplot2中进行MM稳健估计

[英]MM robust estimation in ggplot2 using stat_smooth with method = “rlm”

The function rlm (MASS) permits both M and MM estimation for robust regression. 函数rlm(MASS)允许M和MM估计用于稳健回归。 I would like to plot the smoother from MM robust regression in ggplot2, however I think that when selecting method = "rlm" in stat_smooth, the estimation method automatically chosen is the M type. 我想在ggplot2中绘制来自MM稳健回归的平滑器,但是我认为在stat_smooth中选择method =“rlm”时,自动选择的估计方法是M类型。

Is there any way of selecting the MM type estimation technique for the rlm function through ggplot2? 有没有办法通过ggplot2为rlm函数选择MM类型估计技术?

Here is my code: 这是我的代码:

df <-  data.frame("x"=c(119,118,144,127,78.8,98.4,108,50,74,30.4,
50,72,99,155,113,144,102,131,105,127,120,85,153,40.6,133),
"y"=c(1.56,2.17,0.81,1.07,1.12,2.03,0.90,1.48,0.64,
0.91,0.85,0.41,0.55,2.18,1.49,1.56,0.82,0.93,0.84,1.84,
0.78,1.15,3.85,3.30,0.94))      

library(ggplot2)
library(MASS)      

ggplot(df,aes(x=x,y=y))+geom_point()+
stat_smooth(method="rlm",fullrange=TRUE)+xlim(0,160)

I have checked the results with the rlm summary itself, and I am pretty sure ggplot2 is using the (default?) M estimation. 我已经用rlm摘要本身检查了结果,我很确定ggplot2正在使用(默认?)M估计。

How can I use the MM estimation from the rlm function? 如何使用rlm函数中的MM估计?

rlm(formula, ...,method = "MM")

Many thanks in advance! 提前谢谢了!

Unfortunately both stat_smooth and rlm have a method parameter. 不幸的是, stat_smoothrlm都有一个method参数。 That makes it a bit harder: 这让它变得有点困难:

ggplot(df,aes(x=x,y=y)) +
  geom_point() +
  stat_smooth(method=function(formula,data,weights=weight) rlm(formula,
                                                               data,
                                                               weights=weight,
                                                                method="MM"),
              fullrange=TRUE) +
  xlim(0,160)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM