Mixed Anova in R

I am trying to do an anova anaysis in R. The experiment done had each subject tested in Method 1 and Method 2 as well a being in one of 4 different Levels (each subject in one group). The goal is to compare Method 1 and 2 for similarity. The way I see this anova being set up would be with the Method as a within factor and the Level being a between factor.I have tried using the aov, the Anova(in car package), and the ezAnova functions. I am getting wrong values for every method I try. I believe my misunderstanding is not with the code, but my understanding of how this anova should be setup.

The corrected output given by SAS (done by someone else) is here: [![SAS Anova][1]][1]

I am confused about the dfs in the SAS output. I found an aov function (trial and error) that gives similar resutls the correct SAS Anova but I dont understand what that model implies about the experiment or the hypothesis I am testing for. Also, I have many datasets like this one that are unblanced so a final answer with aov wouldnt work.

library(car)
library(ez)

#set up data
sample_data <- data.frame(Subject=rep(1:20,2),Method=rep(c('Method1','Method2'),each=20),Level=rep(rep(c('Level1','Level2','Level3','Level4'),each=5),2))
sample_data\$Result <- c(4.76,5.03,4.97,4.70,5.03,6.43,6.44,6.43,6.39,6.40,5.31,4.54,5.07,4.99,4.79,4.93,5.36,4.81,4.71,5.06,4.72,5.10,4.99,4.61,5.10,6.45,6.62,6.37,6.42,6.43,5.22,4.72,5.03,4.98,4.59,5.06,5.29,4.87,4.81,5.07)
sample_data[, 'Subject'] <- as.factor(sample_data[, 'Subject'])
#Set the contrats if needed to run type 3 sums of square for unblanaced data
#options(contrats=c("contr.sum","contr.poly"))

#With aov method as I understand it 'should' work
anova_aov <- aov(Result ~ Method*Level + Error(Subject/Method),data=test_data)
print(summary(anova_aov))

#aov method that seems to give correct results
anova_aov2 <- aov(Result ~ Method/Level + Error(Method:Level),data=sample_data)
print(summary(anova_aov2))

#ezAnova method,
anova_ez = ezANOVA(data=sample_data, wid=Subject, dv = Result, within = Method, between=Level, detailed = TRUE, type=3)
print(anova_ez)

• I am voting to leave this question open. Essentially it deals with the type of inference being conducted and calculation of degrees of freedom. More details are needed though. It would be better if you included some output from your results and point to the specific values which cause confusion. I will caution you that the ez package seems dubious, anything claiming to be "easy" should not be trusted for reliable results. – AdamO Nov 15 '16 at 19:34