[R] Tukey Test, lme, error: less than two groups
Steven McKinney
smckinney at bccrc.ca
Fri Dec 3 22:32:25 CET 2010
Just to close this thread, Lilith provided the data which was in a .csv text file
and had multiple lines of blank data at the end
species;code;treatment;pretreatment;provenance;greenhouse;individual;leaf;Date;DataPAM
Ae;c-ae-1-1-3;C;C;1;1;3;1;25.05.10 14:00; 0.665
.
.
.
Ae;w-ae-6-3-4;C;W;6;3;4;3;23.06.10 12:30; 0.622
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
;;;;;;;;;
Removing the blank (NA) rows of data and keeping all variables in the dataframe resolves the issue.
(Free floating variables yield this error
> summary(glht(PAM.lme, linfct = mcp(Provenancef = "Tukey")))
Error in `[.data.frame`(mf, nhypo[checknm]) : undefined columns selected)
Steven McKinney
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Steven McKinney [smckinney at bccrc.ca]
Sent: December 2, 2010 2:03 PM
To: 'Lilith'; r-help at r-project.org
Subject: Re: [R] Tukey Test, lme, error: less than two groups
Comments in-line below
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Lilith
> Sent: December-02-10 9:39 AM
> To: r-help at r-project.org
> Subject: [R] Tukey Test, lme, error: less than two groups
>
>
> Dear R-group,
>
> I am trying desperately to get this Tukey test working. Its my first time
> here so I hope my question is not too stupid, but I couldn't find anything
> helpful in the help or in the forum.
>
> I am analysing a dataset of treated grasses. I want to find out, if the
> grasses from different Provenances react differently.
> In the aov test I found a significance for the combination Treatment and
> provenance:
>
> summary(PAMaov<-aov(PAMval~Treatmentf*Pretreatmentf*Provenancef+Error(Datef/Code)))
>
> Treatmentf:Provenancef p-value: 0.008023 **
>
> In the Linear fixed effects model lme, I can see that there is a
> significance for two provenances (HU and ES)
>
> summary(PAM.lme<-lme(PAMval~Treatmentf*Provenancef*Pretreatmentf, random=
> ~1|Datef/Code,na.action=na.omit))
>
> Value Std.Error DF t-value
> p-value
> (Intercept) 0.6890317 0.06117401 994 11.263473
> 0.0000
> TreatmentfF -0.2897619 0.05484590 467 -5.283201
> 0.0000
> ProvenancefDE 0.0105873 0.05484590 467 0.193037
> 0.8470
>
> TreatmentfF:ProvenancefES 0.1647302 0.08226884 467 2.002340
> 0.0458
> TreatmentfF:ProvenancefHU 0.1569524 0.07756381 467 2.023526
> 0.0436
>
> No the big mystery is the Tukey test. I just can't find the mistake, it
> keeps telling me, that there are " less than two groups"
>
> summary(glht(PAM.lme, linfct = mcp(Provenancef = "Tukey")))
>
> Fehler in contrMat(table(mf[[nm]]), type = types[pm]) :
> less than two groups
>
> I guess its important to know that I made factors out of some of the data.
> Here is the code:
>
>
> PAMdata$provenance[PAMdata$provenance == "5"] = "ES"
> PAMdata$provenance[PAMdata$provenance == "6"] = "HU"
> # etc.
>
> Treatmentf <- factor(PAMdata$treatment, levels=c("C","F"))
> Datef <- factor(PAMdata$Date, levels=c( "25.05.10 14:00","26.05.10
> 19:00","27.05.2010 7:30","27.05.10 14:00","01.06.10 14:00","02.06.10
> 19:00","23.06.10 12:30"),ordered=TRUE)
>
>
> Pretreatmentf <- as.factor(PAMdata$pretreatment)
> Provenancef <- as.factor(PAMdata$provenance)
> Greenhousef <- as.factor(PAMdata$greenhouse)
> Individualf <- as.factor(PAMdata$individual)
>
> PAMval <- (PAMdata$DataPAM)
> Code<-(PAMdata$code)
I suspect the problem is the creation of all these individual variables.
Try instead
PAMdata$Treatmentf <- factor(PAMdata$treatment, levels=c("C","F"))
PAMdata$Datef <- factor(PAMdata$Date, levels=c( "25.05.10 14:00","26.05.10
19:00","27.05.2010 7:30","27.05.10 14:00","01.06.10 14:00","02.06.10
19:00","23.06.10 12:30"),ordered=TRUE)
...
PAMdata$PAMval <- (PAMdata$DataPAM)
PAMdata$Code<-(PAMdata$code)
etc.
so that all of your required variables are variables in the dataframe PAMdata.
When you pass off fitted model objects to additional functions, the
additional functions often require access to the dataframe used in the
initial modeling. Then call lme with
summary(PAM.lme<-lme(PAMval~Treatmentf*Provenancef*Pretreatmentf, random=
~1|Datef/Code, data = PAMdata, na.action=na.omit))
then try
summary(glht(PAM.lme, linfct = mcp(Provenancef = "Tukey")))
again.
(If you still get an error, run the
traceback()
command and provide that information.)
I'm also wondering why no term for Pretreatmentf shows in your model output.
After setting up the factor variables in the PAMdata dataframe, what does the
command
with(PAMdata, table(Pretreatmentf, Provenancef, Treatmentf))
show? Is Pretreatmentf even needed in the model?
The output of the command
sessionInfo()
is also useful to help people figure out such issues.
Also, if you can share the data, or a mock-up of it, others will
be able to run code examples, and not just guess.
HTH
Steve McKinney
>
> Thank you for any hint! That Tukey test seems so easy, I just can't find the
> mistake....
> Thank you very much fpr your help and greetings from Tanzania,
> Lilith
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Tukey-Test-lme-error-less-than-two-groups-
> tp3069789p3069789.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list