The main effects parameters (alphas and betas) and interaction parameter effects (ab’s) can be found below.
Alpha values = 0.5222 (beef), 2.6556 (pork), -3.1778 (grain)
Beta values = -6.6444 (low), -1.077 (medium), 7.7222 (high)
options(digits=10)
food <- matrix(c(76.0,83.3,83.8,86.8,89.5,83.5,101.8,98.2,86.2),ncol=3,byrow=FALSE)
colnames(food) <- c("Low","Medium","High")
rownames(food) <- c("Beef","Pork","Grain")
food <- as.table(food)
food
## Low Medium High
## Beef 76.0 86.8 101.8
## Pork 83.3 89.5 98.2
## Grain 83.8 83.5 86.2
#y's from rows
y1_dot <- sum(food[1,])/3
y2_dot <- sum(food[2,])/3
y3_dot <- sum(food[3,])/3
#y's from columns
ydot_1 <- sum(food[,1])/3
ydot_2 <- sum(food[,2])/3
ydot_3 <- sum(food[,3])/3
#y all
y_all <- sum(food)/9
#Alpha Values
alpha_1 <- y1_dot - y_all
alpha_1
## [1] 0.5222222222
alpha_2 <- y2_dot - y_all
alpha_2
## [1] 2.655555556
alpha_3 <- y3_dot - y_all
alpha_3
## [1] -3.177777778
#Beta Values
beta_1 <- ydot_1 - y_all
beta_1
## [1] -6.644444444
beta_2 <- ydot_2 - y_all
beta_2
## [1] -1.077777778
beta_3 <- ydot_3 - y_all
beta_3
## [1] 7.722222222
#Yij
y11 <- alpha_1 + beta_1 + y_all
y12 <- alpha_1 + beta_2 + y_all
y13 <- alpha_1 + beta_3 + y_all
y21 <- alpha_2 + beta_1 + y_all
y22 <- alpha_2 + beta_2 + y_all
y23 <- alpha_2 + beta_3 + y_all
y31 <- alpha_3 + beta_1 + y_all
y32 <- alpha_3 + beta_2 + y_all
y33 <- alpha_3 + beta_3 + y_all
yij <- matrix(c(y11,y12,y13,y21,y22,y23,y31,y32,y33), ncol=3, byrow=TRUE)
yij
## [,1] [,2] [,3]
## [1,] 81.55555556 87.12222222 95.92222222
## [2,] 83.68888889 89.25555556 98.05555556
## [3,] 77.85555556 83.42222222 92.22222222
#ab_ij
ab_ij <- food - yij
ab_ij
## Low Medium High
## Beef -5.55555555556 -0.32222222222 5.87777777778
## Pork -0.38888888889 0.24444444444 0.14444444444
## Grain 5.94444444444 0.07777777778 -6.02222222222
Find the sum of squares and complete the two-way anova, clearly reporting the interaction p-value and reporting its significance or not using the 1% type one error rate
\(H_0\) : No Interaction \(H_A\) : Interaction
With an interaction p-value = 0.0052303 < 0.01 = \(\alpha\), we reject the null hypothesis. We conclude the interaction is significant.
#SSa
SSa <- 2*3*(alpha_1^2 + alpha_2^2 + alpha_3^2)
SSa
## [1] 104.5377778
#SSb
SSb <- 2*3*(beta_1^2 + beta_2^2 + beta_3^2)
SSb
## [1] 629.6577778
#SSab
SSab <- 2*sum(ab_ij^2)
SSab
## [1] 274.7155556
#Degrees of Freedom
#a = 3, b = 3, n = 2
#a-1,b-1,(a-1)(b-1),(n-1)ab
df <- c(2,2,4,9)
#Mean Square Error
MSe <- 8.75
SSe <- MSe*9
SSe
## [1] 78.75
#Mean Square Error Alpha
MSa <- SSa/2
MSa
## [1] 52.26888889
#Mean Square Error Beta
MSb <- SSb/2
MSb
## [1] 314.8288889
#Mean Square Error Interaction
MSab <- SSab/4
MSab
## [1] 68.67888889
#MS
MS <- c(MSa, MSb, MSab, MSe)
#Sum of Squares Treatment
SSt <- SSa + SSb + SSab + SSe
SSt
## [1] 1087.661111
#F_value
F_a <- MSa/MSe
F_a
## [1] 5.973587302
F_b <- MSb/MSe
F_b
## [1] 35.98044444
F_ab <-MSab/MSe
F_ab
## [1] 7.849015873
#P-Value
pval_ab <-1-pf(F_ab,4,9)
pval_ab
## [1] 0.005230337502
Since the interaction in the previous part should turn out to be significant (hint, hint), next do the “within Protein Source” analysis - do this separately for the Beef, Pork and Grain protein sources, and break each 2 df up into the “linear contrasts” using contrast weights -1, 0, 1 (linear) and into the “quadratic contrasts” using the contrast weights 1, -2, 1 (quadratic); clearly state your findings for each protein source in terms of whether the linear and/or quadratic terms are significant. Also, show that the sums of squares for these 6 one-degree-of-freedom pieces sum up to a combination of sums of squares from your two-way anova table from part (b).
lin_con<-c(-1,0,1)
quad_con<-c(1,-2,1)
SSL_beef <-(sum(lin_con*food[1,])^2)/((sum((lin_con)^2))/2)
SSL_beef
## [1] 665.64
SSQ_beef<-(sum(quad_con*food[1,])^2)/((sum((quad_con)^2))/2)
SSQ_beef
## [1] 5.88
SSL_pork<-(sum(lin_con*food[2,])^2)/((sum((lin_con)^2))/2)
SSL_pork
## [1] 222.01
SSQ_pork<-(sum(quad_con*food[2,])^2)/((sum((quad_con)^2))/2)
SSQ_pork
## [1] 2.083333333
SSL_grain<-(sum(lin_con*food[3,])^2)/((sum((lin_con)^2))/2)
SSL_grain
## [1] 5.76
SSQ_grain<-(sum(quad_con*food[3,])^2)/((sum((quad_con)^2))/2)
SSQ_grain
## [1] 3
SSL_beef+SSL_pork+SSL_grain+SSQ_beef+SSQ_pork+SSQ_grain
## [1] 904.3733333
SSb+SSab
## [1] 904.3733333
p.246, Exercise 10.3 Clear state which terms are and which terms are not significant (0.05 level) and why.
Answer:
SS(R) SS(C|R) SS(RC|R,C)
SS(C) SS(R|C) SS(RC|C,R)
SST <- 3.3255 + 112.95 + 0.48787 + 0.8223
SST #SST
## [1] 117.58567
#Table 1 R then C then RC
F_val_r <- 1.1085/0.058736
F_val_r
## [1] 18.8725824
F_val_c <- 37.65/0.058736
F_val_c
## [1] 641.0038137
F_val_rc <- 0.054207/0.058736
F_val_rc
## [1] 0.9228922637
#Since this is type 1, SSE SST and SS(RC) of the interactions are the same
#Here is the SS(R) for the second table
SS_R_2 <- SST - 116.25 - 0.48787 - 0.8223
SS_R_2
## [1] 0.0255
MSR_2 <- SS_R_2/3
MSR_2
## [1] 0.0085
#C for second table
SS_C_2 <- 116.25
SS_C_2
## [1] 116.25
MSC_2 <- 116.25/3
MSC_2
## [1] 38.75
#Table 2 C then R then RC
F_val_c_2 <- 38.749/0.058736
F_val_c_2
## [1] 659.7146554
F_val_r_2 <- 0.0085/0.058736
F_val_r_2
## [1] 0.1447153364
F_val_rc_2 <- 0.054207/0.058736
F_val_rc_2
## [1] 0.9228922637