diff --git a/_quarto.yml b/_quarto.yml index f020bba..c6eabbf 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -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 diff --git a/chapters/Lattice-design.qmd b/chapters/Lattice-design.qmd new file mode 100644 index 0000000..7a930c7 --- /dev/null +++ b/chapters/Lattice-design.qmd @@ -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) +``` diff --git a/chapters/incomplete-block-design.qmd b/chapters/incomplete-block-design.qmd index 8708a5c..452f3cd 100644 --- a/chapters/incomplete-block-design.qmd +++ b/chapters/incomplete-block-design.qmd @@ -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) ``` @@ -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, diff --git a/chapters/strip-plot.qmd b/chapters/strip-plot.qmd index b188c35..325428f 100644 --- a/chapters/strip-plot.qmd +++ b/chapters/strip-plot.qmd @@ -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) -``` diff --git a/docs/index.html b/docs/index.html index efd4ee4..24f0d8a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,7 +2,7 @@ - + @@ -92,11 +92,11 @@ @@ -168,8 +168,8 @@