生信人

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

0

收听

12

听众

279

主题
发表于 2022-9-4 22:01:44 | 查看: 647| 回复: 0
一、线性回归
       回归 regression,通常指那些用一个或多个预测变量,也称自变量或解释变量,来预测响应变量,也称为因变量、效标变量或结果变量的方法。
       回归分析的各种变体
      
  1. #简单线性回归  
  2. rm(list = ls())
  3. women  
  4. plot(women)
  5. plot(women$height,women$weight,type = 'l')
  6. fit <- lm(weight ~ height,data=women)  
  7. fit  
  8. summary(fit)  
  9. plot(fit)
  10. fitted(fit)
  11. resid(fit)
  12. newdata <- data.frame(height=c(73,60))
  13. predict(object = fit,newdata = newdata)
复制代码
      如何写回归公式?
       R表达式中常用的符号
      
       上面是简单的示例数据,下面介绍多元线性回归,使用state.x77数据。
  1. #谋杀率案例  
  2. states <- as.data.frame(state.x77)  
  3. colnames(states)
  4. fit <- lm(Murder ~ Population + Income + Illiteracy + `Life Exp` + `HS Grad` + Frost + Area,data=states)  
  5. summary(fit)
  6. fit1 <- lm(Murder ~ Population + `Life Exp`,data=states)  
  7. summary(fit1) #调整变量达到R方0.85以上即可,但过拟合拿到新的数据可能也验证不了
复制代码


二、基因组大小与基因个数线性回归
      
       基因组大小与基因数目线性关系
  1. #基因组大小与基因个数线性回归
  2. rm(list = ls())
  3. x <- read.csv("prok_representative.csv")
  4. head(x)
  5. plot(x$Size,x$Genes,pch = 16,cex = 0.8)
  6. attach(x)
  7. fit <- lm(Genes ~ Size,data = x)
  8. fit
  9. summary(fit)
  10. plot(x$Size,x$Genes,pch = 16,cex = 0.8,
  11.      xlab="Genome Size",ylab="Gene Numbers",main = 'Genomesize with Gene Numbers')
  12. abline(fit,col="blue")
  13. text(3.5,10000,label = 'y=843.7x+286.6 \n R2=0.9676')
  14. x[x$Size>15,]
  15. x[x$Size<5 &x$Genes>6000,]
  16. text(7,3000,labels='Corynebacterium striatum')
  17. text(2,7000,labels='Candidatus Burkholderia kirkii UZHbot1')
  18. #保存pdf后用adobe修改。
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|生信人

GMT+8, 2024-5-7 07:20 , Processed in 0.046870 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表