[R] glht: Problem with symbolic contrast for factors with number-levels
Using a factor with 'number' levels the straightforward symbolic formulation of a contrast in 'glht' of the 'multcomp' package fails. How can this problem be resolved without having to redefine the factor levels? Example: #A is a factor with 'number' levels #B similar factor with 'letter' levels dat-data.frame(y=1:4,A=factor(c(1,1,2,2)), B=factor(c('e','e','f','f')) ) motA-lm(y~A,data=dat) motB-lm(y~B,data=dat) library(multcomp) #does not work glht(motA,linfct=mcp(A=c(2 - 1 = 0 ))) #the error message is # Error in coefs(ex[[3]]) : # cannot interpret expression '1' as linear function #works glht(motB,linfct=mcp(B=c(f - e = 0))) regards Ulrich Halekoh Aarhus University e-mail: ulrich.hale...@agrsci.dk I use R.2.12.2, package version of multcomp : 1.2-5 __ R-help@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.
Re: [R] glht: Problem with symbolic contrast for factors withnumber-levels
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ulrich Halekoh Sent: Friday, March 04, 2011 11:04 AM To: r-help@r-project.org Subject: [R] glht: Problem with symbolic contrast for factors withnumber-levels Using a factor with 'number' levels the straightforward symbolic formulation of a contrast in 'glht' of the 'multcomp' package fails. How can this problem be resolved without having to redefine the factor levels? Example: #A is a factor with 'number' levels #B similar factor with 'letter' levels dat-data.frame(y=1:4,A=factor(c(1,1,2,2)), B=factor(c('e','e','f','f')) ) motA-lm(y~A,data=dat) motB-lm(y~B,data=dat) library(multcomp) #does not work glht(motA,linfct=mcp(A=c(2 - 1 = 0 ))) #the error message is # Error in coefs(ex[[3]]) : # cannot interpret expression '1' as linear function Try putting backquotes around the factor levels so the R parser makes names out of them. glht(motA,linfct=mcp(A=c(`2` - `1` = 0 ))) General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Linear Hypotheses: Estimate `2` - `1` == 02 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com #works glht(motB,linfct=mcp(B=c(f - e = 0))) regards Ulrich Halekoh Aarhus University e-mail: ulrich.hale...@agrsci.dk I use R.2.12.2, package version of multcomp : 1.2-5 __ R-help@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@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.
Re: [R] glht: Problem with symbolic contrast for factors with number-levels
Use backquotes confint(glht(motA,linfct=mcp(A=c(`2` - `1` = 0 On Fri, Mar 4, 2011 at 2:03 PM, Ulrich Halekoh ulrich.hale...@agrsci.dkwrote: Using a factor with 'number' levels the straightforward symbolic formulation of a contrast in 'glht' of the 'multcomp' package fails. How can this problem be resolved without having to redefine the factor levels? Example: #A is a factor with 'number' levels #B similar factor with 'letter' levels dat-data.frame(y=1:4,A=factor(c(1,1,2,2)), B=factor(c('e','e','f','f')) ) motA-lm(y~A,data=dat) motB-lm(y~B,data=dat) library(multcomp) #does not work glht(motA,linfct=mcp(A=c(2 - 1 = 0 ))) #the error message is # Error in coefs(ex[[3]]) : # cannot interpret expression '1' as linear function #works glht(motB,linfct=mcp(B=c(f - e = 0))) regards Ulrich Halekoh Aarhus University e-mail: ulrich.hale...@agrsci.dk I use R.2.12.2, package version of multcomp : 1.2-5 __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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] glht problem
I am struggling with a simple repeated-measure model: fit-lme(trait~year * A, random = ~1|subj/year) A being a factor with three levels. I got have the following results for anova(fit): numDF denDF F-value p-value (Intercept) 1 126 2471.4720 .0001 year 2060 10.4126 .0001 A 2 126 23.0721 .0001 year:A40 1261.6499 0.0193 Now I try to use glht for A, but fail: Linear Hypotheses: Estimate Std. Error z value p value A2 - A1 == 0 0.25 1.10 0.227 0.972 A3 - A1 == 0 1.001.10 0.909 0.634 A3 - A2 == 0 0.75 1.10 0.682 0.774 (Adjusted p values reported -- single-step method) Warning message: In mcp2matrix(model, linfct = linfct) : covariate interactions found -- default contrast might be inappropriate What can be going on with this? many thanks in advance, Wolf __ R-help@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.