diff --git a/chapters/lattice-design.qmd b/chapters/lattice-design.qmd index ded829c..f86c022 100644 --- a/chapters/lattice-design.qmd +++ b/chapters/lattice-design.qmd @@ -1,28 +1,26 @@ ---- -title: "Lattice Design" ---- +# Lattice Design -# Background +## 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 = k3, or t = k(k +1). +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. -https://kwstat.github.io/agridat/reference/cochran.lattice.html - - Statistical model for lattice design: -$Yijk = \mu + \alpha_i + \gamma_j + \tau_t + \beta_k + \epsilon_ijk$ +$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 -First, load the libraries for analysis and estimation: +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) @@ -34,33 +32,61 @@ library(dplyr); library(agridat); library(desplot) ``` ::: -Import data from agridat package and create columns for row and column as factor variables. This is a balanced experiment design +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 contiguous reps in 8 rows, 16 columns +# 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(dat$yield, main = "", xlab = "yield") +hist(dat2$y, main = "", xlab = "yield") ``` ```{r, echo=FALSE} @@ -75,8 +101,8 @@ hist(dat$yield, main = "", xlab = "yield", cex.lab = 1.8, cex.axis = 1.5) ### lme4 ```{r} -m1 <- lmer(yield ~ gen + (1|rep) + (1|rep:row) + (1|rep:col), - data=dat, +m1 <- lmer(y ~ trt + (1|rep) + (1|rep:row) + (1|rep:col), + data=dat2, na.action = na.exclude) summary(m1) ``` @@ -85,7 +111,7 @@ summary(m1) ```{r, eval=FALSE} ## lme not working for this, need help in fixing it -#m1 <- lme(yield ~ gen, +m1 <- lme(yield ~ gen, random = ~ 1|rep + 1|rep:row + 1|rep:col, data = dat, na.action = na.exclude) @@ -95,12 +121,11 @@ summary(m1) ### Check Model Assumptions Remember those iid assumptions? Let's make sure we actually met them. + ```{r, fig.height=9} check_model(m1) ``` - - ```{r} #Random rep, row and col within rep m1 <- lmer(yield ~ gen + (1|rep) + (1|rep:row) + (1|rep:col), data=dat) @@ -108,6 +133,7 @@ summary(m1) anova(m1) ``` + ### 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. diff --git a/docs/search.json b/docs/search.json index 61b4811..4973ce7 100644 --- a/docs/search.json +++ b/docs/search.json @@ -214,7 +214,7 @@ "href": "chapters/lattice-design.html", "title": "9Ā  Lattice Design", "section": "", - "text": "10 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 = k^2, 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.\nhttps://kwstat.github.io/agridat/reference/cochran.lattice.html\nStatistical model for lattice design:\n\\(Yijk = \\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.", + "text": "9.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": [ "9Ā  Lattice Design" ] @@ -403,8 +403,8 @@ "objectID": "chapters/lattice-design.html#example-analysis", "href": "chapters/lattice-design.html#example-analysis", "title": "9Ā  Lattice Design", - "section": "10.1 Example Analysis", - "text": "10.1 Example Analysis\nFirst, load the libraries for analysis and estimation:\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 and create columns for row and column as factor variables. This is a balanced experiment design\n\ndata(burgueno.rowcol)\ndat <- burgueno.rowcol\n\n\n# Two contiguous reps in 8 rows, 16 columns\n\ndesplot(dat, yield ~ col*row,\n out1=rep, # aspect unknown\n text=gen, shorten=\"none\", cex=.75,\n main=\"burgueno.rowcol\")\n\n\n\n\n\n\n\n\n\n10.1.1 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\ndat$row <- as.factor(dat$row)\ndat$col <- as.factor(dat$col)\n\n\nhist(dat$yield, 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 <- lmer(yield ~ gen + (1|rep) + (1|rep:row) + (1|rep:col), \n data=dat, \n na.action = na.exclude)\nsummary(m1) \n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: yield ~ gen + (1 | rep) + (1 | rep:row) + (1 | rep:col)\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 rep:col (Intercept) 0.2189 0.4679 \n rep:row (Intercept) 0.1646 0.4057 \n rep (Intercept) 0.1916 0.4378 \n Residual 0.1796 0.4238 \nNumber of obs: 128, groups: rep:col, 32; rep: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\n## lme not working for this, need help in fixing it\n#m1 <- lme(yield ~ gen,\n random = ~ 1|rep + 1|rep:row + 1|rep:col,\n data = dat, \n na.action = na.exclude)\n\n\n\n\n\n\n10.1.2 Check Model Assumptions\nRemember those iid assumptions? Letā€™s make sure we actually met them.\n\ncheck_model(m1)\n\n\n\n\n\n\n\n\n\n#Random rep, row and col within rep\n m1 <- lmer(yield ~ gen + (1|rep) + (1|rep:row) + (1|rep:col), data=dat)\nsummary(m1) \n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: yield ~ gen + (1 | rep) + (1 | rep:row) + (1 | rep:col)\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 rep:col (Intercept) 0.2189 0.4679 \n rep:row (Intercept) 0.1646 0.4057 \n rep (Intercept) 0.1916 0.4378 \n Residual 0.1796 0.4238 \nNumber of obs: 128, groups: rep:col, 32; rep: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\nanova(m1)\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\n\n\n10.1.3 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)\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, ~ 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", + "section": "9.2 Example Analysis", + "text": "9.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\n9.2.1 Data integrity checks\n\n\n\n\n\n\nHistogram of the dependent variable.\n\n\n\n\n\n9.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Ā 9.1: Histogram of the dependent variable.\n\n\n\n\n\nlme4nlme\n\n\n\nm1 <- lmer(y ~ trt + (1|rep) + (1|rep:row) + (1|rep:col), \n data=dat2, \n na.action = na.exclude)\n\nboundary (singular) fit: see help('isSingular')\n\nsummary(m1) \n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: y ~ trt + (1 | rep) + (1 | rep:row) + (1 | rep:col)\n Data: dat2\n\nREML criterion at convergence: 433.9\n\nScaled residuals: \n Min 1Q Median 3Q Max \n-2.1384 -0.5057 -0.0117 0.4584 2.2629 \n\nRandom effects:\n Groups Name Variance Std.Dev.\n rep:col (Intercept) 3.17 1.781 \n rep:row (Intercept) 10.92 3.304 \n rep (Intercept) 0.00 0.000 \n Residual 23.86 4.885 \nNumber of obs: 80, groups: rep:col, 20; rep:row, 20; rep, 5\n\nFixed effects:\n Estimate Std. Error df t value Pr(>|t|) \n(Intercept) 6.090 2.566 61.592 2.373 0.02078 * \ntrtT02 7.641 3.451 47.810 2.214 0.03163 * \ntrtT03 2.403 3.451 47.810 0.696 0.48960 \ntrtT04 5.254 3.451 47.810 1.522 0.13451 \ntrtT05 3.472 3.451 47.810 1.006 0.31942 \ntrtT06 1.206 3.451 47.810 0.350 0.72824 \ntrtT07 1.208 3.451 47.810 0.350 0.72778 \ntrtT08 3.323 3.451 47.810 0.963 0.34045 \ntrtT09 4.024 3.451 47.810 1.166 0.24941 \ntrtT10 9.094 3.451 47.810 2.635 0.01131 * \ntrtT11 11.815 3.451 47.810 3.423 0.00128 **\ntrtT12 6.756 3.451 47.810 1.958 0.05612 . \ntrtT13 4.942 3.451 47.810 1.432 0.15865 \ntrtT14 8.160 3.451 47.810 2.364 0.02217 * \ntrtT15 3.205 3.451 47.810 0.929 0.35778 \ntrtT16 4.537 3.451 47.810 1.315 0.19492 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\n\n\nCorrelation matrix not shown by default, as p = 16 > 12.\nUse print(x, correlation=TRUE) or\n vcov(x) if you need it\n\n\noptimizer (nloptwrap) convergence code: 0 (OK)\nboundary (singular) fit: see help('isSingular')\n\n\n\n\n\n## lme not working for this, need help in fixing it\nm1 <- lme(yield ~ gen,\n random = ~ 1|rep + 1|rep:row + 1|rep:col,\n data = dat, \n na.action = na.exclude)\n\n\n\n\n\n\n9.2.3 Check Model Assumptions\nRemember those iid assumptions? Letā€™s make sure we actually met them.\n\ncheck_model(m1)\n\n\n\n\n\n\n\n\n\n#Random rep, row and col within rep\n m1 <- lmer(yield ~ gen + (1|rep) + (1|rep:row) + (1|rep:col), data=dat)\nsummary(m1) \n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: yield ~ gen + (1 | rep) + (1 | rep:row) + (1 | rep:col)\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 rep:col (Intercept) 0.2189 0.4679 \n rep:row (Intercept) 0.1646 0.4057 \n rep (Intercept) 0.1916 0.4378 \n Residual 0.1796 0.4238 \nNumber of obs: 128, groups: rep:col, 32; rep: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\nanova(m1)\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\n\n\n9.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)\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, ~ 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": [ "9Ā  Lattice Design" ]