I'm trying to wean myself off of SPSS and switch to R for psych statistics and I'm mostly getting there, but I've run into a real roadblock with fit.contrast
from the gmodels package. As far as I can tell, even the provided example doesn't work properly--either that, or I grossly misunderstand contrasts in R (always a possibility).
First let's look at the example code that comes with the documentation for gmodels::fit.contrast()
:
set.seed(03215)
Genotype <- sample(c("WT","KO"), 1000, replace=TRUE)
Time <- factor(sample(1:3, 1000, replace=TRUE))
y <- rnorm(1000)
data <- data.frame(y, Genotype, Time)
model <- aov( y ~ Genotype + Time + Genotype:Time, data=data )
model.tables(model, "means")
fit.contrast( model, "Genotype", rbind("KO vs WT"=c(-1,1) ), conf=0.95 , df=T)
For me, this produces the following output:
Estimate Std. Error t value Pr(>|t|) lower CI upper CI
GenotypeKO vs WT 0.01683876 0.1095764 0.1536714 0.8779 -0.1981888 0.2318664
Now consider the later example code:
model <- aov( y ~ Genotype + Time + Genotype:Time, data=data,
contrasts=list(Genotype=make.contrasts(cm.G),
Time=make.contrasts(cm.T) )
)
summary(model, split=list( Genotype=list( "KO vs WT"=1 ),
Time = list( "1 vs 2" = 1,
"2 vs 3" = 2 ) ) )
This produces this output for me:
Df Sum Sq Mean Sq F value Pr(>F)
Genotype 1 1.2 1.1687 1.121 0.290
Genotype: KO vs WT 1 1.2 1.1687 1.121 0.290
Time 2 0.7 0.3677 0.353 0.703
Time: 1 vs 2 1 0.2 0.1784 0.171 0.679
Time: 2 vs 3 1 0.6 0.5571 0.534 0.465
Genotype:Time 2 1.2 0.5760 0.552 0.576
Genotype:Time: KO vs WT.1 vs 2 1 0.3 0.3265 0.313 0.576
Genotype:Time: KO vs WT.2 vs 3 1 0.8 0.8256 0.792 0.374
Residuals 994 1036.6 1.0429
I'm completely flummoxed here. The p-values for the two tests on Genotype should match, but they don't! The p-values are not the same and the F-value isn't the square of the t-value. Also, the value computed for the contrast estimate (0.0168) is NOT the difference in the two means... why not?
Any help in understanding what fit.contrast is doing here would be greatly appreciated!