[英]How do I add a regression line equation to plot?
I am trying to add regression line equation, R square and P value to my plot, any thoughts on how I can do it? 我正在尝试向绘图添加回归线方程式,R平方和P值,对此我有何想法?
Here is the code that I am using in R: 这是我在R中使用的代码:
plot<- plot(Q,CALCIUM.DISSOLVED)
fit<-(lm(CALCIUM.DISSOLVED ~ Q))
abline (fit)
Using the data set cars 使用数据集汽车
m <- lm(dist ~ speed, data = cars)
plot(dist ~ speed,data = cars)
abline(m, col = "red")
Here we use summary() to extract the R-squared and P-value. 在这里,我们使用summary()提取R平方和P值。
m1 <- summary(m)
mtext(paste0("R squared: ",round(m1$r.squared,2)),adj = 0)
mtext(paste0("P-value: ", format.pval(pf(m1$fstatistic[1], # F-statistic
m1$fstatistic[2], # df
m1$fstatistic[3], # df
lower.tail = FALSE))))
mtext(paste0("dist ~ ",round(m1$coefficients[1],2)," + ",
round(m1$coefficients[2],2),"x"),
adj = 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.