Say, I wanted to compare the effect of $t=3$ (8 hours, 12 hours, 16 hours) lengths of exposures to sun on plant growth. I randomly applied these 3 lengths of exposures to $r=3$ pots but let us say that it is too costly or tedious to measure plant growth for all plants in the entire pot, so I randomly selected $s=4$ plants within each pot for my measurement. The variables would be: treatment (a factor of 3 different hours of exposure to sunlight at which each measurement of growth is taken), pot (a factor of three per treatment), plant (a factor of four plants per pot), growth (dependent variable). The following are the null hypotheses to be tested in order (according to our manual): (1) The mean plant growth within pots are the same. (2) There are no differences in mean plant growth among the different treatments.
The linear model for the experiment is
$$Y_{ijk}=\mu+\tau_i+\delta_{ij}+\varepsilon_{ijk}$$
where $Y_{ijk}$ is the $k$th response on the $j$th pot applied with the $i$th treatment, $\tau_i$ is the effect of the length of exposure to sunlight on plant growth, $\delta_{ij}$ is the error associated to the $j$th pot in the $i$th treatment on the growth of the plant, and $\varepsilon_{ijk}$ is the error attributed to the $k$th plant on the $j$th pot applied with treatment $i$.
In the corresponding ANOVA table, I have $SSTot=SSTrt+SSPE+SSSSE$, where SSTot is Total Sum of Squares, SSTrt is Treatment Sum of Square, SSPE is Sum of Squares for the Pots, and SSSSE is the sum of squares for the subsamples, with degrees of freedom, $t-1$, $t(r-1)$, $tr(s-1)$, respectively, where $t=$ number of treatments, $r=$ number of experimental units and $s=$ number of sampling units,
Our school manual suggests a sequential tests of hypotheses. For tests of variability of the experimental units, it says to test
$$ \frac{MSPE}{MSSSE}\sim F_{(\alpha,t(r-1),tr(s-1))}$$
Then it suggests to consider the following cases for the test of differences among treatment means
- When $H_0:\sigma^2_\varepsilon=0$ is rejected
$$\frac{MSTrt}{MSPE}\sim F_{(t-1,t(r-1))}$$
- When $H_0: \sigma^2_{\varepsilon}=0$ is accepted
$$\frac{MSTrt}{MSE_{pooled}}\sim F_{(t-1,tr(s-1))}$$
where
$$MSE_{pooled}=\frac{SSPE+SSSSE}{t(rs-1)}$$.
Here, MS stands for mean squares for the corresponding sum of squares previously defined.
Question: How do I perform this sequential tests of hypotheses in R?
model <- lm(response ~ trt/pot, data)
anova(model)
I can't get it to display the correct $F$ for the treatment differences in both cases. Below is an example when $H_0:\sigma^2_\varepsilon=0$ is rejected.
I actually don't know if all of these even make sense. I did not come from a stats background and I finally decided to start learning it after a while. My school uses SAS and this procedure seems to be built-in. I know of the University Edition of SAS but I couldn't run it on my old laptop. So I am trying to find a way to get the same output in R.
Example
Here is a the data set for the following.
example <- read.csv("example.csv", header=T)
example$pot <- factor(example$pot)
example$hours <- factor(example$hours)
model <- lm(growth ~ hours/pot, example)
anova(model)
which gives the following output
## Analysis of Variance Table
##
## Response: growth
## Df Sum Sq Mean Sq F value Pr(>F)
## hours 2 15.0417 7.5208 15.3255 3.569e-05 ***
## hours:pot 6 8.2083 1.3681 2.7877 0.03054 *
## Residuals 27 13.2500 0.4907
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
In this particular example where there is significant variance among experimental units, our school manual prescribes that the F value for hours should be anova(model)$"Sum Sq"[1]/anova(model)$"Sum Sq"[2]
. Is there a way to compute it automatically? In this case, the $F$ for the test of treatment differences should be 5.4973.
This is based on the example given in our manual. I don't know if the manual is even correct in its prescribed procedures.