【问题标题】:Multiple linear regression using SNPs [duplicate]使用 SNP 的多元线性回归
【发布时间】:2015-05-28 13:35:50
【问题描述】:

我有 40 个 SNP,想了解每个 SNP 对绝经年龄的影响。为此,我需要对每个单独的 SNP 进行多元线性回归。我想避免输入相同的命令 40 次不同的时间(因为将来我会用更多的 SNP 来做这个)。

我想要做的是在csv 文件中列出 SNP,并将其命名为x

x <- read.csv("snps.csv")

那我想在这个命令中使用这个列表;

fit <- lm(a_menopause ~ "snps" + country, data=mydata)

snps 是我需要分析的 SNP 列表,但需要一次完成一个 SNP。理想情况下,我希望将结果打印到 csv 文件中。

【问题讨论】:

  • 为什么需要单独的模型?将所有内容组合到一个模型中。
  • 我需要查看每个 SNP 对绝经年龄的影响
  • 循环遍历列表并为每个x 拟合一个模型,如果需要不同的截距
  • 嗨 6pool 感谢您的回答。我不完全确定我该怎么做。到目前为止,我得到的是一个包含我的 SNP(以及这些变量的数据)的 csv 文档。我将其命名为 snps。然后我做了 > varlist
  • 请联系统计学家。

标签: r regression linear-regression bioinformatics lm


【解决方案1】:

见下例:

#dummy data
set.seed(123)
#phenotype
phenotype <- data.frame(
  a_menopause=sample(c(0,1),10,replace=TRUE),
  country=sample(letters[1:3],10,replace=TRUE))
#genotype
genotype <- 
read.table(text="SNP1   SNP2    SNP3    SNP4
1   0   1   1
           2    0   2   1
           0    0   0   1
           0    0   0   1
           0    1   0   1
           1    1   0   1
           1    2   0   1
           1    2   1   2
           0    0   0   1
           0    1   0   1
           ",header=TRUE)
#data for lm
fitDat <- cbind(phenotype,genotype)

#get fit for all SNPs
fitAllSNPs <-
  lapply(colnames(fitDat)[3:6], function(SNP){
    fit <- lm(paste("a_menopause ~ country + ", SNP), 
              data=fitDat)
    })

#extract coef for each SNP
lapply(fitAllSNPs,coef)

#output
# [[1]]
# (Intercept)      countryb      countryc          SNP1 
# 1.000000e+00 -2.633125e-16 -1.000000e+00  9.462903e-17 
# 
# [[2]]
# (Intercept)      countryb      countryc          SNP2 
# 1.000000e+00 -1.755417e-16 -1.000000e+00  2.780094e-19 
# 
# [[3]]
# (Intercept)      countryb      countryc          SNP3 
# 1.000000e+00 -2.633125e-16 -1.000000e+00  1.079985e-16 
# 
# [[4]]
# (Intercept)      countryb      countryc          SNP4 
# 1.000000e+00 -1.755417e-16 -1.000000e+00  4.269835e-31 

【讨论】:

    猜你喜欢
    • 2019-01-30
    • 2020-10-09
    • 2010-11-23
    • 2013-07-17
    • 2014-05-20
    • 1970-01-01
    • 2018-08-11
    • 2013-07-14
    • 2016-04-19
    相关资源
    最近更新 更多