大通評論,實際lmodel2()
代碼,並且使用將是有益的ggplot
代碼。但這裏的,可能你指出正確方向邁出的例子:
dat <- data.frame(a=log10(rnorm(50, 30, 10)), b=log10(rnorm(50, 20, 2)))
mod <- lmodel2(a ~ b, data=dat,"interval", "interval", 99)
#EDIT: mod is a list, with components (data.frames) regression.results and
# confidence.intervals containing the intercepts+slopes for different
# estimation methods; just put the right values into geom_abline
ggplot(dat,aes(x=b,y=a)) + geom_point() +
geom_abline(intercept=mod$regression.results[4,2],
slope=mod$regression.results[4,3],colour="blue") +
geom_abline(intercept=mod$confidence.intervals[4,2],
slope=mod$confidence.intervals[4,4],colour="red") +
geom_abline(intercept=mod$confidence.intervals[4,3],
slope=mod$confidence.intervals[4,5],colour="red") +
xlim(c(-10,10)) + ylim(c(-10,10))
全面披露:我什麼都不知道RMA的迴歸,所以我只是想出來的培訓相關的斜率和截距,一屁股它們變成geom_abline()
,使用一些示例代碼作爲指導從lmodel2
。在這個玩具示例中生成的配置項似乎沒什麼意義,因爲我必須使用xlim()
和ylim()
來強制ggplot縮小以查看配置項線(紅色)。
但也許這會幫助你在ggplot()
構建一個工作示例。
EDIT2:使用OPS添加的代碼來提取係數,該ggplot()
會是這樣的:
ggplot(dat,aes(x=b,y=a)) + geom_point() +
geom_abline(intercept=fit2[1,1],slope=fit2[2,1],colour="blue") +
geom_abline(intercept=fit2[1,2],slope=fit2[2,2],colour="red") +
geom_abline(intercept=fit2[1,3],slope=fit2[2,3],colour="red")
請添加您正在使用的'lmodel2()'的代碼。 – Chase 2011-05-23 21:54:56