rglmlmposthoctukey

Error when running posthoc analysis for glm


I'm trying to perform posthoc comparisons for my treatments but I keep getting this error when running the glht: "Error in modelparm.default(model, ...) : dimensions of coefficients and covariance matrix don't match".

Is there a better way of doing multiple pairwise comparisons? I've also tried using emmeans abut I'm not sure if that's the correct method.

This is a subset of my data:

mydata <- read.table(header=TRUE, text="
treatment    total.bites   hours   rep
                     A  10  3.1  a1
                     A  1   3.2  a2
                     A  1024   3.22 a3
                     B  0   3.13 a1
                     B  16  3.15 a2
                     B  1305  3.24 a3
                     C  0   3.13 a1
                     C  0  3.26 a2
                     C  0   3.11 a3
                     D  2  3.25 a1
                     D  0   3.17 a2 
                     D  3   3.21 a3
                     ")
mC4 <- glmmTMB(total.bites~treatment + offset(log(hours)) +(1|rep), ziformula=~0, family=nbinom1, data=mydata)
summary(mC4)
summary(glht(mC4, mcp(treatment = "Tukey")))


Solution

  • As you already mentioned emmeans you could do

    library(emmeans)
    pairs(emmeans(mC4, "treatment"))
    #contrast estimate       SE df t.ratio p.value
    #A - B       0.323 8.94e-01  6  0.361  0.9824
    #A - C      20.930 1.51e+04  6  0.001  1.0000
    #A - D       0.892 9.05e-01  6  0.985  0.7631
    #B - C      20.607 1.51e+04  6  0.001  1.0000
    #B - D       0.569 9.92e-01  6  0.573  0.9365
    #C - D     -20.038 1.51e+04  6 -0.001  1.0000
    #
    #Results are given on the log (not the response) scale.
    #P value adjustment: tukey method for comparing a family of 4 estimates
    

    Here we condition on treatment and characterise all pairwise comparisons, correcting for multiple hypothesis testing using Tukey's method.