#read in data with no headerrow and no case labels
#Data <- read.table("anslabRawAnovaData.txt", sep ="\t")
#Data <- as.matrix(Data)

#DataModel  <- lm(Data ~ 0)
#DataModel2 <- update(DataModel, ~ 1) 

#WithinDesignFactors <- data.frame(nahrung=gl(2,4,8,labels = c("hochsuess","niedrigsuess")),intervall=gl(4,1,8,labels = c("t1","t2","t3","t4")))
#anova(DataModel,DataModel2,M=~nahrung+intervall,X=~nahrung,idata=WithinDesignFactors, test="Spherical")
#anova(DataModel,DataModel2,M=~nahrung+intervall,X=~intervall,idata=WithinDesignFactors, test="Spherical")
#anova(DataModel,DataModel2,X=~intervall+nahrung,idata=WithinDesignFactors, test="Spherical")


Data <- read.table("AnslabAnovaRData.txt",sep="\t",header=TRUE)
DataFrame <- read.table("AnslabAnovaRData.txt",sep="\t",header=TRUE)
DataGrouped <- groupedData( formula = DV ~ 1 | Subject/nahrung/intervall,  data = DataFrame, FUN = mean, outer=~group, inner=~nahrung*intervall)
LmeResult <- lme(fixed = DV ~ nahrung*intervall*group, data = DataGrouped, random = ~ 1 | Subject)
anova(LmeResult)