将回归方程和R2,pvalue添加到R中的此代码

时间:2019-06-25 16:07:17

标签: r ggplot2 graph equation

我的数据是:

df <- data.frame(y, ind1, Ind2)
dput(head(df))

structure(list(y = c(17.5460928, 15.09292512, 404.6266803, 509.8268418, 
22.29624608, 27.62826976, 15.62685944, 28.1327364, 21.80956416, 
17.6183345, 23.11261875, 454.8629825, 277.3728927, 6.69668148, 
18.13138523, 9.960903315, 19.41601536, 45.57917108, 424.4031894, 
53.88895104), ind1 = c(0.003739281, 0.003473227, 0.096486361, 
0.124097819, 0.005281017, 0.005089576, 0.003019071, 0.00657555, 
0.003959192, 0.003318307, 0.004417865, 0.105784493, 0.078675101, 
0.001288249, 0.003525652, 0.001924422, 0.004071504, 0.008824734, 
0.100098211, 0.016286016), ind2 = c(0.20708766, 0.216378894, 
0.628712871, 0.505681818, 0.318622945, 0.245192308, 0.237227283, 
0.193723291, 0.185897436, 0.459722222, 0.517696729, 0.495145631, 
0.32820499, 0.229536789, 0.066927991, 0.061670358, 0.083333333, 
0.190874286, 0.37745098, 0.34897506)), row.names = c(NA, 20L), class = 
"data.frame")

logy <- log(df$y)
logind1 <- log(df$ind1)
logind2 <- log(df$ind2)

我在此站点上找到了以下代码来创建情节。

 mod <- lm(logy ~ logind1 + logind2) 
 summary(mod)

 mod.predict <- cbind(data, predict(mod, interval = 'confidence'))

 p <- ggplot(mod, aes(logind1 + logind2,logy))
 p <- p + geom_point()
 p <- p + geom_line(aes(logind1 + logind2, fit))
 p <- p + geom_ribbon(aes(ymin=lwr, ymax=upr), alpha=0.3)
 p

现在,我想将预测线与方程式以及R2和Pvalue一起添加。 任何帮助将不胜感激!

谢谢

0 个答案:

没有答案