-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5aa0cf5
commit 77337c9
Showing
6 changed files
with
215 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# Lattice Design | ||
|
||
```{r, include=FALSE, echo=FALSE} | ||
source(here::here("settings.r")) | ||
``` | ||
|
||
## Background | ||
|
||
Yates (1936) proposed this method of arranging agricultural variety trials involving a large number of crop varieties. These types of arrangements were named a quasi-factorial or lattice designs. His paper contained numerical examples based on the results of a uniformity trial on orange trees. A special feature of lattice designs is that the number of treatments, t, is related to the block size, k, in one of three forms: t = k^2^, t = k^3^, or t = k(k +1). | ||
|
||
Even though the number of possible treatments is limited, a lattice design may be an ideal design for field experiments with a large number of treatments. | ||
|
||
Statistical model for lattice design: | ||
|
||
$Y_{ijk} = \mu + \alpha_i + \gamma_j + \tau_t + \beta_k + \epsilon_ijk$ | ||
|
||
where, $\mu$ is the experiment mean, 𝛽 is the row effect, 𝛾 is the column effect, and 𝜏 is the treatment effect. | ||
|
||
## Example Analysis | ||
|
||
The data used in this example is from a balanced lattice experiment in cotton containing 16 treatments in a 4x4 layout in each of 5 replicates. The response variable in this data is the precentage of young flower buds attacked by boll weevils. | ||
|
||
Let's start the analysis firstly by loading the required libraries: | ||
|
||
::: panel-tabset | ||
### lme4 | ||
|
||
```{r, message=FALSE, warning=FALSE} | ||
library(lme4); library(lmerTest); library(emmeans); library(performance) | ||
library(dplyr); library(broom.mixed); library(agridat); library(desplot) | ||
``` | ||
|
||
### nlme | ||
```{r, message=FALSE, warning=FALSE} | ||
library(nlme); library(broom.mixed); library(emmeans); library(performance) | ||
library(dplyr); library(agridat); library(desplot) | ||
``` | ||
::: | ||
|
||
Import data from agridat package. The data contains . This is a balanced experiment design | ||
```{r} | ||
data(cochran.lattice) | ||
dat2 <- cochran.lattice | ||
head(dat2) | ||
str(dat2) | ||
libs(desplot) | ||
desplot(dat2, y~row*col|rep, | ||
text=trt, # aspect unknown, should be 2 or .5 | ||
main="cochran.lattice") | ||
``` | ||
|
||
```{r} | ||
data(burgueno.rowcol) | ||
dat <- burgueno.rowcol | ||
head(dat) | ||
``` | ||
Here, we can use the `desplot()` function from the 'desplot' package to visualize the plot plan from lattice design. | ||
```{r} | ||
# Two contiuous reps in 8 rows, 16 columns | ||
desplot(dat, yield ~ col*row, | ||
out1=rep, # aspect unknown | ||
text=gen, shorten="none", cex=0.75, | ||
main="lattice design") | ||
``` | ||
### Data integrity checks | ||
```{r, echo=FALSE} | ||
#| label: lattice_design | ||
#| fig-cap: "Histogram of the dependent variable." | ||
#| column: margin | ||
par(mar=c(5.1, 5, 2.1, 2.1)) | ||
desplot(dat, yield ~ col*row, | ||
out1=rep, # aspect unknown | ||
text=gen, shorten="none", cex=.75, | ||
main="burgueno.rowcol") | ||
``` | ||
### Data integrity checks | ||
|
||
```{r} | ||
str(dat) | ||
``` | ||
|
||
```{r} | ||
dat2$row <- as.factor(dat2$row) | ||
dat2$col <- as.factor(dat2$col) | ||
dat$row <- as.factor(dat$row) | ||
dat$col <- as.factor(dat$col) | ||
``` | ||
|
||
```{r, eval=FALSE} | ||
hist(dat2$y, main = "", xlab = "yield") | ||
``` | ||
|
||
```{r, echo=FALSE} | ||
#| label: fig-rcbd_hist | ||
#| fig-cap: "Histogram of the dependent variable." | ||
#| column: margin | ||
par(mar=c(5.1, 5, 2.1, 2.1)) | ||
hist(dat$yield, main = "", xlab = "yield", cex.lab = 1.8, cex.axis = 1.5) | ||
``` | ||
|
||
::: panel-tabset | ||
### lme4 | ||
|
||
```{r} | ||
m1_a <- lmer(yield ~ gen + (1|row) + (1|col:rep) + (1|rep), | ||
data = dat, | ||
na.action = na.exclude) | ||
summary(m1_a) | ||
``` | ||
|
||
### nlme | ||
|
||
```{r} | ||
dat$dummy <- factor(1) | ||
m1_b <- lme(yield ~ gen, | ||
random = list(dummy = pdBlocked(list( | ||
pdIdent(~row - 1), | ||
pdIdent(~rep - 1), | ||
pdIdent(~col:rep)))), | ||
data = dat, | ||
na.action = na.exclude) | ||
VarCorr(m1_b) | ||
``` | ||
::: | ||
|
||
### Check Model Assumptions | ||
|
||
Remember those iid assumptions? Let's make sure we actually met them. | ||
|
||
```{r, fig.height=9} | ||
check_model(m1_a) | ||
``` | ||
|
||
|
||
### Inference | ||
|
||
Estimates for each treatment level can be obtained with the 'emmeans' package. And we can extract the ANOVA table from model using `anova()` function. | ||
|
||
```{r} | ||
anova(m1_a) | ||
``` | ||
|
||
Estimated marginal means | ||
|
||
```{r} | ||
emmeans(m1_a, ~ gen) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,4 @@ | ||
# Strip Plot Design | ||
|
||
```{r, include=FALSE, echo=FALSE} | ||
source(here::here("settings.r")) | ||
``` | ||
|
||
## Background | ||
|
||
Yates (1936) proposed this method of arranging agricultural variety trials involving a large number of crop varieties. These types of arrangements were named a quasi-factorial or lattice designs. His paper contained numerical examples based on the results of a uniformity trial on orange trees. A special feature of lattice designs is that the number of treatments, t, is related to the block size, k, in one of three forms: t = k^2^, t = k^3^, or t = k(k +1). | ||
|
||
Even though the number of possible treatments is limited, a lattice design may be an ideal design for field experiments with a large number of treatments. | ||
|
||
Statistical model for lattice design: | ||
|
||
$Y_{ijk} = \mu + \alpha_i + \gamma_j + \tau_t + \beta_k + \epsilon_ijk$ | ||
|
||
where, $\mu$ is the experiment mean, 𝛽 is the row effect, 𝛾 is the column effect, and 𝜏 is the treatment effect. | ||
|
||
## Example Analysis | ||
|
||
The data used in this example is from a balanced lattice experiment in cotton containing 16 treatments in a 4x4 layout in each of 5 replicates. The response variable in this data is the precentage of young flower buds attacked by boll weevils. | ||
|
||
Let's start the analysis firstly by loading the required libraries: | ||
|
||
::: panel-tabset | ||
### lme4 | ||
|
||
```{r, message=FALSE, warning=FALSE} | ||
library(lme4); library(lmerTest); library(emmeans); library(performance) | ||
library(dplyr); library(broom.mixed); library(agridat); library(desplot) | ||
``` | ||
|
||
### nlme | ||
```{r, message=FALSE, warning=FALSE} | ||
library(nlme); library(broom.mixed); library(emmeans); library(performance) | ||
library(dplyr); library(agridat); library(desplot) | ||
``` | ||
::: | ||
|
||
Import data from agridat package. The data contains . This is a balanced experiment design | ||
```{r} | ||
data(cochran.lattice) | ||
dat2 <- cochran.lattice | ||
head(dat2) | ||
str(dat2) | ||
libs(desplot) | ||
desplot(dat2, y~row*col|rep, | ||
text=trt, # aspect unknown, should be 2 or .5 | ||
main="cochran.lattice") | ||
``` | ||
|
||
```{r} | ||
data(burgueno.rowcol) | ||
dat <- burgueno.rowcol | ||
head(dat) | ||
``` | ||
Here, we can use the `desplot()` function from the 'desplot' package to visualize the plot plan from lattice design. | ||
```{r} | ||
# Two contiuous reps in 8 rows, 16 columns | ||
desplot(dat, yield ~ col*row, | ||
out1=rep, # aspect unknown | ||
text=gen, shorten="none", cex=0.75, | ||
main="lattice design") | ||
``` | ||
### Data integrity checks | ||
```{r, echo=FALSE} | ||
#| label: lattice_design | ||
#| fig-cap: "Histogram of the dependent variable." | ||
#| column: margin | ||
par(mar=c(5.1, 5, 2.1, 2.1)) | ||
desplot(dat, yield ~ col*row, | ||
out1=rep, # aspect unknown | ||
text=gen, shorten="none", cex=.75, | ||
main="burgueno.rowcol") | ||
``` | ||
### Data integrity checks | ||
|
||
```{r} | ||
str(dat) | ||
``` | ||
|
||
```{r} | ||
dat2$row <- as.factor(dat2$row) | ||
dat2$col <- as.factor(dat2$col) | ||
dat$row <- as.factor(dat$row) | ||
dat$col <- as.factor(dat$col) | ||
``` | ||
|
||
```{r, eval=FALSE} | ||
hist(dat2$y, main = "", xlab = "yield") | ||
``` | ||
|
||
```{r, echo=FALSE} | ||
#| label: fig-rcbd_hist | ||
#| fig-cap: "Histogram of the dependent variable." | ||
#| column: margin | ||
par(mar=c(5.1, 5, 2.1, 2.1)) | ||
hist(dat$yield, main = "", xlab = "yield", cex.lab = 1.8, cex.axis = 1.5) | ||
``` | ||
|
||
::: panel-tabset | ||
### lme4 | ||
|
||
```{r} | ||
m1_a <- lmer(yield ~ gen + (1|row) + (1|col:rep) + (1|rep), | ||
data = dat, | ||
na.action = na.exclude) | ||
summary(m1_a) | ||
``` | ||
|
||
### nlme | ||
|
||
```{r} | ||
dat$dummy <- factor(1) | ||
m1_b <- lme(yield ~ gen, | ||
random = list(dummy = pdBlocked(list( | ||
pdIdent(~row - 1), | ||
pdIdent(~rep - 1), | ||
pdIdent(~col:rep)))), | ||
data = dat, | ||
na.action = na.exclude) | ||
VarCorr(m1_b) | ||
``` | ||
::: | ||
|
||
### Check Model Assumptions | ||
|
||
Remember those iid assumptions? Let's make sure we actually met them. | ||
|
||
```{r, fig.height=9} | ||
check_model(m1_a) | ||
``` | ||
|
||
|
||
### Inference | ||
|
||
Estimates for each treatment level can be obtained with the 'emmeans' package. And we can extract the ANOVA table from model using `anova()` function. | ||
|
||
```{r} | ||
anova(m1_a) | ||
``` | ||
|
||
Estimated marginal means | ||
|
||
```{r} | ||
emmeans(m1_a, ~ gen) | ||
``` |
Oops, something went wrong.