Multiple linear regression for groups of columns

Viewed 74

I have a df with individuals id in the 1st col, a response variable (grain yield) in the 2nd col and the following columns are markers data

id yield Snp1 Snp2 Snp3 Snp4 Snp5 Snp6
id1 4.5   2    2    0    2    0    2
id2 4.2   0    2    2    2    2    2
id3 4.1   0    2    2    2    2    0
id4 4.9   2    0    0    0    2    0
id5 5.4   0    0    2    2    0    2
id6 3.9   2    2    0    2    0    0

What I want to do is to fit a linear model in R with the effect of two groups of Snps, for example: the first group is Snp1 + Snp2 and the second group is Snp4 + Snp5 I don't know how to write the code, but my idea is the following:

model <- lm ( yield~ (group1) + (group2)

Thanks in advance.

1 Answers

If what you mean is you want to compare regressing group1 to regressing all columns then try this (and similarly for group2):

fm0 <- lm(yield ~., DF[-1])
fm1 <- lm(yield ~ Snp1 + Snp2, DF)
anova(fm1, fm0)

Note

Input in reproducible form:

Lines <- "id yield Snp1 Snp2 Snp3 Snp4 Snp5 Snp6
id1 4.5   2    2    0    2    0    2
id2 4.2   0    2    2    2    2    2
id3 4.1   0    2    2    2    2    0
id4 4.9   2    0    0    0    2    0
id5 5.4   0    0    2    2    0    2
id6 3.9   2    2    0    2    0    0"
DF <- read.table(text = Lines, header = TRUE)
Related