<p>When you fit a model, you need to check whether it's overly determined, meaning some terms cannot be determined. We can look at one of your samples, for example only for RB5 and Nocardia_nova_SH22a_RB20_RB56:</p>
<pre><code>df = structure(list(X = c(226L, 227L, 228L, 229L, 230L, 231L, 232L, 
233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 
244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L, 
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L, 
266L, 267L, 268L, 269L, 270L, 1126L, 1127L, 1128L, 1129L, 1130L, 
1131L, 1132L, 1133L, 1134L, 1135L, 1136L, 1137L, 1138L, 1139L, 
1140L, 1141L, 1142L, 1143L, 1144L, 1145L, 1146L, 1147L, 1148L, 
1149L, 1150L, 1151L, 1152L, 1153L, 1154L, 1155L, 1156L, 1157L, 
1158L, 1159L, 1160L, 1161L, 1162L, 1163L, 1164L, 1165L, 1166L, 
1167L, 1168L, 1169L, 1170L), sample = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(&quot;Nocardia_nova_SH22a_RB20_RB56&quot;, 
&quot;RB56&quot;), class = &quot;factor&quot;), substrate = structure(c(10L, 37L, 
29L, 11L, 24L, 9L, 39L, 30L, 42L, 14L, 21L, 40L, 38L, 45L, 28L, 
5L, 22L, 3L, 41L, 16L, 32L, 27L, 18L, 26L, 20L, 34L, 7L, 12L, 
23L, 17L, 44L, 35L, 4L, 19L, 25L, 13L, 1L, 33L, 31L, 43L, 36L, 
6L, 2L, 8L, 15L, 10L, 37L, 29L, 11L, 24L, 9L, 39L, 30L, 42L, 
14L, 21L, 40L, 38L, 45L, 28L, 5L, 22L, 3L, 41L, 16L, 32L, 27L, 
18L, 26L, 20L, 34L, 7L, 12L, 23L, 17L, 44L, 35L, 4L, 19L, 25L, 
13L, 1L, 33L, 31L, 43L, 36L, 6L, 2L, 8L, 15L), .Label = c(&quot;acylsphingosine&quot;, 
&quot;agarose&quot;, &quot;alcohol&quot;, &quot;alginate&quot;, &quot;alpha-glucan&quot;, &quot;amylaceous polysaccharides&quot;, 
&quot;arabinogalactans&quot;, &quot;aribinose&quot;, &quot;beta-glucan&quot;, &quot;cellulose&quot;, 
&quot;chitin&quot;, &quot;cutin&quot;, &quot;cyclomaltodextrin&quot;, &quot;D-galactose&quot;, &quot;D-glucan&quot;, 
&quot;D-glucose&quot;, &quot;dermatan sulfate&quot;, &quot;dextran&quot;, &quot;fructans&quot;, &quot;fructose&quot;, 
&quot;galactan&quot;, &quot;galactose&quot;, &quot;galacturonide&quot;, &quot;glucan&quot;, &quot;glucose&quot;, 
&quot;glucuronoside&quot;, &quot;glycan&quot;, &quot;glycans&quot;, &quot;glycogen&quot;, &quot;hemicellulose&quot;, 
&quot;hyaluronate&quot;, &quot;L-rhamnose&quot;, &quot;lacto-N-tetraose&quot;, &quot;levan&quot;, &quot;lignin&quot;, 
&quot;maltose&quot;, &quot;mannan&quot;, &quot;mannose&quot;, &quot;pectin&quot;, &quot;peptidoglycan&quot;, &quot;pullulan&quot;, 
&quot;trehalose&quot;, &quot;Vanillyl-alcohol&quot;, &quot;xanthan&quot;, &quot;xylose&quot;), class = &quot;factor&quot;), 
    count = c(2L, 0L, 2L, 2L, 0L, 1L, 2L, 2L, 3L, 0L, 0L, 1L, 
    0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 3L, 1L, 3L, 3L, 0L, 3L, 3L, 5L, 2L, 0L, 0L, 4L, 
    0L, 0L, 1L, 2L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 
    0L, 0L, 0L), origin = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(&quot;free&quot;, &quot;isolate&quot;
    ), class = &quot;factor&quot;)), row.names = c(226L, 227L, 228L, 229L, 
230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 
241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 
252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 
263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 1126L, 1127L, 
1128L, 1129L, 1130L, 1131L, 1132L, 1133L, 1134L, 1135L, 1136L, 
1137L, 1138L, 1139L, 1140L, 1141L, 1142L, 1143L, 1144L, 1145L, 
1146L, 1147L, 1148L, 1149L, 1150L, 1151L, 1152L, 1153L, 1154L, 
1155L, 1156L, 1157L, 1158L, 1159L, 1160L, 1161L, 1162L, 1163L, 
1164L, 1165L, 1166L, 1167L, 1168L, 1169L, 1170L), class = &quot;data.frame&quot;)
</code></pre>
<p>Now we look at whether how it is distributed:</p>
<pre><code>df<span class="math-container">$sample = droplevels(df$</span>sample)
table(df<span class="math-container">$origin,df$</span>sample)
         
          Nocardia_nova_SH22a_RB20_RB56 RB56
  free                               45    0
  isolate                             0   45
