Skip to content

Commit

Permalink
new chapter-strip-plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidhuharp97 committed Sep 27, 2024
1 parent 5aa0cf5 commit 77337c9
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 179 deletions.
3 changes: 2 additions & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ book:
- chapters/rcbd.qmd
- chapters/split-plot-design.qmd
- chapters/split-split-plot.qmd
- chapters/strip-plot.qmd
- chapters/factorial-design.qmd
- chapters/incomplete-block-design.qmd
- chapters/strip-plot.qmd
#- chapters/Lattice-design.qmd
- chapters/repeated-measures.qmd
#- chapters/glmm.qmd
- chapters/special-conditions.qmd
Expand Down
153 changes: 153 additions & 0 deletions chapters/Lattice-design.qmd
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)
```
4 changes: 2 additions & 2 deletions chapters/incomplete-block-design.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library(lme4); library(lmerTest); library(emmeans)
library(dplyr); library(broom.mixed); library(performance)
```
### nlme
```{r, message=FALSE, warning=FALSE, eval=FALSE}
```{r, message=FALSE, warning=FALSE}
library(nlme); library(broom.mixed); library(emmeans)
library(dplyr); library(performance)
```
Expand All @@ -62,7 +62,7 @@ https://kwstat.github.io/agridat/reference/weiss.incblock.html
dat <- weiss.incblock
```

```{r, fig.height= 9}
```{r, fig.height= 9, echo=FALSE}
library(desplot)
desplot(dat, yield~col*row,
text=gen, shorten='none', cex=.6, out1=block,
Expand Down
149 changes: 0 additions & 149 deletions chapters/strip-plot.qmd
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)
```
Loading

0 comments on commit 77337c9

Please sign in to comment.