I have a really bizzare problem. I am running an anova on an lme mixed effects model that has "city" as one of the factors. There are three cities total for this vairable, and the levels are organized alphabetically by defualt. However, if I reorder the cities by latitude (thus changing the order) using the df$v1 <- factor(df$v1, levels=c(B, A, C)
command, I get a totally different p-value for my anova results. My lme model is: mod <- lme(v3~v2*v1, random=~1|v4, data=df)
. For my anova, my code is: anova(mod, type = 'marginal')
str(df)
'data.frame': 5157 obs. of 6 variables:
$ family : Factor w/ 296 levels "A_101","A_102",..: 1 1 1 1 1 1 1 1 1 1
...
$ individual: Factor w/ 50 levels "1","10","1001",..: 1 17 21 32 43 46 47 48
49 2 ...
$ city : Factor w/ 3 levels "Miami","Tallahassee",..: 3 3 3 3 3 3 3 3 3
3 ...
$ habitat : Factor w/ 2 levels "Swamp","Beach": 2 2 2 2 2 2 2 2 2 2 ...
$ temp : int 21 21 21 21 21 21 21 21 21 21 ...
$ shell_size : num 0.673 0.657 0.658 0.695 0.67 0.668 0.683 0.681
0.673 0.648 ...
head(df)
family individual city habitat temp shell_size
A_101 1 Miami Swamp 21 0.673
A_102 2 Miami Swamp 23 0.657
A_103 3 Tallahassee Beach 31 0.658
A_104 4 Key Largo Beach 33 0.695
A_105 5 Tallahassee Swamp 26 0.670
A_106 6 Key Largo Swamp 31 0.668
How can changing the order of the cities possibly change the p-value? It shouldn't! I did an lsmeans
with my city variable organized both by default (alphabetical) and by latitude, and the two test results were identical.