</code></pre>
<p>You can see, the samples are either free or isolate, and never both. So you cannot discern the effect of origin from samples. This means your model is over-determined and hence you see the error above.</p>
<p>To know the effect of origin, you have to fit, i used a poisson for this example because if i use only the subset above, the counts are not overdispersed hence glm.nb throws some error:</p>
<pre><code>fit = glm(count~ origin+substrate,data=df,family=poisson)
summary(fit)

 head(coefficients(summary(fit)))
                           Estimate   Std. Error       z value   Pr(&gt;|z|)
(Intercept)           -2.266968e+01 2.930556e+04 -7.735624e-04 0.99938279
originisolate          6.931472e-01 2.970443e-01  2.333481e+00 0.01962291
substrateagarose       2.282092e-06 4.144430e+04  5.506408e-11 1.00000000
substratealcohol       2.280854e-06 4.144430e+04  5.503420e-11 1.00000000
substratealginate      2.278865e-06 4.144430e+04  5.498621e-11 1.00000000
substratealpha-glucan  2.295736e+01 2.930556e+04  7.833790e-04 0.99937495
</code></pre>
<p>You can see that in this model, free is the reference, and isolate is compared to free in the &quot;originisolate&quot;. The coefficient 6.931472e-01 means isolate samples are higher than free samples, by exp(6.931472e-01) times.</p>

CC BY-SA 4.0
2020-07-10T13:16:11.217Z
2020-07-10T13:16:11.217Z
StupidWolf
<p>Having constructed two nested negbin glms in R, one has a dropped factor, We can do an <code>anova</code> with <code>test = &quot;Chisq&quot;</code> to see if there is a significant difference between the models. But what does the Pvalue as a result of this actually tell me?</p>
<pre><code>anova(mnegbin1, mnegbin2, test = &quot;Chisq&quot;)
Likelihood ratio tests of Negative Binomial Models

Response: count
                        Model    theta Resid. df    2 x log-lik.   Test    df      LR stat. Pr(Chi)
1 origin + substrate + sample 18.46502      1232       -2459.886                                   
2          substrate + sample 18.46502      1232       -2459.886 1 vs 2     0 -1.500666e-11       1
</code></pre>

CC BY-SA 4.0
2020-07-10T12:15:36.553Z
Hi @Lamma, welcome to bioinformatics. I commented on a similar question on cross-validated. https://stats.stackexchange.com/questions/476492/is-is-better-to-compare-the-log-likelihoods-between-glm-models-or-the-residual-d
StupidWolf
CC BY-SA 4.0
2020-07-10T12:16:02.967Z
To avoid any misunderstanding, can you explain how is it that two users have the same dataset and exactly the same code? Is it a school assignment?
StupidWolf
CC BY-SA 4.0
2020-07-10T12:19:10.277Z
Hi @StupidWolf They are some results from a group project yes, I guess someone else in the group is asking the same question, I will find out who and communicate with them to keep you from answering both of us!
Lamma
CC BY-SA 4.0
2020-07-10T12:21:16.603Z
@StupidWolf I see you say it indicates some of the terms are linear correlated, how come the glm function is not throwing up an error then?
Lamma
CC BY-SA 4.0
2020-07-10T12:25:46.637Z
Not linearly correlated, but linear combinations. It means that you don't have the samples for you to estimate certain effects. For example if all samples from origin A are also of substrate 1, then you cannot distinguish A and 1 right? https://stats.stackexchange.com/questions/35071/what-is-rank-deficiency-and-how-to-deal-with-it
StupidWolf
CC BY-SA 4.0
2020-07-10T12:30:35.100Z
@StupidWolf I think I get what you mean but that is as are as I am aware, not the case in this data. There might however examples of substrates only found in origin A or B, Could this cause the same effect?
Lamma
CC BY-SA 4.0
2020-07-10T12:34:50.140Z
@StupidWolf I just checked and there are 9 substrates found in origin B that are not in origin B
Lamma
CC BY-SA 4.0
2020-07-10T12:36:12.117Z
@StupidWolf I am artificially forcing this though but just putting a count of each substrate for each sample. and the samples are from either origin A or B
Lamma
CC BY-SA 4.0
2020-07-10T12:42:06.813Z
@StupidWolf Is there some way I can share the data with you? 
If the substrate did not exist in that sample it was simply given a count of 0, so i did fill for missing counts (I think?) if I am understanding correctly.
Lamma
CC BY-SA 4.0
2020-07-10T12:43:08.587Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/110452/discussion-between-stupidwolf-and-lamma).
StupidWolf
<r><logistic-regression>
What is the pvalue from anova(glm1, glm2, test = “Chisq”) telling me in R when the glms have a negative binomial distribution?
# What is the pvalue from anova(glm1, glm2, test = “Chisq”) telling me in R when the glms have a negative binomial distribution?

