使用具有方法=“rlm”的stat_smooth的ggplot2中的MM鲁棒估计。 [英] MM robust estimation in ggplot2 using stat_smooth with method = "rlm"

查看:360
本文介绍了使用具有方法=“rlm”的stat_smooth的ggplot2中的MM鲁棒估计。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数rlm(MASS)允许M和MM估计用于鲁棒回归。我想在ggplot2中绘制MM稳健回归的平滑图,但我认为当在stat_smooth中选择method =rlm时,自动选择的估计方法是M类型。



是否有任何方法通过ggplot2为rlm函数选择MM类型估计技术?



以下是我的代码:

  df < -  data。 (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)

我已经用rlm摘要本身检查了结果,我很确定ggplot2正在使用(默认值?)M估计值。



如何能我使用rlm函数中的MM估计值吗?

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ rlm(公式,...,method =MM)

非常感谢您!

解决方案

不幸的是, stat_smooth rlm 都有一个方法参数。这使得它有点难:

  ggplot(df,aes(x = x,y = y))+ $ b $ (公式,数据,权重=权重)rlm(公式,
数据,
权重=权重,
方法=MM)b geom_point()+
stat_smooth ),
fullrange = TRUE)+
xlim(0,160)


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!

解决方案

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)

这篇关于使用具有方法=“rlm”的stat_smooth的ggplot2中的MM鲁棒估计。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