Nested Designs

library(GAD)
## Loading required package: matrixStats
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.

We want to test the hypotheses that only process is significant:

\[ H_0:\alpha=0\\ H_a:\alpha\neq 0 \]

process <- c(rep(1:3,each=4,3))
batch <- c(rep(1:4,9))
obs <- c(rep(1:3, each=4*3))
response <- c(25,19,15,15,19,23,18,35,14,35,38,25,30,28,17,16,17,24,21,27,15,21,54,29,26,20,14,13,14,21,17,25,20,24,50,33)


dat <- data.frame(process,batch,obs,response)
dat
##    process batch obs response
## 1        1     1   1       25
## 2        1     2   1       19
## 3        1     3   1       15
## 4        1     4   1       15
## 5        2     1   1       19
## 6        2     2   1       23
## 7        2     3   1       18
## 8        2     4   1       35
## 9        3     1   1       14
## 10       3     2   1       35
## 11       3     3   1       38
## 12       3     4   1       25
## 13       1     1   2       30
## 14       1     2   2       28
## 15       1     3   2       17
## 16       1     4   2       16
## 17       2     1   2       17
## 18       2     2   2       24
## 19       2     3   2       21
## 20       2     4   2       27
## 21       3     1   2       15
## 22       3     2   2       21
## 23       3     3   2       54
## 24       3     4   2       29
## 25       1     1   3       26
## 26       1     2   3       20
## 27       1     3   3       14
## 28       1     4   3       13
## 29       2     1   3       14
## 30       2     2   3       21
## 31       2     3   3       17
## 32       2     4   3       25
## 33       3     1   3       20
## 34       3     2   3       24
## 35       3     3   3       50
## 36       3     4   3       33
process <- as.fixed(process)
batch <- as.random(batch)
obs <- as.random(obs)
model <- lm(response~process+batch%in%process)
model
## 
## Call:
## lm(formula = response ~ process + batch %in% process)
## 
## Coefficients:
##     (Intercept)         process2         process3  process1:batch2  
##          27.000          -10.333          -10.667           -4.667  
## process2:batch2  process3:batch2  process1:batch3  process2:batch3  
##           6.000           10.333          -11.667            2.000  
## process3:batch3  process1:batch4  process2:batch4  process3:batch4  
##          31.000          -12.333           12.333           12.667
summary(model)
## 
## Call:
## lm(formula = response ~ process + batch %in% process)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -9.333 -2.083 -0.500  2.333  8.333 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       27.000      2.511  10.752 1.17e-10 ***
## process2         -10.333      3.551  -2.910  0.00768 ** 
## process3         -10.667      3.551  -3.004  0.00615 ** 
## process1:batch2   -4.667      3.551  -1.314  0.20123    
## process2:batch2    6.000      3.551   1.690  0.10406    
## process3:batch2   10.333      3.551   2.910  0.00768 ** 
## process1:batch3  -11.667      3.551  -3.285  0.00312 ** 
## process2:batch3    2.000      3.551   0.563  0.57853    
## process3:batch3   31.000      3.551   8.729 6.51e-09 ***
## process1:batch4  -12.333      3.551  -3.473  0.00197 ** 
## process2:batch4   12.333      3.551   3.473  0.00197 ** 
## process3:batch4   12.667      3.551   3.567  0.00156 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.349 on 24 degrees of freedom
## Multiple R-squared:  0.8585, Adjusted R-squared:  0.7936 
## F-statistic: 13.23 on 11 and 24 DF,  p-value: 1.177e-07
gad(model)
## Analysis of Variance Table
## 
## Response: response
##               Df  Sum Sq Mean Sq F value    Pr(>F)    
## process        2  676.06  338.03  1.4643    0.2815    
## process:batch  9 2077.58  230.84 12.2031 5.477e-07 ***
## Residual      24  454.00   18.92                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

From the anova test, we can conclude that the process is not significant (p=0.2815).