(Asked by: username_0 on 2020-07-10)

Having constructed two nested negbin glms in R, one has a dropped factor, We can do an anova with test = "Chisq" to see if there is a significant difference between the models. But what does the Pvalue as a result of this actually tell me?
anova(mnegbin1, mnegbin2, test = "Chisq")
Likelihood ratio tests of Negative Binomial Models

Response: count
                        Model    theta Resid. df    2 x log-lik.   Test    df      LR stat. Pr(Chi)
1 origin + substrate + sample 18.46502      1232       -2459.886                                   
2          substrate + sample 18.46502      1232       -2459.886 1 vs 2     0 -1.500666e-11       1

**Tags:** r, logistic-regression
> **Comments:**
> **username_1**: Hi @Lamma, welcome to bioinformatics. I commented on a similar question on cross-validated. https://stats.stackexchange.com/questions/476492/is-is-better-to-compare-the-log-likelihoods-between-glm-models-or-the-residual-d  
> **username_1**: To avoid any misunderstanding, can you explain how is it that two users have the same dataset and exactly the same code? Is it a school assignment?  
> **username_0**: Hi @StupidWolf They are some results from a group project yes, I guess someone else in the group is asking the same question, I will find out who and communicate with them to keep you from answering both of us!  
> **username_0**: @StupidWolf I see you say it indicates some of the terms are linear correlated, how come the glm function is not throwing up an error then?  
> **username_1**: Not linearly correlated, but linear combinations. It means that you don't have the samples for you to estimate certain effects. For example if all samples from origin A are also of substrate 1, then you cannot distinguish A and 1 right? https://stats.stackexchange.com/questions/35071/what-is-rank-deficiency-and-how-to-deal-with-it  
> **username_0**: @StupidWolf I think I get what you mean but that is as are as I am aware, not the case in this data. There might however examples of substrates only found in origin A or B, Could this cause the same effect?  
> **username_0**: @StupidWolf I just checked and there are 9 substrates found in origin B that are not in origin B  
> **username_0**: @StupidWolf I am artificially forcing this though but just putting a count of each substrate for each sample. and the samples are from either origin A or B  
> **username_0**: @StupidWolf Is there some way I can share the data with you?  If the substrate did not exist in that sample it was simply given a count of 0, so i did fill for missing counts (I think?) if I am understanding correctly.  
> **username_1**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/110452/discussion-between-stupidwolf-and-lamma).  

---

## 1 answers

### Answer by username_1 on 2020-07-10. Score: 2 | Accepted answer

