I have an unbalanced dataset (4 groups in total, of which 3 groups consist of 8 rats and one group consists of 7 rats). I want to run a mixed ANOVA (type III) with the Car package. My dataset has 3 factors: Day (10 levels, within-subject factor), Sex (2 levels, between-subject factor) and Group (2 levels, between-subject factor). My dependent variable is Weight.
A subset of my data can be obtained with this code:
weight_gain_SI <- structure(list(Day = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), levels = c("2", "3", "4", "5", "6",
"7", "8", "9", "10", "11"), class = "factor"), Rat = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L), levels = c("I0",
"I1", "I2", "I3", "J0", "J1", "J2", "J3", "K0", "K1", "K2", "K3",
"L0", "L1", "L3", "M0", "M1", "M2", "M3", "N0", "N1", "N2", "N3",
"O0", "O1", "O2", "O3", "P0", "P1", "P2", "P3"), class = "factor"),
Weight = c(1.015921931, 1.011339093, 1.016291327, 1.019565217,
1.046148738, 1.011992005, 1.041567291, 1.023960067, 0.992353905,
0.972113503, 0.991992463, 1.00931677, 1.004423273, 0.994209809,
1.031988873, 1.036828645, 1.015625, 1.001497006, 1.004291845,
1.057726153, 1.04837595, 1.048746996, 1.046019483, 1.010251153,
1.024016352, 1.017249877, 1.011802575, 1.044538362, 1.043112513,
1.032426778, 1.039370079, 0.995377504, 1.021598272, 0.973646382,
0.970652174, 1.002324037, 0.988674217, 0.989778535, 0.988019967,
0.985800109, 0.989236791, 0.971267075, 0.996376812, 1.023817625,
0.991485014, 0.998609179, 1.053196931, 1.014616935, 0.989021956,
1.033798283, 1.065821894, 1.072909468, 1.057329214, 1.06886127,
1.017426961, 0.998978028, 1.049285362, 1.027896996, 1.057542263,
1.061338941, 1.057880056, 1.061280383, 0.996404725, 0.976781857,
0.972208912, 0.95923913, 0.983067729, 0.987341772, 0.97955707,
1.008319468, 0.980338613, 0.995596869, 0.995760716, 0.979296066,
1.040830214, 0.982629428, 0.98922114, 1.028132992, 1.047883065,
1.027944112, 1.058476395, 1.093980993, 1.098479613, 1.080672846,
1.095398052, 1.038954382, 1.059785386, 1.057663874, 1.055257511,
1.08289987, 1.069751139, 1.078103208, 1.063334474), Sex = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L), levels = c("Female", "Male"), class = "factor"),
Group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("Control ", "Stress "
), class = "factor"), line_group = c("Female Stress ", "Female Stress ",
"Female Stress ", "Female Stress ", "Male Stress ", "Male Stress ",
"Male Stress ", "Male Stress ", "Female Stress ", "Female Stress ",
"Female Stress ", "Female Stress ", "Male Stress ", "Male Stress ",
"Male Stress ", "Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ", "Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ", "Female Stress ", "Female Stress ", "Female Stress ",
"Female Stress ", "Male Stress ", "Male Stress ", "Male Stress ",
"Male Stress ", "Female Stress ", "Female Stress ", "Female Stress ",
"Female Stress ", "Male Stress ", "Male Stress ", "Male Stress ",
"Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ", "Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ", "Female Stress ", "Female Stress ", "Female Stress ",
"Female Stress ", "Male Stress ", "Male Stress ", "Male Stress ",
"Male Stress ", "Female Stress ", "Female Stress ", "Female Stress ",
"Female Stress ", "Male Stress ", "Male Stress ", "Male Stress ",
"Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ", "Female Control ", "Female Control ", "Female Control ",
"Female Control ", "Male Control ", "Male Control ", "Male Control ",
"Male Control ")), row.names = c(NA, -93L), class = c("tbl_df",
"tbl", "data.frame"))
My code looks like this:
weight_gain_SI$Sex <- as.factor(weight_gain_SI$Sex) weight_gain_SI$Group <- as.factor(weight_gain_SI$Group) weight_gain_SI$Day <- as.factor(weight_gain_SI$Day) weight_gain_SI$Rat <- as.factor(weight_gain_SI$Rat) model <- lm(Weight ~ Sex*Group*Day, data = weight_gain_SI, contrasts=list(Sex=contr.sum,Group=contr.sum, Day=contr.sum)) Anova(model, type=3)
When I run this code, I do not get the Mauchly’s test result and the Geisser – Greenhouse or Huynh – Feldt results. What code do I need to run in order to obtain these results?
I also tried to run this code:
new_anova <- Anova(model, idata=data.frame(Day), idesign = ~Day, type="III") summary(new_anova, multivariate=FALSE)
but it gave me this output:
Sum Sq Df F value Pr(>F)
Min. : 0.0005 Min. : 1.00 Min. : 0.2 Min. :0.0000000
1st Qu.: 0.0458 1st Qu.: 1.00 1st Qu.: 28.4 1st Qu.:0.0000000
Median : 0.1033 Median : 9.00 Median : 99.1 Median :0.0000000
Mean : 38.6102 Mean : 34.44 Mean :113348.9 Mean :0.1247278
3rd Qu.: 0.2707 3rd Qu.: 9.00 3rd Qu.: 609.4 3rd Qu.:0.0000229
Max. :346.0971 Max. :270.00 Max. :904371.0 Max. :0.9977311
NA's :1 NA's :1
which is very different from the outputs I saw online that people obtained with that code. I would want an output that looks like this (screenshot from an online website, link: https://www.crumplab.com/rstatsforpsych/repeated-measures-anova.html):
output that someone else got with the same code
Can someone please help me with this issue? Many thanks in advance!
Mirte is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.