I prepared a mixed 2x2 ANOVA design analysis both in SPSS and in R. The SPSS script is correct, but in R script there is a mistake somewhere. To test that I generated artificial data from a normal distribution to simulate the interaction between two independent variables. There were no difference between the results in main effects, but results of simple effects analysis do not match when comparing between levels of variable which introduced repeated measures (GROUP A: PRE vs POST ; GROUP B: PRE vs POST).

I would be very thankful if you can help me.
The code below will do everything for you.

**Here is the code in R which:**
- generates the data
- calculates mixed ANOVA
- prepares data to csv format to import to SPSS
- performs simple effect analysis (there is probably a mistake)

```
N <- 100
absMean <- 1
sdCustom <- 5

grA_pre <- data.frame(ID = seq(N), lvl=rnorm(N, mean=absMean, sd=sdCustom), group=factor('A'), stage = factor('pre'))
grA_post <- data.frame(ID = seq(N), lvl=rnorm(N, mean=-absMean, sd=sdCustom), group=factor('A'), stage = factor('post'))
grB_pre <- data.frame(ID = seq(N+1,2*N), lvl=rnorm(N, mean=-absMean, sd=sdCustom), group=factor('B'), stage = factor('pre'))
grB_post <- data.frame(ID = seq(N+1,2*N), lvl=rnorm(N, mean=absMean, sd=sdCustom), group=factor('B'), stage = factor('post'))

gr <- rbind(grA_pre, grA_post, grB_pre, grB_post)
names(gr)
head(gr)

# save set to .csv to import to SPSS 
grSPSS <- reshape(data = gr, timevar = "stage", idvar = c("ID", "group"), direction = "wide")

write.csv2(grSPSS, file = "sample2.csv")

library(ggplot2)
library(plyr)
library(ez)

print("Omnibus mixed ANOVA - main effects and interactions")
ezPlot(data = gr, wid = ID, dv = lvl, between = group, within = stage, type = "III", x = group, split = stage, x_lab = "Group", y_lab = "Level of experience")
ezANOVA(data = gr, wid = ID, dv = lvl, between = group, within = stage, detailed = TRUE, type = "III")
#ezStats(data = gr, wid = ID, dv = lvl, between = group, within = stage, type = "III")

print("Simple main effects analysis")
dataA <- subset(gr, group == "A" )
dataB <- subset(gr, group == "B" )
dataPRE <- subset(gr, stage == "pre" )
dataPOST <- subset(gr, stage == "post" )

print("GROUP = A: PRE vs POST")
simpleEffControlANOVA <- ezANOVA(data = dataA, dv = lvl, wid = ID, within = stage, detailed = TRUE, type = "III" )
print(simpleEffControlANOVA)

print("GROUP = B: PRE vs POST")
simpleEffControlANOVA <- ezANOVA(data = dataB, dv = lvl, wid = ID, within = stage, detailed = TRUE, type = "III" )
print(simpleEffControlANOVA)

print("STAGE = PRE: A vs B")
simpleEffControlANOVA <- ezANOVA(data = dataPRE, dv = lvl, wid = ID, between = group, detailed = TRUE, type = "III" )
print(simpleEffControlANOVA)

print("STAGE = POST: A vs B")
simpleEffControlANOVA <- ezANOVA(data = dataPOST, dv = lvl, wid = ID, between = group, detailed = TRUE, type = "III" )
print(simpleEffControlANOVA)

```

**Here is the code for SPSS Syntax which:**
- calculates everything on imported data, generated by R

```
DATASET ACTIVATE DataSet1.
GLM lvl.pre lvl.post BY group
  /WSFACTOR=stage 2 Polynomial 
  /METHOD=SSTYPE(3)
  /POSTHOC=group(TUKEY T3) 
  /EMMEANS=TABLES(group) COMPARE ADJ(BONFERRONI)
  /EMMEANS=TABLES(stage) COMPARE ADJ(BONFERRONI)
  /EMMEANS=TABLES(group*stage) COMPARE(group)
  /EMMEANS=TABLES(group*stage) COMPARE(stage)
  /PLOT=PROFILE(group*stage)
  /PRINT=DESCRIPTIVE ETASQ OPOWER HOMOGENEITY 
  /CRITERIA=ALPHA(.05)
  /WSDESIGN=stage 
  /DESIGN=group.

```