From 77337c9d4d15c54b94148b8849bde56b74829966 Mon Sep 17 00:00:00 2001 From: Harpreet Kaur <hkaur@uidaho.edu> Date: Fri, 27 Sep 2024 08:16:36 -0700 Subject: [PATCH] new chapter-strip-plot --- _quarto.yml | 3 +- chapters/Lattice-design.qmd | 153 +++++++++++++++++++++++++++ chapters/incomplete-block-design.qmd | 4 +- chapters/strip-plot.qmd | 149 -------------------------- docs/index.html | 47 ++++---- docs/search.json | 38 +++++-- 6 files changed, 215 insertions(+), 179 deletions(-) create mode 100644 chapters/Lattice-design.qmd 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 @@ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> <meta charset="utf-8"> -<meta name="generator" content="quarto-1.4.555"> +<meta name="generator" content="quarto-1.5.57"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> @@ -92,11 +92,11 @@ </nav> <nav class="quarto-secondary-nav"> <div class="container-fluid d-flex"> - <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> + <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> <i class="bi bi-layout-text-sidebar-reverse"></i> </button> <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./index.html">Preface</a></li></ol></nav> - <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> + <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> </a> </div> </nav> @@ -168,8 +168,8 @@ </li> <li class="sidebar-item"> <div class="sidebar-item-container"> - <a href="./chapters/lattice-design.html" class="sidebar-item-text sidebar-link"> - <span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Lattice Design</span></span></a> + <a href="./chapters/strip-plot.html" class="sidebar-item-text sidebar-link"> + <span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Strip Plot Design</span></span></a> </div> </li> <li class="sidebar-item"> @@ -314,18 +314,7 @@ <h2 class="anchored" data-anchor-id="recent-updates">Recent Updates</h2> } return false; } - const clipboard = new window.ClipboardJS('.code-copy-button', { - text: function(trigger) { - const codeEl = trigger.previousElementSibling.cloneNode(true); - for (const childEl of codeEl.children) { - if (isCodeAnnotation(childEl)) { - childEl.remove(); - } - } - return codeEl.innerText; - } - }); - clipboard.on('success', function(e) { + const onCopySuccess = function(e) { // button target const button = e.trigger; // don't keep focus @@ -357,7 +346,29 @@ <h2 class="anchored" data-anchor-id="recent-updates">Recent Updates</h2> }, 1000); // clear code selection e.clearSelection(); + } + const getTextToCopy = function(trigger) { + const codeEl = trigger.previousElementSibling.cloneNode(true); + for (const childEl of codeEl.children) { + if (isCodeAnnotation(childEl)) { + childEl.remove(); + } + } + return codeEl.innerText; + } + const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { + text: getTextToCopy }); + clipboard.on('success', onCopySuccess); + if (window.document.getElementById('quarto-embedded-source-code-modal')) { + // For code content inside modals, clipBoardJS needs to be initialized with a container option + // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860) + const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', { + text: getTextToCopy, + container: window.document.getElementById('quarto-embedded-source-code-modal') + }); + clipboardModal.on('success', onCopySuccess); + } var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); var mailtoRegex = new RegExp(/^mailto:/); var filterRegex = new RegExp('/' + window.location.host + '/'); @@ -365,7 +376,7 @@ <h2 class="anchored" data-anchor-id="recent-updates">Recent Updates</h2> return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); } // Inspect non-navigation links and adorn them if external - var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool)'); + var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)'); for (var i=0; i<links.length; i++) { const link = links[i]; if (!isInternal(link.href)) { diff --git a/docs/search.json b/docs/search.json index bd26617..a26c9ea 100644 --- a/docs/search.json +++ b/docs/search.json @@ -182,31 +182,31 @@ { "objectID": "chapters/incomplete-block-design.html", "href": "chapters/incomplete-block-design.html", - "title": "8 Incomplete Block Design", + "title": "9 Incomplete Block Design", "section": "", - "text": "8.1 Background\nThe block design in Chapter 4 was complete, meaning that every block contained all the treatments. In practice, it may not be possible to have too many treatments in each block. Sometimes, there are also situations where it is advised to not have many treatments in each block.\nIn such cases, incomplete block designs are used where we have to decide what subset of treatments to be used in an individual block. This will work well if we enough blocks. However, if we only have small number of blocks, there would be the risk that certain quantities are not estimable anymore.\nTo avoid having a disconnected design, a balanced incomplete block design can be used\nThe statistical model for balanced incomplete block design is:\n\\[y_{ij} = \\mu + \\alpha_i + \\beta_j + \\epsilon_{ij}\\] Where:\n\\(\\mu\\) = overall experimental mean \\(\\alpha\\) = treatment effects (fixed) \\(\\beta\\) = block effects (random) \\(\\epsilon\\) = error terms\n\\[ \\epsilon \\sim N(0, \\sigma)\\]\n\\[ \\beta \\sim N(0, \\sigma_b)\\] There are few key points that we need to keep in mind while designing incomplete block designs:", + "text": "9.1 Background\nThe block design in Chapter 4 was complete, meaning that every block contained all the treatments. In practice, it may not be possible to have too many treatments in each block. Sometimes, there are also situations where it is advised to not have many treatments in each block.\nIn such cases, incomplete block designs are used where we have to decide what subset of treatments to be used in an individual block. This will work well if we enough blocks. However, if we only have small number of blocks, there would be the risk that certain quantities are not estimable anymore.\nTo avoid having a disconnected design, a balanced incomplete block design can be used\nThe statistical model for balanced incomplete block design is:\n\\[y_{ij} = \\mu + \\alpha_i + \\beta_j + \\epsilon_{ij}\\] Where:\n\\(\\mu\\) = overall experimental mean \\(\\alpha\\) = treatment effects (fixed) \\(\\beta\\) = block effects (random) \\(\\epsilon\\) = error terms\n\\[ \\epsilon \\sim N(0, \\sigma)\\]\n\\[ \\beta \\sim N(0, \\sigma_b)\\] There are few key points that we need to keep in mind while designing incomplete block designs:", "crumbs": [ - "<span class='chapter-number'>8</span> <span class='chapter-title'>Incomplete Block Design</span>" + "<span class='chapter-number'>9</span> <span class='chapter-title'>Incomplete Block Design</span>" ] }, { "objectID": "chapters/incomplete-block-design.html#background", "href": "chapters/incomplete-block-design.html#background", - "title": "8 Incomplete Block Design", + "title": "9 Incomplete Block Design", "section": "", "text": "A drawback of this design is that block effect and treatment effects are confounded.\nTo eliminate of block effects, better compare treatments within a block.\nNo treatment should appear twice in any block as they contributes nothing no within block comparisons.\n\n\n\n\n\n\n\nA note\n\n\n\nBecause the blocks are incomplete, the Type I and Type III sums of squares will be different. That is, the missing treatments in each block represent missing observations (but not missing ‘at random’).", "crumbs": [ - "<span class='chapter-number'>8</span> <span class='chapter-title'>Incomplete Block Design</span>" + "<span class='chapter-number'>9</span> <span class='chapter-title'>Incomplete Block Design</span>" ] }, { "objectID": "chapters/incomplete-block-design.html#example-analysis", "href": "chapters/incomplete-block-design.html#example-analysis", - "title": "8 Incomplete Block Design", - "section": "8.2 Example Analysis", - "text": "8.2 Example Analysis\nWe will demonstrate an example data set designed in a balanced incomplete block design. First, load the libraries for analysis and estimation: ::: panel-tabset ### lme4\n\nlibrary(lme4); library(lmerTest); library(emmeans)\nlibrary(dplyr); library(broom.mixed); library(performance)\n\n\n8.2.1 nlme\n\nlibrary(nlme); library(broom.mixed); library(emmeans)\nlibrary(dplyr); library(performance)\n\n:::\nhttps://kwstat.github.io/agridat/reference/weiss.incblock.html\n\n library(agridat)\n data(weiss.incblock)\n dat <- weiss.incblock\n\n\n library(desplot)\n desplot(dat, yield~col*row,\n text=gen, shorten='none', cex=.6, out1=block,\n aspect=252/96, # true aspect\n main=\"weiss.incblock\")\n\n\n\n\n\n\n\n\n\n\n8.2.2 Data integrity checks\nThe first thing is to make sure the data is what we expect. There are two steps:\n\nmake sure data are the expected data type\ncheck the extent of missing data\ninspect the independent variables and make sure the expected levels are present in the data\ninspect the dependent variable to ensure its distribution is following expectations\n\n\nstr(dat)\n\n'data.frame': 186 obs. of 5 variables:\n $ block: Factor w/ 31 levels \"B01\",\"B02\",\"B03\",..: 1 2 3 4 5 6 7 8 9 10 ...\n $ gen : Factor w/ 31 levels \"G01\",\"G02\",\"G03\",..: 24 15 20 18 20 5 22 1 9 14 ...\n $ yield: num 29.8 24.2 30.5 20 35.2 25 23.6 23.6 29.3 25.5 ...\n $ row : int 42 36 30 24 18 12 6 42 36 30 ...\n $ col : int 1 1 1 1 1 1 1 2 2 2 ...\n\n\nThese look okay with block and gen being factor variables and yield, row, and col being numeric variables.\nNext, check the independent variables. Running a cross tabulations is often sufficient to ascertain this.\n\ndat$row <- as.factor(dat$row)\n\n\ntable(dat$gen, dat$block)\n\n \n B01 B02 B03 B04 B05 B06 B07 B08 B09 B10 B11 B12 B13 B14 B15 B16 B17 B18\n G01 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1\n G02 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0\n G03 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0\n G04 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0\n G05 0 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 0 0\n G06 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0\n G07 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0\n G08 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0\n G09 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n G10 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1\n G11 0 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0\n G12 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0\n G13 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0\n G14 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n G15 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0\n G16 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0\n G17 0 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0\n G18 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1\n G19 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0\n G20 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0\n G21 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0\n G22 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1\n G23 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0\n G24 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0\n G25 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0\n G26 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0\n G27 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0\n G28 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1\n G29 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0\n G30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n G31 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0\n \n B19 B20 B21 B22 B23 B24 B25 B26 B27 B28 B29 B30 B31\n G01 1 0 0 0 0 0 0 0 0 0 1 1 0\n G02 0 1 0 0 0 0 0 0 1 1 0 0 0\n G03 0 0 0 0 1 0 0 0 0 0 0 0 0\n G04 0 0 1 0 0 0 1 0 0 0 0 0 1\n G05 0 0 0 0 0 1 0 0 0 0 0 0 0\n G06 1 1 0 1 0 0 0 0 0 0 0 0 1\n G07 0 0 0 1 0 1 0 0 0 0 1 0 0\n G08 0 0 1 1 0 0 0 0 0 1 0 0 0\n G09 0 0 0 1 0 0 1 0 1 0 0 1 0\n G10 0 0 0 1 1 0 0 0 0 0 0 0 0\n G11 1 0 0 0 0 0 0 0 1 0 0 0 0\n G12 0 0 1 0 1 0 0 0 0 0 0 1 0\n G13 0 0 0 0 0 0 0 0 0 0 1 0 1\n G14 0 0 0 0 0 1 1 0 0 1 0 0 0\n G15 0 1 0 0 0 0 0 0 0 0 0 0 0\n G16 1 0 1 0 0 1 0 0 0 0 0 0 0\n G17 0 0 0 0 0 0 0 0 0 0 0 0 0\n G18 0 0 0 0 0 0 0 0 1 0 0 0 0\n G19 0 1 0 0 1 0 1 0 0 0 1 0 0\n G20 0 0 0 0 0 0 0 0 0 1 0 1 1\n G21 1 0 0 0 1 0 0 0 0 1 0 0 0\n G22 0 0 0 0 0 0 0 0 0 0 0 0 1\n G23 0 1 0 0 0 1 0 0 0 0 0 1 0\n G24 0 0 0 0 0 0 1 0 0 0 0 0 0\n G25 0 0 1 0 0 0 0 0 1 0 1 0 0\n G26 0 0 0 1 0 0 0 1 0 0 0 0 0\n G27 1 0 0 0 0 0 1 1 0 0 0 0 0\n G28 0 1 1 0 0 0 0 1 0 0 0 0 0\n G29 0 0 0 0 0 0 0 1 0 0 0 1 0\n G30 0 0 0 0 1 1 0 1 1 0 0 0 1\n G31 0 0 0 0 0 0 0 1 0 1 1 0 0\n\n\nThere are 31 varieties and it is perfectly balanced, with exactly one observation per treatment per block.\nHere is a quick check I run to count the number of missing data in each column.\n\napply(dat, 2, function(x) sum(is.na(x)))\n\nblock gen yield row col \n 0 0 0 0 0 \n\n\nWe observed no missing data!\nLast, check the dependent variable. A histogram is often quite sufficient to accomplish this. This is designed to be a quick check, so no need to spend time making the plot look good.\n\nhist(dat$yield, main = \"\", xlab = \"yield\")\n\n\n\n\n\n\n\n\n\n\nFigure 8.1: Histogram of the dependent variable.\n\n\n\n\nThis data set is ready for analysis!\n\n\n8.2.3 Model Building\n\nlme4nlme\n\n\n\nmodel_icbd <- lmer(yield ~ gen + (1|block),\n data = dat, \n na.action = na.exclude)\ntidy(model_icbd)\n\n# A tibble: 33 × 8\n effect group term estimate std.error statistic df p.value\n <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n 1 fixed <NA> (Intercept) 24.6 0.922 26.7 153. 2.30e-59\n 2 fixed <NA> genG02 2.40 1.17 2.06 129. 4.17e- 2\n 3 fixed <NA> genG03 8.04 1.17 6.88 129. 2.31e-10\n 4 fixed <NA> genG04 2.37 1.17 2.03 129. 4.42e- 2\n 5 fixed <NA> genG05 1.60 1.17 1.37 129. 1.73e- 1\n 6 fixed <NA> genG06 7.39 1.17 6.32 129. 3.82e- 9\n 7 fixed <NA> genG07 -0.419 1.17 -0.359 129. 7.20e- 1\n 8 fixed <NA> genG08 3.04 1.17 2.60 129. 1.04e- 2\n 9 fixed <NA> genG09 4.84 1.17 4.14 129. 6.22e- 5\n10 fixed <NA> genG10 -0.0429 1.17 -0.0367 129. 9.71e- 1\n# ℹ 23 more rows\n\n\n\n#model_icbd1 <- lmer(yield ~ gen + (1|block) + (1|row:block),\n# data = dat, \n# na.action = na.exclude)\n#tidy(model_icbd1)\n\n\n\n\nmodel_icbd <- lme(yield ~ gen,\n random = ~ 1|block,\n data = dat, \n na.action = na.exclude)\ntidy(model_icbd)\n\n\n\n\n\n\n8.2.4 Check Model Assumptions\n\ncheck_model(model_icbd)\n\n\n\n\n\n\n\n\n\n\n8.2.5 Inference\n\nanova(model_icbd)\n\nType III Analysis of Variance Table with Satterthwaite's method\n Sum Sq Mean Sq NumDF DenDF F value Pr(>F) \ngen 1901.1 63.369 30 129.06 17.675 < 2.2e-16 ***\n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\n\n\nemmeans(model_icbd, ~ gen)\n\n gen emmean SE df lower.CL upper.CL\n G01 24.6 0.923 153 22.7 26.4\n G02 27.0 0.923 153 25.2 28.8\n G03 32.6 0.923 153 30.8 34.4\n G04 26.9 0.923 153 25.1 28.8\n G05 26.2 0.923 153 24.4 28.0\n G06 32.0 0.923 153 30.1 33.8\n G07 24.2 0.923 153 22.3 26.0\n G08 27.6 0.923 153 25.8 29.4\n G09 29.4 0.923 153 27.6 31.2\n G10 24.5 0.923 153 22.7 26.4\n G11 27.1 0.923 153 25.2 28.9\n G12 29.3 0.923 153 27.4 31.1\n G13 29.9 0.923 153 28.1 31.8\n G14 24.2 0.923 153 22.4 26.1\n G15 26.1 0.923 153 24.3 27.9\n G16 25.9 0.923 153 24.1 27.8\n G17 19.7 0.923 153 17.9 21.5\n G18 25.7 0.923 153 23.9 27.5\n G19 29.0 0.923 153 27.2 30.9\n G20 33.2 0.923 153 31.3 35.0\n G21 31.1 0.923 153 29.3 32.9\n G22 25.2 0.923 153 23.3 27.0\n G23 29.8 0.923 153 28.0 31.6\n G24 33.6 0.923 153 31.8 35.5\n G25 27.0 0.923 153 25.2 28.8\n G26 27.1 0.923 153 25.3 29.0\n G27 23.8 0.923 153 22.0 25.6\n G28 26.5 0.923 153 24.6 28.3\n G29 24.8 0.923 153 22.9 26.6\n G30 36.2 0.923 153 34.4 38.0\n G31 27.1 0.923 153 25.3 28.9\n\nDegrees-of-freedom method: kenward-roger \nConfidence level used: 0.95", + "title": "9 Incomplete Block Design", + "section": "9.2 Example Analysis", + "text": "9.2 Example Analysis\nWe will demonstrate an example data set designed in a balanced incomplete block design. First, load the libraries for analysis and estimation: ::: panel-tabset ### lme4\n\nlibrary(lme4); library(lmerTest); library(emmeans)\nlibrary(dplyr); library(broom.mixed); library(performance)\n\n\n9.2.1 nlme\n\nlibrary(nlme); library(broom.mixed); library(emmeans)\nlibrary(dplyr); library(performance)\n\n:::\nhttps://kwstat.github.io/agridat/reference/weiss.incblock.html\n\n library(agridat)\n data(weiss.incblock)\n dat <- weiss.incblock\n\n\n\n\n\n\n\n\n\n\n\n\n9.2.2 Data integrity checks\nThe first thing is to make sure the data is what we expect. There are two steps:\n\nmake sure data are the expected data type\ncheck the extent of missing data\ninspect the independent variables and make sure the expected levels are present in the data\ninspect the dependent variable to ensure its distribution is following expectations\n\n\nstr(dat)\n\n'data.frame': 186 obs. of 5 variables:\n $ block: Factor w/ 31 levels \"B01\",\"B02\",\"B03\",..: 1 2 3 4 5 6 7 8 9 10 ...\n $ gen : Factor w/ 31 levels \"G01\",\"G02\",\"G03\",..: 24 15 20 18 20 5 22 1 9 14 ...\n $ yield: num 29.8 24.2 30.5 20 35.2 25 23.6 23.6 29.3 25.5 ...\n $ row : int 42 36 30 24 18 12 6 42 36 30 ...\n $ col : int 1 1 1 1 1 1 1 2 2 2 ...\n\n\nThese look okay with block and gen being factor variables and yield, row, and col being numeric variables.\nNext, check the independent variables. Running a cross tabulations is often sufficient to ascertain this.\n\ndat$row <- as.factor(dat$row)\n\n\ntable(dat$gen, dat$block)\n\n \n B01 B02 B03 B04 B05 B06 B07 B08 B09 B10 B11 B12 B13 B14 B15 B16 B17 B18\n G01 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1\n G02 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0\n G03 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0\n G04 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0\n G05 0 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 0 0\n G06 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0\n G07 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0\n G08 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0\n G09 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n G10 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1\n G11 0 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0\n G12 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0\n G13 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0\n G14 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n G15 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0\n G16 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0\n G17 0 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0\n G18 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1\n G19 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0\n G20 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0\n G21 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0\n G22 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1\n G23 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0\n G24 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0\n G25 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0\n G26 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0\n G27 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0\n G28 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1\n G29 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0\n G30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n G31 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0\n \n B19 B20 B21 B22 B23 B24 B25 B26 B27 B28 B29 B30 B31\n G01 1 0 0 0 0 0 0 0 0 0 1 1 0\n G02 0 1 0 0 0 0 0 0 1 1 0 0 0\n G03 0 0 0 0 1 0 0 0 0 0 0 0 0\n G04 0 0 1 0 0 0 1 0 0 0 0 0 1\n G05 0 0 0 0 0 1 0 0 0 0 0 0 0\n G06 1 1 0 1 0 0 0 0 0 0 0 0 1\n G07 0 0 0 1 0 1 0 0 0 0 1 0 0\n G08 0 0 1 1 0 0 0 0 0 1 0 0 0\n G09 0 0 0 1 0 0 1 0 1 0 0 1 0\n G10 0 0 0 1 1 0 0 0 0 0 0 0 0\n G11 1 0 0 0 0 0 0 0 1 0 0 0 0\n G12 0 0 1 0 1 0 0 0 0 0 0 1 0\n G13 0 0 0 0 0 0 0 0 0 0 1 0 1\n G14 0 0 0 0 0 1 1 0 0 1 0 0 0\n G15 0 1 0 0 0 0 0 0 0 0 0 0 0\n G16 1 0 1 0 0 1 0 0 0 0 0 0 0\n G17 0 0 0 0 0 0 0 0 0 0 0 0 0\n G18 0 0 0 0 0 0 0 0 1 0 0 0 0\n G19 0 1 0 0 1 0 1 0 0 0 1 0 0\n G20 0 0 0 0 0 0 0 0 0 1 0 1 1\n G21 1 0 0 0 1 0 0 0 0 1 0 0 0\n G22 0 0 0 0 0 0 0 0 0 0 0 0 1\n G23 0 1 0 0 0 1 0 0 0 0 0 1 0\n G24 0 0 0 0 0 0 1 0 0 0 0 0 0\n G25 0 0 1 0 0 0 0 0 1 0 1 0 0\n G26 0 0 0 1 0 0 0 1 0 0 0 0 0\n G27 1 0 0 0 0 0 1 1 0 0 0 0 0\n G28 0 1 1 0 0 0 0 1 0 0 0 0 0\n G29 0 0 0 0 0 0 0 1 0 0 0 1 0\n G30 0 0 0 0 1 1 0 1 1 0 0 0 1\n G31 0 0 0 0 0 0 0 1 0 1 1 0 0\n\n\nThere are 31 varieties and it is perfectly balanced, with exactly one observation per treatment per block.\nHere is a quick check I run to count the number of missing data in each column.\n\napply(dat, 2, function(x) sum(is.na(x)))\n\nblock gen yield row col \n 0 0 0 0 0 \n\n\nWe observed no missing data!\nLast, check the dependent variable. A histogram is often quite sufficient to accomplish this. This is designed to be a quick check, so no need to spend time making the plot look good.\n\nhist(dat$yield, main = \"\", xlab = \"yield\")\n\n\n\n\n\n\n\n\n\n\nFigure 9.1: Histogram of the dependent variable.\n\n\n\n\nThis data set is ready for analysis!\n\n\n9.2.3 Model Building\n\nlme4nlme\n\n\n\nmodel_icbd <- lmer(yield ~ gen + (1|block),\n data = dat, \n na.action = na.exclude)\ntidy(model_icbd)\n\n# A tibble: 33 × 8\n effect group term estimate std.error statistic df p.value\n <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n 1 fixed <NA> (Intercept) 24.6 0.922 26.7 153. 2.30e-59\n 2 fixed <NA> genG02 2.40 1.17 2.06 129. 4.17e- 2\n 3 fixed <NA> genG03 8.04 1.17 6.88 129. 2.31e-10\n 4 fixed <NA> genG04 2.37 1.17 2.03 129. 4.42e- 2\n 5 fixed <NA> genG05 1.60 1.17 1.37 129. 1.73e- 1\n 6 fixed <NA> genG06 7.39 1.17 6.32 129. 3.82e- 9\n 7 fixed <NA> genG07 -0.419 1.17 -0.359 129. 7.20e- 1\n 8 fixed <NA> genG08 3.04 1.17 2.60 129. 1.04e- 2\n 9 fixed <NA> genG09 4.84 1.17 4.14 129. 6.22e- 5\n10 fixed <NA> genG10 -0.0429 1.17 -0.0367 129. 9.71e- 1\n# ℹ 23 more rows\n\n\n\n#model_icbd1 <- lmer(yield ~ gen + (1|block) + (1|row:block),\n# data = dat, \n# na.action = na.exclude)\n#tidy(model_icbd1)\n\n\n\n\nmodel_icbd <- lme(yield ~ gen,\n random = ~ 1|block,\n data = dat, \n na.action = na.exclude)\ntidy(model_icbd)\n\n\n\n\n\n\n9.2.4 Check Model Assumptions\n\ncheck_model(model_icbd)\n\n\n\n\n\n\n\n\n\n\n9.2.5 Inference\n\nanova(model_icbd)\n\nType III Analysis of Variance Table with Satterthwaite's method\n Sum Sq Mean Sq NumDF DenDF F value Pr(>F) \ngen 1901.1 63.369 30 129.06 17.675 < 2.2e-16 ***\n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\n\n\nemmeans(model_icbd, ~ gen)\n\n gen emmean SE df lower.CL upper.CL\n G01 24.6 0.923 153 22.7 26.4\n G02 27.0 0.923 153 25.2 28.8\n G03 32.6 0.923 153 30.8 34.4\n G04 26.9 0.923 153 25.1 28.8\n G05 26.2 0.923 153 24.4 28.0\n G06 32.0 0.923 153 30.1 33.8\n G07 24.2 0.923 153 22.3 26.0\n G08 27.6 0.923 153 25.8 29.4\n G09 29.4 0.923 153 27.6 31.2\n G10 24.5 0.923 153 22.7 26.4\n G11 27.1 0.923 153 25.2 28.9\n G12 29.3 0.923 153 27.4 31.1\n G13 29.9 0.923 153 28.1 31.8\n G14 24.2 0.923 153 22.4 26.1\n G15 26.1 0.923 153 24.3 27.9\n G16 25.9 0.923 153 24.1 27.8\n G17 19.7 0.923 153 17.9 21.5\n G18 25.7 0.923 153 23.9 27.5\n G19 29.0 0.923 153 27.2 30.9\n G20 33.2 0.923 153 31.3 35.0\n G21 31.1 0.923 153 29.3 32.9\n G22 25.2 0.923 153 23.3 27.0\n G23 29.8 0.923 153 28.0 31.6\n G24 33.6 0.923 153 31.8 35.5\n G25 27.0 0.923 153 25.2 28.8\n G26 27.1 0.923 153 25.3 29.0\n G27 23.8 0.923 153 22.0 25.6\n G28 26.5 0.923 153 24.6 28.3\n G29 24.8 0.923 153 22.9 26.6\n G30 36.2 0.923 153 34.4 38.0\n G31 27.1 0.923 153 25.3 28.9\n\nDegrees-of-freedom method: kenward-roger \nConfidence level used: 0.95", "crumbs": [ - "<span class='chapter-number'>8</span> <span class='chapter-title'>Incomplete Block Design</span>" + "<span class='chapter-number'>9</span> <span class='chapter-title'>Incomplete Block Design</span>" ] }, { @@ -448,5 +448,25 @@ "crumbs": [ "<span class='chapter-number'>9</span> <span class='chapter-title'>Strip Plot Design</span>" ] + }, + { + "objectID": "chapters/Lattice-design.html", + "href": "chapters/Lattice-design.html", + "title": "10 Lattice Design", + "section": "", + "text": "10.1 Background\nYates (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 = k2, t = k3, or t = k(k +1).\nEven 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.\nStatistical model for lattice design:\n\\(Y_{ijk} = \\mu + \\alpha_i + \\gamma_j + \\tau_t + \\beta_k + \\epsilon_ijk\\)\nwhere, \\(\\mu\\) is the experiment mean, 𝛽 is the row effect, 𝛾 is the column effect, and 𝜏 is the treatment effect.", + "crumbs": [ + "<span class='chapter-number'>10</span> <span class='chapter-title'>Lattice Design</span>" + ] + }, + { + "objectID": "chapters/Lattice-design.html#example-analysis", + "href": "chapters/Lattice-design.html#example-analysis", + "title": "10 Lattice Design", + "section": "10.2 Example Analysis", + "text": "10.2 Example Analysis\nThe 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.\nLet’s start the analysis firstly by loading the required libraries:\n\nlme4nlme\n\n\n\nlibrary(lme4); library(lmerTest); library(emmeans); library(performance)\nlibrary(dplyr); library(broom.mixed); library(agridat); library(desplot)\n\n\n\n\nlibrary(nlme); library(broom.mixed); library(emmeans); library(performance)\nlibrary(dplyr); library(agridat); library(desplot)\n\n\n\n\nImport data from agridat package. The data contains . This is a balanced experiment design\n\ndata(cochran.lattice)\ndat2 <- cochran.lattice\nhead(dat2)\n\n y rep row col trt\n1 9.0 R1 1 1 T10\n2 20.3 R1 1 2 T12\n3 17.7 R1 1 3 T09\n4 26.3 R1 1 4 T11\n5 4.7 R1 2 1 T02\n6 9.0 R1 2 2 T04\n\nstr(dat2)\n\n'data.frame': 80 obs. of 5 variables:\n $ y : num 9 20.3 17.7 26.3 4.7 9 7.3 8.3 9 6.7 ...\n $ rep: Factor w/ 5 levels \"R1\",\"R2\",\"R3\",..: 1 1 1 1 1 1 1 1 1 1 ...\n $ row: int 1 1 1 1 2 2 2 2 3 3 ...\n $ col: int 1 2 3 4 1 2 3 4 1 2 ...\n $ trt: Factor w/ 16 levels \"T01\",\"T02\",\"T03\",..: 10 12 9 11 2 4 1 3 14 16 ...\n\nlibs(desplot)\ndesplot(dat2, y~row*col|rep,\n text=trt, # aspect unknown, should be 2 or .5\n main=\"cochran.lattice\")\n\n\n\n\n\n\n\n\n\ndata(burgueno.rowcol)\ndat <- burgueno.rowcol\nhead(dat)\n\n rep row col gen yield\n1 R1 1 1 G05 1.5318\n2 R1 1 2 G19 2.2211\n3 R1 1 3 G55 1.4589\n4 R1 1 4 G23 1.2436\n5 R1 1 5 G27 1.8989\n6 R1 1 6 G38 1.3366\n\n\nHere, we can use the desplot() function from the ‘desplot’ package to visualize the plot plan from lattice design.\n\n# Two contiuous reps in 8 rows, 16 columns\ndesplot(dat, yield ~ col*row,\n out1=rep, # aspect unknown\n text=gen, shorten=\"none\", cex=0.75,\n main=\"lattice design\")\n\n\n\n\n\n\n\n\n\n10.2.1 Data integrity checks\n\n\n\n\n\n\nHistogram of the dependent variable.\n\n\n\n\n\n10.2.2 Data integrity checks\n\nstr(dat)\n\n'data.frame': 128 obs. of 5 variables:\n $ rep : Factor w/ 2 levels \"R1\",\"R2\": 1 1 1 1 1 1 1 1 1 1 ...\n $ row : int 1 1 1 1 1 1 1 1 1 1 ...\n $ col : int 1 2 3 4 5 6 7 8 9 10 ...\n $ gen : Factor w/ 64 levels \"G01\",\"G02\",\"G03\",..: 5 19 55 23 27 38 64 44 14 13 ...\n $ yield: num 1.53 2.22 1.46 1.24 1.9 ...\n\n\n\ndat2$row <- as.factor(dat2$row)\ndat2$col <- as.factor(dat2$col)\n\ndat$row <- as.factor(dat$row)\ndat$col <- as.factor(dat$col)\n\n\nhist(dat2$y, main = \"\", xlab = \"yield\")\n\n\n\n\n\n\n\n\n\n\nFigure 10.1: Histogram of the dependent variable.\n\n\n\n\n\nlme4nlme\n\n\n\nm1_a <- lmer(yield ~ gen + (1|row) + (1|col:rep) + (1|rep),\n data = dat,\n na.action = na.exclude)\nsummary(m1_a) \n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: yield ~ gen + (1 | row) + (1 | col:rep) + (1 | rep)\n Data: dat\n\nREML criterion at convergence: 168.7\n\nScaled residuals: \n Min 1Q Median 3Q Max \n-1.1392 -0.4036 0.0000 0.4036 1.1392 \n\nRandom effects:\n Groups Name Variance Std.Dev.\n col:rep (Intercept) 0.2189 0.4679 \n row (Intercept) 0.1646 0.4057 \n rep (Intercept) 0.1916 0.4378 \n Residual 0.1796 0.4238 \nNumber of obs: 128, groups: col:rep, 32; row, 8; rep, 2\n\nFixed effects:\n Estimate Std. Error df t value Pr(>|t|) \n(Intercept) 2.325589 0.509444 4.216418 4.565 0.0091 **\ngenG02 0.349182 0.523392 38.995063 0.667 0.5086 \ngenG03 0.371260 0.531293 41.034622 0.699 0.4886 \ngenG04 0.475842 0.527614 43.470779 0.902 0.3721 \ngenG05 -0.601225 0.513762 38.892580 -1.170 0.2490 \ngenG06 0.574869 0.527284 40.643852 1.090 0.2820 \ngenG07 0.244490 0.534996 42.592433 0.457 0.6500 \ngenG08 0.606486 0.527879 43.602192 1.149 0.2569 \ngenG09 0.010630 0.525899 42.747488 0.020 0.9840 \ngenG10 0.509855 0.527357 43.301826 0.967 0.3390 \ngenG11 0.463014 0.535708 42.977451 0.864 0.3922 \ngenG12 0.340678 0.517892 43.399748 0.658 0.5141 \ngenG13 -0.041178 0.483241 34.257292 -0.085 0.9326 \ngenG14 0.132480 0.523679 39.142513 0.253 0.8016 \ngenG15 0.385104 0.526349 43.013937 0.732 0.4683 \ngenG16 -0.148379 0.483194 34.227894 -0.307 0.7606 \ngenG17 -0.016143 0.536067 42.926995 -0.030 0.9761 \ngenG18 0.358218 0.526325 42.993175 0.681 0.4998 \ngenG19 0.734743 0.533892 41.978194 1.376 0.1761 \ngenG20 0.212299 0.521319 40.753106 0.407 0.6860 \ngenG21 0.150212 0.525313 39.814746 0.286 0.7764 \ngenG22 -0.039713 0.497948 37.586406 -0.080 0.9369 \ngenG23 0.325771 0.484472 34.701705 0.672 0.5058 \ngenG24 -0.194686 0.524899 39.587776 -0.371 0.7127 \ngenG25 0.202462 0.514979 39.325398 0.393 0.6963 \ngenG26 0.089411 0.483188 34.221812 0.185 0.8543 \ngenG27 0.218244 0.536631 43.262734 0.407 0.6862 \ngenG28 -0.284235 0.524825 39.538457 -0.542 0.5911 \ngenG29 0.047110 0.515184 39.470339 0.091 0.9276 \ngenG30 -0.213561 0.484574 34.769665 -0.441 0.6621 \ngenG31 -0.034873 0.535702 42.734026 -0.065 0.9484 \ngenG32 1.000827 0.535020 42.606153 1.871 0.0683 . \ngenG33 0.252960 0.507660 40.377683 0.498 0.6210 \ngenG34 0.242054 0.537217 43.562588 0.451 0.6545 \ngenG35 0.213005 0.515262 39.472578 0.413 0.6816 \ngenG36 0.362633 0.525014 42.290855 0.691 0.4935 \ngenG37 0.282612 0.530472 40.615244 0.533 0.5971 \ngenG38 -0.125437 0.537059 43.462082 -0.234 0.8164 \ngenG39 1.261824 0.537018 43.466180 2.350 0.0234 * \ngenG40 0.346211 0.536855 43.369657 0.645 0.5224 \ngenG41 -0.255692 0.522110 41.202626 -0.490 0.6269 \ngenG42 0.744461 0.483144 34.195322 1.541 0.1326 \ngenG43 0.489907 0.535381 42.795749 0.915 0.3653 \ngenG44 0.445400 0.527076 43.156823 0.845 0.4027 \ngenG45 0.728849 0.531497 41.172558 1.371 0.1777 \ngenG46 0.008386 0.527720 43.541892 0.016 0.9874 \ngenG47 -0.173693 0.525585 42.635003 -0.330 0.7427 \ngenG48 0.364422 0.523287 41.600011 0.696 0.4900 \ngenG49 0.283642 0.535631 42.924562 0.530 0.5992 \ngenG50 -0.160189 0.534315 42.227391 -0.300 0.7658 \ngenG51 0.127042 0.526978 43.139993 0.241 0.8106 \ngenG52 -0.277455 0.534469 42.326672 -0.519 0.6064 \ngenG53 -0.401069 0.525510 42.532998 -0.763 0.4496 \ngenG54 -0.221400 0.533965 42.027349 -0.415 0.6805 \ngenG55 0.479012 0.524627 42.079587 0.913 0.3664 \ngenG56 0.232007 0.536959 43.388811 0.432 0.6678 \ngenG57 -0.153493 0.526605 42.888008 -0.291 0.7721 \ngenG58 0.545562 0.523508 41.715186 1.042 0.3034 \ngenG59 0.691577 0.536175 43.006805 1.290 0.2040 \ngenG60 -0.221321 0.517482 37.741262 -0.428 0.6713 \ngenG61 0.205307 0.514087 39.066489 0.399 0.6918 \ngenG62 0.341897 0.534904 42.530411 0.639 0.5261 \ngenG63 0.701913 0.517290 40.377937 1.357 0.1823 \ngenG64 0.066248 0.526946 40.462383 0.126 0.9006 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\n\n\nCorrelation matrix not shown by default, as p = 64 > 12.\nUse print(x, correlation=TRUE) or\n vcov(x) if you need it\n\n\n\n\n\ndat$dummy <- factor(1)\n\nm1_b <- lme(yield ~ gen,\n random = list(dummy = pdBlocked(list(\n pdIdent(~row - 1),\n pdIdent(~rep - 1),\n pdIdent(~col:rep)))),\n data = dat, \n na.action = na.exclude)\n\nVarCorr(m1_b)\n\ndummy = pdIdent(row - 1), pdIdent(rep - 1), pdIdent(col:rep) \n Variance StdDev \nrow1 0.1645986 0.4057076\nrow2 0.1645986 0.4057076\nrow3 0.1645986 0.4057076\nrow4 0.1645986 0.4057076\nrow5 0.1645986 0.4057076\nrow6 0.1645986 0.4057076\nrow7 0.1645986 0.4057076\nrow8 0.1645986 0.4057076\nrepR1 0.1916416 0.4377688\nrepR2 0.1916416 0.4377688\n(Intercept) 0.2188853 0.4678517\ncol1:repR1 0.2188853 0.4678517\ncol2:repR1 0.2188853 0.4678517\ncol3:repR1 0.2188853 0.4678517\ncol4:repR1 0.2188853 0.4678517\ncol5:repR1 0.2188853 0.4678517\ncol6:repR1 0.2188853 0.4678517\ncol7:repR1 0.2188853 0.4678517\ncol8:repR1 0.2188853 0.4678517\ncol9:repR1 0.2188853 0.4678517\ncol10:repR1 0.2188853 0.4678517\ncol11:repR1 0.2188853 0.4678517\ncol12:repR1 0.2188853 0.4678517\ncol13:repR1 0.2188853 0.4678517\ncol14:repR1 0.2188853 0.4678517\ncol15:repR1 0.2188853 0.4678517\ncol16:repR1 0.2188853 0.4678517\ncol1:repR2 0.2188853 0.4678517\ncol2:repR2 0.2188853 0.4678517\ncol3:repR2 0.2188853 0.4678517\ncol4:repR2 0.2188853 0.4678517\ncol5:repR2 0.2188853 0.4678517\ncol6:repR2 0.2188853 0.4678517\ncol7:repR2 0.2188853 0.4678517\ncol8:repR2 0.2188853 0.4678517\ncol9:repR2 0.2188853 0.4678517\ncol10:repR2 0.2188853 0.4678517\ncol11:repR2 0.2188853 0.4678517\ncol12:repR2 0.2188853 0.4678517\ncol13:repR2 0.2188853 0.4678517\ncol14:repR2 0.2188853 0.4678517\ncol15:repR2 0.2188853 0.4678517\ncol16:repR2 0.2188853 0.4678517\nResidual 0.1795838 0.4237733\n\n\n\n\n\n\n\n10.2.3 Check Model Assumptions\nRemember those iid assumptions? Let’s make sure we actually met them.\n\ncheck_model(m1_a)\n\n\n\n\n\n\n\n\n\n\n10.2.4 Inference\nEstimates for each treatment level can be obtained with the ‘emmeans’ package. And we can extract the ANOVA table from model using anova() function.\n\nanova(m1_a)\n\nType III Analysis of Variance Table with Satterthwaite's method\n Sum Sq Mean Sq NumDF DenDF F value Pr(>F)\ngen 9.5245 0.15118 63 34.322 0.8418 0.7274\n\n\nEstimated marginal means\n\nemmeans(m1_a, ~ gen)\n\n gen emmean SE df lower.CL upper.CL\n G01 2.33 0.515 4.21 0.923 3.73\n G02 2.67 0.515 4.21 1.272 4.08\n G03 2.70 0.515 4.21 1.294 4.10\n G04 2.80 0.515 4.21 1.399 4.20\n G05 1.72 0.515 4.21 0.322 3.13\n G06 2.90 0.515 4.20 1.497 4.30\n G07 2.57 0.515 4.21 1.167 3.97\n G08 2.93 0.515 4.21 1.529 4.33\n G09 2.34 0.515 4.20 0.933 3.74\n G10 2.84 0.515 4.20 1.432 4.24\n G11 2.79 0.515 4.20 1.385 4.19\n G12 2.67 0.515 4.19 1.263 4.07\n G13 2.28 0.515 4.21 0.882 3.69\n G14 2.46 0.515 4.20 1.055 3.86\n G15 2.71 0.515 4.20 1.307 4.11\n G16 2.18 0.515 4.21 0.775 3.58\n G17 2.31 0.515 4.19 0.906 3.71\n G18 2.68 0.515 4.21 1.281 4.09\n G19 3.06 0.514 4.18 1.657 4.46\n G20 2.54 0.515 4.20 1.135 3.94\n G21 2.48 0.515 4.19 1.072 3.88\n G22 2.29 0.515 4.21 0.883 3.69\n G23 2.65 0.515 4.21 1.249 4.05\n G24 2.13 0.515 4.19 0.727 3.53\n G25 2.53 0.515 4.20 1.125 3.93\n G26 2.42 0.515 4.21 1.013 3.82\n G27 2.54 0.515 4.20 1.141 3.95\n G28 2.04 0.515 4.20 0.638 3.44\n G29 2.37 0.515 4.20 0.970 3.78\n G30 2.11 0.515 4.19 0.708 3.52\n G31 2.29 0.514 4.18 0.887 3.69\n G32 3.33 0.515 4.20 1.923 4.73\n G33 2.58 0.514 4.19 1.175 3.98\n G34 2.57 0.515 4.21 1.165 3.97\n G35 2.54 0.515 4.20 1.136 3.94\n G36 2.69 0.515 4.20 1.285 4.09\n G37 2.61 0.515 4.20 1.205 4.01\n G38 2.20 0.515 4.21 0.797 3.60\n G39 3.59 0.515 4.20 2.184 4.99\n G40 2.67 0.515 4.21 1.269 4.07\n G41 2.07 0.514 4.18 0.666 3.47\n G42 3.07 0.515 4.21 1.668 4.47\n G43 2.82 0.515 4.20 1.412 4.22\n G44 2.77 0.515 4.20 1.368 4.17\n G45 3.05 0.515 4.20 1.651 4.46\n G46 2.33 0.515 4.21 0.931 3.74\n G47 2.15 0.515 4.20 0.749 3.56\n G48 2.69 0.515 4.19 1.286 4.09\n G49 2.61 0.515 4.22 1.207 4.01\n G50 2.17 0.514 4.19 0.762 3.57\n G51 2.45 0.514 4.19 1.049 3.86\n G52 2.05 0.514 4.19 0.644 3.45\n G53 1.92 0.515 4.19 0.521 3.33\n G54 2.10 0.514 4.18 0.700 3.51\n G55 2.80 0.514 4.18 1.401 4.21\n G56 2.56 0.515 4.20 1.155 3.96\n G57 2.17 0.515 4.19 0.769 3.58\n G58 2.87 0.514 4.18 1.467 4.28\n G59 3.02 0.514 4.19 1.613 4.42\n G60 2.10 0.516 4.22 0.702 3.51\n G61 2.53 0.515 4.21 1.128 3.93\n G62 2.67 0.514 4.18 1.264 4.07\n G63 3.03 0.514 4.19 1.624 4.43\n G64 2.39 0.515 4.19 0.988 3.80\n\nDegrees-of-freedom method: kenward-roger \nConfidence level used: 0.95", + "crumbs": [ + "<span class='chapter-number'>10</span> <span class='chapter-title'>Lattice Design</span>" + ] } ] \ No newline at end of file