In: Statistics and Probability
Need to construct ANOVA table in R using the below information
We have five groups and three observations per group. The group means Exercise 3.4 are 6.5, 4.5, 5.7, 5.7, and 5.1, and the mean square for error is .75. Compute an ANOVA table using R for these data
## The R function
k=5 ## Number of treatment
n=3 ## Number of observation in each treatment
N=n*k # total observation
T.mean=c(6.5, 4.5, 5.7, 5.7, 5.1)
M=n*sum(T.mean)/N ## Mean of all N observations
M
SST=n*sum((T.mean-M)^2) ## Sum of square treatment
MSE=0.75 # Given, mean square for error is .75
dfT=k-1 # degree of freedom for Treatment
dfE=N-k # degree of freedom for Error
SSE=MSE*dfE ## Sum of square Error
TSS=SST+SSE
MSST=SST/dfT
MSSE=SSE/dfE
Sourse=c("Treatment", "Error")
df=c(dfT, dfE)
SS=c(SST, SSE)
MSS=c(MSST, MSSE)
FT=MSST/MSSE
F=c(FT, NA)
P=df(FT, dfT, dfE)
PF=c(P, NA)
## The ANOVA table is
data.frame(Sourse, df, SS, MSS, F, PF)
## End Function
#### Run
> k=5 ## Number of treatment
> n=3 ## Number of observation in each treatment
>
> N=n*k # total observation
> T.mean=c(6.5, 4.5, 5.7, 5.7, 5.1)
> M=n*sum(T.mean)/N ## Mean of all N observations
> M
[1] 5.5
>
> SST=n*sum((T.mean-M)^2) ## Sum of square treatment
> MSE=0.75 # Given, mean square for error is .75
> dfT=k-1 # degree of freedom for Treatment
> dfE=N-k # degree of freedom for Error
> SSE=MSE*dfE ## Sum of square Error
> TSS=SST+SSE
>
> MSST=SST/dfT
> MSSE=SSE/dfE
>
> Sourse=c("Treatment", "Error")
> df=c(dfT, dfE)
> SS=c(SST, SSE)
> MSS=c(MSST, MSSE)
> FT=MSST/MSSE
>
> F=c(FT, NA)
> P=df(FT, dfT, dfE)
> PF=c(P, NA)
>
> ## The ANOVA table is
> data.frame(Sourse, df, SS, MSS, F, PF)
Sourse df SS MSS F PF
1 Treatment 4 6.72 1.68 2.24 0.1220734
2 Error 10 7.50 0.75 NA NA