简体   繁体   English

ggplot2:如何获取回归线方程的值r ^ 2和p值?

[英]ggplot2: how to get values for the regression line equation, r^2 and p value?

I cant work out how to get the regression line equation, r^2 and p value of the linear regression I have plotted using the function geom_smooth. 我无法解决如何使用函数geom_smooth绘制线性回归的回归线方程,r ^ 2和p值。

This is my code: 这是我的代码:

   g <- ggplot(data=data.male, aes(x=mid_year, y=mean_tc, colour=data.male$survey_type))  
   g <- g + geom_point(shape = 20, size =2) 
   g <- g + geom_smooth(method=lm, na.rm = FALSE, se = TRUE, aes(group=1), colour = "black")
   g <- g + theme_gray(base_size=24)
   g <- g+ xlab("Year")
   g <- g + ylab("Mean serum total cholesterol (mmol/L)")
   g <- g + theme(legend.position="bottom")
   g <- g + scale_y_continuous(limits=c(3.5,6.5), breaks=c(3.5,4,4.5,5,5.5,6,6.5))
   g <- g + scale_x_continuous(limits=c(1980,2015), breaks=c(1980,1990,2000,2010))
   g <- g + scale_colour_manual(name = "Survey Type", values= c("Red", "Blue", "Green")) 
   g  

[1]: [1]:

Don't use a plotting function for modelling. 不要使用绘图功能进行建模。 Fit the model using the lm function. 使用lm函数拟合模型。

Then use the summary method to get everything you need to know about the fit. 然后使用summary方法来获取您需要了解的有关拟合的所有信息。

You should get the same results as the plotting function, which I suspect uses lm internally. 您应该得到与绘图函数相同的结果,我怀疑该函数在内部使用lm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM