R Markdown

\(H_0\): five group means are the same; \(\mu_0 = \mu_{20} = \mu_{40} = \mu_{60} = \mu_{80}\)

\(H_A\) : five group means are not all the same; \(\mu_i \neq \mu_j\) for \(i \neq j\)

Below, we have used contrasts to obtain the linear, quadratic, cubic, and quartic sum of squares.

#Given
grps <- c(0, 20, 40, 60,80)
mean <- c(2.16, 2.45, 2.91, 3.00, 2.71)
SSE <- 153.4
MSE <- 1.278 #Calculated last time = SSE/120

#Contrasts
linear <- c(-2,-1,0,1,2)
quadratic <- c(2,-1,-2,-1,2)
cubic <- c(-1,2,0,-2,1)
quartic <- c(1,-4,6,-4,1)

#Sum of Squares

##Linear Sum of Squares
SS_linear <- ((sum(linear*mean))^2)/sum((linear^2)/25)
SS_linear
## [1] 6.80625
##Quadratic Sum of Squares
SS_quadratic <- ((sum(quadratic*mean))^2)/sum((quadratic^2)/25)
SS_quadratic
## [1] 4.180179
##Cubic Sum of Squares
SS_cubic <- ((sum(cubic*mean))^2)/sum((cubic^2)/25)
SS_cubic
## [1] 0.75625
##Quartic Sum of Squares
SS_quartic <- ((sum(quartic*mean))^2)/sum((quartic^2)/25)
SS_quartic
## [1] 0.1003214
#F Terms
F_linear <- SS_linear/MSE
F_linear
## [1] 5.325704
F_quadratic <- SS_quadratic/MSE
F_quadratic
## [1] 3.270875
F_cubic <- SS_cubic/MSE
F_cubic
## [1] 0.5917449
F_quartic <- SS_quartic/MSE
F_quartic
## [1] 0.07849877
#P-Values using r
p_linear <- 1-pf(F_linear,1,120)
p_linear
## [1] 0.0227261
p_quadratic <- 1-pf(F_quadratic,1,120)
p_quadratic
## [1] 0.07302402
p_cubic <- 1-pf(F_cubic,1,120)
p_cubic
## [1] 0.4432566
p_quartic <- 1-pf(F_quartic,1,120)
p_quartic
## [1] 0.7798246

We define our hypothesis and test the quadratic effect.

\(H_0\): Quadratic effect is zero; \(\beta_2 = 0\) \(H_A\): Quadratic effic isnโ€™t zero; \(\beta_2 \neq 0\)

With a F_quadratic = 3.27 and a p-value = 0.073, we fail to reject the null hpyothesis that the quadratic effect is zero.

#F Value and p-value
F_quadratic
## [1] 3.270875
p_quadratic 
## [1] 0.07302402

Below, we execute the the lack of linear fit test. The degrees of freedom for the F_LOF ~ 2,122

With an F value of 0.3406184 and p-value of 0.7120046, we fail to reject the null hypothesis that the quadratic effect is zero.

#Pure Error
SSE <- 153.4
LOF <- SS_cubic+SS_quartic
LOF
## [1] 0.8565714
F_LOF<-(LOF/2)/(SSE/122)
F_LOF
## [1] 0.3406184
1-pf(F_LOF,2,122)
## [1] 0.7120046

Estimate of \(\hat{\sigma^2}\) = 1.2643

(LOF+SSE)/(120+2)
## [1] 1.264398