When you fit a model, you need to check whether it's overly determined, meaning some terms cannot be determined. We can look at one of your samples, for example only for RB5 and Nocardia_nova_SH22a_RB20_RB56:
df = structure(list(X = c(226L, 227L, 228L, 229L, 230L, 231L, 232L, 
233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 
244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L, 
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L, 
266L, 267L, 268L, 269L, 270L, 1126L, 1127L, 1128L, 1129L, 1130L, 
1131L, 1132L, 1133L, 1134L, 1135L, 1136L, 1137L, 1138L, 1139L, 
1140L, 1141L, 1142L, 1143L, 1144L, 1145L, 1146L, 1147L, 1148L, 
1149L, 1150L, 1151L, 1152L, 1153L, 1154L, 1155L, 1156L, 1157L, 
1158L, 1159L, 1160L, 1161L, 1162L, 1163L, 1164L, 1165L, 1166L, 
1167L, 1168L, 1169L, 1170L), sample = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Nocardia_nova_SH22a_RB20_RB56", 
"RB56"), class = "factor"), substrate = structure(c(10L, 37L, 
29L, 11L, 24L, 9L, 39L, 30L, 42L, 14L, 21L, 40L, 38L, 45L, 28L, 
5L, 22L, 3L, 41L, 16L, 32L, 27L, 18L, 26L, 20L, 34L, 7L, 12L, 
23L, 17L, 44L, 35L, 4L, 19L, 25L, 13L, 1L, 33L, 31L, 43L, 36L, 
6L, 2L, 8L, 15L, 10L, 37L, 29L, 11L, 24L, 9L, 39L, 30L, 42L, 
14L, 21L, 40L, 38L, 45L, 28L, 5L, 22L, 3L, 41L, 16L, 32L, 27L, 
18L, 26L, 20L, 34L, 7L, 12L, 23L, 17L, 44L, 35L, 4L, 19L, 25L, 
13L, 1L, 33L, 31L, 43L, 36L, 6L, 2L, 8L, 15L), .Label = c("acylsphingosine", 
"agarose", "alcohol", "alginate", "alpha-glucan", "amylaceous polysaccharides", 
"arabinogalactans", "aribinose", "beta-glucan", "cellulose", 
"chitin", "cutin", "cyclomaltodextrin", "D-galactose", "D-glucan", 
"D-glucose", "dermatan sulfate", "dextran", "fructans", "fructose", 
"galactan", "galactose", "galacturonide", "glucan", "glucose", 
"glucuronoside", "glycan", "glycans", "glycogen", "hemicellulose", 
"hyaluronate", "L-rhamnose", "lacto-N-tetraose", "levan", "lignin", 
"maltose", "mannan", "mannose", "pectin", "peptidoglycan", "pullulan", 
"trehalose", "Vanillyl-alcohol", "xanthan", "xylose"), class = "factor"), 
    count = c(2L, 0L, 2L, 2L, 0L, 1L, 2L, 2L, 3L, 0L, 0L, 1L, 
    0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 3L, 1L, 3L, 3L, 0L, 3L, 3L, 5L, 2L, 0L, 0L, 4L, 
    0L, 0L, 1L, 2L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 
    0L, 0L, 0L), origin = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("free", "isolate"
    ), class = "factor")), row.names = c(226L, 227L, 228L, 229L, 
230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 
241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 
252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 
263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 1126L, 1127L, 
1128L, 1129L, 1130L, 1131L, 1132L, 1133L, 1134L, 1135L, 1136L, 
1137L, 1138L, 1139L, 1140L, 1141L, 1142L, 1143L, 1144L, 1145L, 
1146L, 1147L, 1148L, 1149L, 1150L, 1151L, 1152L, 1153L, 1154L, 
1155L, 1156L, 1157L, 1158L, 1159L, 1160L, 1161L, 1162L, 1163L, 
1164L, 1165L, 1166L, 1167L, 1168L, 1169L, 1170L), class = "data.frame")

Now we look at whether how it is distributed:
df$sample = droplevels(df$sample)
table(df$origin,df$sample)
         
          Nocardia_nova_SH22a_RB20_RB56 RB56
  free                               45    0
  isolate                             0   45

You can see, the samples are either free or isolate, and never both. So you cannot discern the effect of origin from samples. This means your model is over-determined and hence you see the error above.
To know the effect of origin, you have to fit, i used a poisson for this example because if i use only the subset above, the counts are not overdispersed hence glm.nb throws some error:
fit = glm(count~ origin+substrate,data=df,family=poisson)
summary(fit)

 head(coefficients(summary(fit)))
                           Estimate   Std. Error       z value   Pr(>|z|)
(Intercept)           -2.266968e+01 2.930556e+04 -7.735624e-04 0.99938279
originisolate          6.931472e-01 2.970443e-01  2.333481e+00 0.01962291
substrateagarose       2.282092e-06 4.144430e+04  5.506408e-11 1.00000000
substratealcohol       2.280854e-06 4.144430e+04  5.503420e-11 1.00000000
substratealginate      2.278865e-06 4.144430e+04  5.498621e-11 1.00000000
substratealpha-glucan  2.295736e+01 2.930556e+04  7.833790e-04 0.99937495

You can see that in this model, free is the reference, and isolate is compared to free in the "originisolate". The coefficient 6.931472e-01 means isolate samples are higher than free samples, by exp(6.931472e-01) times.


---

