【问题标题】:obtaining regression coefficients from qplot [duplicate]从 qplot 获取回归系数
【发布时间】:2013-11-28 23:45:45
【问题描述】:

我正在使用 qplot 绘制并拟合我的数据的斜率:

qplot(log(X),log(Y),geom=c("point","smooth"),method="gam",formula=y~ns(x,2))

它工作正常。但是如何获得绘制的回归斜率的系数?我知道我可以明确地使用例如 nls 来获得斜率。尽管如此,我想知道斜率 qplot 适合我的数据。我很感激任何建议。

【问题讨论】:

标签: r ggplot2 regression


【解决方案1】:

这个怎么样:

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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 2023-03-22
    • 2011-09-28
    相关资源
    最近更新 更多