[英]MM robust estimation in ggplot2 using stat_smooth with method = “rlm”
函數rlm(MASS)允許M和MM估計用於穩健回歸。 我想在ggplot2中繪制來自MM穩健回歸的平滑器,但是我認為在stat_smooth中選擇method =“rlm”時,自動選擇的估計方法是M類型。
有沒有辦法通過ggplot2為rlm函數選擇MM類型估計技術?
這是我的代碼:
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)
我已經用rlm摘要本身檢查了結果,我很確定ggplot2正在使用(默認?)M估計。
如何使用rlm函數中的MM估計?
rlm(formula, ...,method = "MM")
提前謝謝了!
不幸的是, stat_smooth
和rlm
都有一個method
參數。 這讓它變得有點困難:
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.