[R] error when using multcomp and lm

chrischizinski chris.chizinski at gmail.com
Tue Dec 15 23:09:16 CET 2009


I am trying to use multcomp to do a Tukey posthoc on growth increments among
genetic crosstypes. 

#Fixed effect model
m1 <- lm(inc ~ 0 + Age+ Crosstype + Sex, data = Data.age)
summary(m1)

RESULTS of the model:
summary(m1)

Call:
lm(formula = inc ~ 0 + Age + Crosstype + Sex, data = Data.age)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.87180 -0.34002 -0.02702  0.27710  2.17820 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
Age0             1.35164    0.03028  44.632  < 2e-16 ***
Age1             1.13451    0.03015  37.626  < 2e-16 ***
Age2             0.89568    0.03644  24.582  < 2e-16 ***
CrosstypeBGxB   -0.21644    0.06198  -3.492 0.000500 ***
CrosstypeBGxG   -0.22274    0.09273  -2.402 0.016484 *  
CrosstypeF1_BXG  0.04361    0.03153   1.383 0.166946    
CrosstypeF2_BXG -0.26120    0.07098  -3.680 0.000246 ***
CrosstypeG       0.08839    0.03683   2.400 0.016572 *  
SexM             0.13177    0.02806   4.697 3.01e-06 ***
SexU            -0.03137    0.04280  -0.733 0.463736    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.4173 on 1007 degrees of freedom
Multiple R-squared: 0.8999,	Adjusted R-squared: 0.8989 
F-statistic: 905.6 on 10 and 1007 DF,  p-value: < 2.2e-16 

When I try to use the "multcomp" I this is what happens:
tuk1 <- glht(m1, linfct = mcp(Crosstype="Tukey"))
Error in Ktotal[count:(count + nrow(h$K) - 1), h$where] <- h$K : 
  number of items to replace is not a multiple of replacement length

After reading through the numerous posts and vignettes, I tried this:  
K <- contrMat(table(Data.age$Crosstype), type="Tukey")
and get this:
K

	 Multiple Comparisons of Means: Tukey Contrasts

                 B BGxB BGxG F1_BXG F2_BXG G
BGxB - B        -1    1    0      0      0 0
BGxG - B        -1    0    1      0      0 0
F1_BXG - B      -1    0    0      1      0 0
F2_BXG - B      -1    0    0      0      1 0
G - B           -1    0    0      0      0 1
BGxG - BGxB      0   -1    1      0      0 0
F1_BXG - BGxB    0   -1    0      1      0 0
F2_BXG - BGxB    0   -1    0      0      1 0
G - BGxB         0   -1    0      0      0 1
F1_BXG - BGxG    0    0   -1      1      0 0
F2_BXG - BGxG    0    0   -1      0      1 0
G - BGxG         0    0   -1      0      0 1
F2_BXG - F1_BXG  0    0    0     -1      1 0
G - F1_BXG       0    0    0     -1      0 1
G - F2_BXG       0    0    0      0     -1 1

I get this message:  Error in glht.matrix(m1, linfct = K) : 
  'ncol(linfct)' is not equal to 'length(coef(model))'

I get the same error when I try a variation of the model m1 as a mixed
effects model.  

Can anyone tell my why I am getting this error and perhaps a direction for a
remedy.  I am stuck.  

-- 
View this message in context: http://n4.nabble.com/error-when-using-multcomp-and-lm-tp964705p964705.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list