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

喜欢而已 提交于 2019-12-06 06:08:34

问题


The function rlm (MASS) permits both M and MM estimation for robust regression. 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.

Is there any way of selecting the MM type estimation technique for the rlm function through ggplot2?

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.

How can I use the MM estimation from the rlm function?

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

Many thanks in advance!


回答1:


Unfortunately both stat_smooth and rlm have a method parameter. 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)


来源:https://stackoverflow.com/questions/17487418/mm-robust-estimation-in-ggplot2-using-stat-smooth-with-method-rlm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!