写在前面回归,是我们经常用到的分析手段,对于结果的确定比差异分析和相关分析都要更加深入,所以无论是大小文章,都可以看到回归的影子。 今天我来带大家,仅仅需要一条代码,就将这个分析做的透明,透彻,审稿人无话可说。 今天我会将方程,回归系数,p值都计算出来。 载入需要的R包require(ggplot2) require(reshape2) library(dplyr) 开始分析作图data(mtcars2)
iris_groups<- group_by(mtcars2, variable)
df_summarise<- summarise(iris_groups, mean(mpg), mean(value))
lab = mean(mtcars2$mpg)
#----我们使用的都是同样的y做相关,所以呢都是相同的 ggplot2::ggplot(mtcars2,aes(value,mpg, colour=variable)) + ggplot2::geom_point() + ggpubr::stat_cor(label.y=lab*1.1)+ ggpubr::stat_regline_equation(label.y=lab) + facet_wrap(~variable, scales="free_x") + geom_smooth(aes(value,mpg, colour=variable), method=lm, se=T)+ theme_grey() 如果你有余力,请阅读下面自定义回归如何做##模拟数据 set.seed(20160227) x<-seq(0,50,1) y<-((runif(1,10,20)*x)/(runif(1,0,10)+x))+rnorm(51,0,1)
data = data.frame(x = x,y = y)
#自定义函数 m<-nls(y ~ a*(1-exp(1)^(-k*x)),start=c(a=30,k=20)) m
#评估模式适合度 cor.test(y,predict(m))
cor(y,predict(m)) a = 12.43 k = 0.1095 欢迎加入微生信生物这就是你认识的微生信生物微生信生物
|