Within
base R, to do a randomized control block design, it’s necessary to have the data
saved in three columns: and ‘Outcome’ column with the values, a ‘Block’ column
with the block values, and a ‘Treatment’ column with the treatment values. Use
Example 2 from Section 13.3 as an example of how the data needs to look.
Outcomes <- c(15, 17.9, 17.5, 16.3, 15.4, 14.6, 17.4, 14.8, 17.3, 19.3, 17.7, 16, 14.2, 14.4, 18.8, 10.4, 12.2, 14.8, 12, 14.3)
Treatments <- factor(rep(c('Diet 1', 'Diet 2', 'Diet 3', 'Diet 4'), each = 5))
# NOTE: each = 5 means to repeat each factor five times.
Blocks <- factor(rep(c('Block 1','Block 2','Block 3','Block 4','Block 5'), 4))
# NOTE: the “4” is shorthand for ‘times = 4’. So, instead of repeating an element a certain number of times, the sequence repeats a certain number of times.
Block_data <- data.frame('Outcomes' = Outcomes, 'Treatments' = Treatments, 'Blocks' = Blocks)
Block_data
## Outcomes Treatments Blocks
## 1 15.0 Diet 1 Block 1
## 2 17.9 Diet 1 Block 2
## 3 17.5 Diet 1 Block 3
## 4 16.3 Diet 1 Block 4
## 5 15.4 Diet 1 Block 5
## 6 14.6 Diet 2 Block 1
## 7 17.4 Diet 2 Block 2
## 8 14.8 Diet 2 Block 3
## 9 17.3 Diet 2 Block 4
## 10 19.3 Diet 2 Block 5
## 11 17.7 Diet 3 Block 1
## 12 16.0 Diet 3 Block 2
## 13 14.2 Diet 3 Block 3
## 14 14.4 Diet 3 Block 4
## 15 18.8 Diet 3 Block 5
## 16 10.4 Diet 4 Block 1
## 17 12.2 Diet 4 Block 2
## 18 14.8 Diet 4 Block 3
## 19 12.0 Diet 4 Block 4
## 20 14.3 Diet 4 Block 5
To do
an anova in Base R, use the following code:
summary(aov(Outcomes~ Treatments + Blocks, data = Block_data))
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatments 3 51.87 17.290 5.665 0.0118 *
## Blocks 4 14.71 3.678 1.205 0.3585
## Residuals 12 36.62 3.052
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Ignore the P-value
for the blocks. The P-value for
the treatment (Diet) is 0.0118.