# Can I combine two linear models to show which group fits data best?

I am examining the correlation of the expression data of two genes MC1 and fs3. My hypothesis is that this correlation is happening only in 1 of the two groups that I have (group G and S). When I checked this using two different models:

fitMs = lm(MC1 ~ fs3, family=gaussian, data=delta.CT.midguts)
fitMg = lm(MC1 ~ fs3, family=gaussian, data=delta.CT.midgutg)


I can see that the fitMs is significant while the other one is not:

> summary(fitMs)
Call:
lm(formula = MC1 ~ fs3, data = delta.CT.midguts, family = gaussian)

Residuals:
Min       1Q   Median       3Q      Max
-2.22812 -0.78914  0.06421  0.77183  1.41686

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.46467    0.25809   1.800   0.0849 .
ftsZ         0.15311    0.06269   2.442   0.0227 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.006 on 23 degrees of freedom
Multiple R-squared:  0.2059,    Adjusted R-squared:  0.1714
F-statistic: 5.965 on 1 and 23 DF,  p-value: 0.02269

> summary(fitMg)
Call:
lm(formula = MC1 ~ fs3, data = delta.CT.midgutg, family = gaussian)

Residuals:
Min      1Q  Median      3Q     Max
-3.9630 -0.5302  0.5535  1.0180  2.7349

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.99889    0.46146   2.165    0.041 *
ftsZ         0.13981    0.09702   1.441    0.163
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.755 on 23 degrees of freedom
Multiple R-squared:  0.08281,   Adjusted R-squared:  0.04293
F-statistic: 2.076 on 1 and 23 DF,  p-value: 0.1631


Something that I can also see with the AIC where the value for the fitMs (group S) is way lower than the fitMg.

Can I combine the above 2 models in one or compare them in a different way in order to show that somehow? That the correlation only works for the S group but not for the G group?

• What do you mean when you say "the correlation works"? – Michael R. Chernick Dec 24 '16 at 20:23
• sorry, I meant that the correlation between MC1 and fs3 values is significant (p=0.022) – Panos Sapou Dec 24 '16 at 20:31

I am not sure if this is what you are looking for but you can check to see if the groups are significant by doing this:

t <- read.csv("test.csv", header = TRUE)
t$group.f <- as.factor(t$group)
m1 <- lm(MC1 ~ fs3 + group.f, t)
summary(m1)


Output:

Call:
lm(formula = MC1 ~ fs3 + group.f, t)

Residuals:
Min      1Q  Median      3Q     Max
-3.9746 -0.7216  0.2475  0.9496  2.7281

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.01700    0.33583   3.028  0.00399 **
fs3          0.14567    0.05852   2.489  0.01640 *
group.fsfgc -0.57151    0.40138  -1.424  0.16109
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.415 on 47 degrees of freedom
Multiple R-squared:  0.1414,    Adjusted R-squared:  0.1048
F-statistic: 3.869 on 2 and 47 DF,  p-value: 0.02784


As you can see here, group has no statistically significant impact on MC1. However, if you want to independently test each group, you can do so by m1 <- lm(MC1 ~ fs3, group.f == "gga", data = t) in which case you'll see that only the sfgc group is significant.

Theoretically, you should pick the model that answers your question. If you're interested in whether group and fs3 predict MC1, you should stick with model 1 above. If however, you want to focus on whether individual groups and fs3 predict MC1, you can stick with your original set up.

Notice that the level reported in the output is in comparison to the base level.

• thanks @torentino and sorry I wasnt clear enough... The expression data of MC1 and fs3 belong to two different groups the group S and the group G (categorical value), so half of the above expression data belong to S and I have created a subset named "delta.CT.midguts" and the other half is the other subset named "delta.CT.midgutg". Its true the two models are identical but I want to test the two subsets separately, so each time I am testing one subset. The fs3 is a nominal and the groups (G or S) is a categorical variable. I tried the (MC1 ~ fs3*Group, data) but i dont think it is correct.. – Panos Sapou Dec 24 '16 at 20:29
• Is there a particular reason you're wanting to use linear regression for this? Also, sample data would be helpful. – monarque13 Dec 24 '16 at 20:40
• sample data here: dropbox.com/s/g1fltzifl6kbrdr/test.txt?dl=0 I want to see if the fs3 values can explain the MC1 values, isnt linear regression appropriate?do you think I should use sth else? – Panos Sapou Dec 24 '16 at 20:54