我正在使用qplot绘制斜率,并将其拟合到我的数据中:
qplot(log(X),log(Y),geom=c("point","smooth"),method="gam",formula=y~ns(x,2))它工作得很好。但是如何得到绘制的回归斜率的系数呢?我知道我可以显式地使用nls得到斜率。尽管如此,我还是想知道什么斜率qplot适合我的数据。我很感谢你的建议。
发布于 2013-11-28 23:22:22
这样如何:
g<-qplot(log(X),log(Y),geom=c("point","smooth"))
lookinside<-ggplot_build(g)$data[[2]]
smooth<-data.frame(cbind(x=lookinside$x,y=lookinside$ymax-lookinside$ymin))
lm(smooth$x~smooth$y)
Call:
lm(formula = smooth$x ~ smooth$y)
Coefficients:
(Intercept) smooth$y
1.25482 0.06275
qplot(smooth$x,smooth$y)+geom_abline(intercept=1.25482,slope=0.06275,color="red")

https://stackoverflow.com/questions/20268234
复制相似问题