I have a data set of 482 observations.
data=Populationfull
Im going to do a genotype association analysis for 3 SNPs. Im trying to build a model for my analysis and Im using the aov(y~x,data=...). For one trait I have several fixed effects and covariates that I have included in the model, like so:
Starts <- aov(Starts~Sex+DMRT3+Birthyear+Country+Earnings+Voltsec+Autosec, data=Populationfull) summary(Starts) Df Sum Sq Mean Sq F value Pr(>F) Sex 3 17.90 5.97 42.844 < 2e-16 *** DMRT3 2 1.14 0.57 4.110 0.017 * Birthyear 9 5.59 0.62 4.461 1.26e-05 *** Country 1 11.28 11.28 81.005 < 2e-16 *** Earnings 1 109.01 109.01 782.838 < 2e-16 *** Voltsec 1 12.27 12.27 88.086 < 2e-16 *** Autosec 1 8.97 8.97 64.443 8.27e-15 *** Residuals 463 64.48 0.14 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
I discovered that if i changed the order of the variables in the model i got different p-values, please see below.
Starts2 <- aov(Starts~Voltsec+Autosec+Sex+DMRT3+Birthyear+Country+Earnings, data=Populationfull) summary(Starts2) Df Sum Sq Mean Sq F value Pr(>F) Voltsec 1 2.18 2.18 15.627 8.92e-05 *** Autosec 1 100.60 100.60 722.443 < 2e-16 *** Sex 3 10.43 3.48 24.962 5.50e-15 *** DMRT3 2 0.82 0.41 2.957 0.05294 . Birthyear 9 3.25 0.36 2.591 0.00638 ** Country 1 2.25 2.25 16.183 6.72e-05 *** Earnings 1 46.64 46.64 334.903 < 2e-16 *** Residuals 463 64.48 0.14 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Why do I get different p-values depending on in which order the variables/factors/covariates/fixedeffects(?) are coded? Is there a way to "correct" for it? Can it be that Im using the wrong model? I am still quite new at R so if you can help me with this please keep it really simple so I can understand the answer hehe... Thank you, hopefully someone can help me understand this!
Populationfull
to make your problem reproducible. This does not happen with the example from theaov()
help page.summary(aov(yield ~ block + N + P + K, npk)); summary(aov(yield ~ K + P + block + N , npk))
$\endgroup$Earnings 1 109.01 109.01 782.838 < 2e-16 ***
your second runEarnings 1 46.64 46.64 334.903 < 2e-16 ***
. Your results are not the same. Begin by checking to see that you have not done more than reorder variables. $\endgroup$car
package- it implements Type II and Type III ANOVA, which don't depend on the order of variables, whereasaov
does Type I ANOVA. $\endgroup$