[R-sig-ME] glth function with lme returns error Error in contrMat(table(mf[[nm]]), type = types[pm]) : less than two groups
Thierry Onkelinx
thierry.onkelinx at inbo.be
Mon Mar 14 09:19:25 CET 2016
Dear Annie,
Please don't use attach(). It's a recipe for disaster. Use the data
argument instead.
glht() can't handle interaction terms. You will have to specify the
contrasts manually. A workaround is to create a new variable that
holds the interaction an use that in the model.
spl$Interaction <- interaction(spl$treat, spl$week)
modcover <- lme(logcov ~ Interaction, random= ~1 | rep / week, data = spl)
summary(glht(modcover, linfct = mcp(Interaction = "Tukey")))
Best regards,
Thierry
Op 11-mrt.-2016 23:03 schreef "Annie-Claude Letendre"
<annieclaude.letendre op gmail.com>:
>
> Hi,
>
> I am trying to run a *posthoc* on a lme with the glht function and I get
> this error that I can't figure out "Error in contrMat(table(mf[[nm]]), type
> = types[pm]) :
> less than two groups"
>
> My experiment had 45 indivuduals (rep) each of these had 1 treatment
> (treat) applied to it and then the variable (logcov) was measured twice for
> each individual at week 6 and 12.
>
> I've attached the csv I am using , thanks for any help you can offer !
> Is there any other posthoc test that could work for me ?
>
> Annie
>
> >
> spl<-read.table("C:/Users/Annie/Desktop/splcover.csv",header=T,sep=",",quote="")
> > attach(spl)
> > names(spl)
> [1] "rep" "treat" "logcov" "week"
>
>
> > rep<-factor(rep)
> > treat<-factor(treat)
> > week<-factor(week)
> > levels(treat)
> [1] "c" "f" "g" "p" "r"
> > levels(week)
> [1] "6" "12"
> > levels(rep)
> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
> "15"
> [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
> "30"
> [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44"
> "45"
>
> > library(nlme)
> Warning message:
> package ‘nlme’ was built under R version 3.1.3
>
> > summary(modcover<-lme(logcov~treat*week, random= ~1|rep/week))
> Linear mixed-effects model fit by REML
> Data: NULL
> AIC BIC logLik
> -33.51971 -2.553367 29.75986
>
> Random effects:
> Formula: ~1 | rep
> (Intercept)
> StdDev: 0.09534288
>
> Formula: ~1 | week %in% rep
> (Intercept) Residual
> StdDev: 0.1095635 0.04379889
>
> Fixed effects: logcov ~ treat * week
> Value Std.Error DF t-value p-value
> (Intercept) -2.0000000 0.05056654 40 -39.55185 0.0000
> treatf 1.5944444 0.07151188 40 22.29622 0.0000
> treatg 0.0000000 0.07151188 40 0.00000 1.0000
> treatp 1.3944444 0.07151188 40 19.49948 0.0000
> treatr 1.5744444 0.07151188 40 22.01654 0.0000
> week12 0.1400000 0.05562275 40 2.51696 0.0159
> treatf:week12 -0.0266667 0.07866245 40 -0.33900 0.7364
> treatg:week12 0.1888889 0.07866245 40 2.40126 0.0211
> treatp:week12 -0.0222222 0.07866245 40 -0.28250 0.7790
> treatr:week12 0.0077778 0.07866245 40 0.09888 0.9217
> Correlation:
> (Intr) treatf treatg treatp treatr week12 trtf:12 trtg:12
> trtp:12
> treatf -0.707
>
> treatg -0.707 0.500
>
> treatp -0.707 0.500 0.500
>
> treatr -0.707 0.500 0.500 0.500
>
> week12 -0.550 0.389 0.389 0.389 0.389
>
> treatf:week12 0.389 -0.550 -0.275 -0.275 -0.275 -0.707
>
> treatg:week12 0.389 -0.275 -0.550 -0.275 -0.275 -0.707 0.500
>
> treatp:week12 0.389 -0.275 -0.275 -0.550 -0.275 -0.707 0.500 0.500
>
> treatr:week12 0.389 -0.275 -0.275 -0.275 -0.550 -0.707 0.500 0.500
> 0.500
>
> Standardized Within-Group Residuals:
> Min Q1 Med Q3 Max
> -0.741681806 -0.152850434 -0.008438999 0.126023769 0.836897713
>
> Number of Observations: 90
> Number of Groups:
> rep week %in% rep
> 45 90
> > anova(modcover)
> numDF denDF F-value p-value
> (Intercept) 1 40 2817.8201 <.0001
> treat 4 40 366.2476 <.0001
> week 1 40 46.4611 <.0001
> treat:week 4 40 2.6323 0.0483
> > require(multcomp)
> Loading required package: multcomp
> Loading required package: mvtnorm
> Loading required package: survival
> Loading required package: splines
> Loading required package: TH.data
>
>
> > summary(glht(modcover, linfct=mcp(treat="Tukey")))
> Error in contrMat(table(mf[[nm]]), type = types[pm]) :
> less than two groups
>
> > is.factor(treat)
> [1] TRUE
>
> > sessionInfo()
> R version 3.1.1 (2014-07-10)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
> [3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
> [5] LC_TIME=English_Canada.1252
>
> attached base packages:
> [1] splines stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] multcomp_1.3-6 TH.data_1.0-3 survival_2.37-7 mvtnorm_1.0-0
> [5] nlme_3.1-125
>
> loaded via a namespace (and not attached):
> [1] colorspace_1.2-4 ggplot2_2.0.0 grid_3.1.1 gtable_0.1.2
> [5] lattice_0.20-33 munsell_0.4.2 plyr_1.8.3 Rcpp_0.12.2
> [9] sandwich_2.3-2 scales_0.3.0 zoo_1.7-11
> _______________________________________________
> R-sig-mixed-models op r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list