diff --git a/chapters/means-and-contrasts.qmd b/chapters/means-and-contrasts.qmd
index b42b77b..1b608ca 100644
--- a/chapters/means-and-contrasts.qmd
+++ b/chapters/means-and-contrasts.qmd
@@ -61,12 +61,12 @@ Now that we have a good model, let’s use the emmeans() function to obtain EMMs
Now that we have fitted a linear mixed model (model1) and it meets the model assumption. Let's use the `emmeans()` function to obtain estimated marginal means for main (variety and nitrogen) and interaction (variety x nitrogen) effects.
#### Main effects
-```{r}
+```{r, warning=FALSE}
m1 <- emmeans(model1, ~V, level = 0.95)
m1
```
-```{r}
+```{r, warning=FALSE}
m2 <- emmeans(model1, ~N)
m2
```
@@ -97,36 +97,20 @@ pairs(m2)
Here if we look at the results from code chunk above, it's easy to interpret results from `pairs()` function in case of varietey comparison becuase there were only 3 groups. It's bit confusing in case of Nitrogen treatments where we had 4 groups. We can further simplify it by using custom contrasts.
+::: {.callout-caution}
+## `pairs()`
+Remember!!
+The `pairs()` function can be used to calculate pairwise comparison when treatment groups are less than equal to 3.
+:::
### Custom contrasts
-1. Treatment
-
-Firstly, let's run emmean object 'm1' for variety compariosn.
+Firstly, let's run emmean object 'm2' for nitrogen treatment comparison.
```{r}
m2
```
-```{r, echo=FALSE}
-#emmeans(model1, specs = trt.vs.ctrlk ~ N)
-```
-
-
-
-```{r}
-coef(pairs(m1))
-```
-
-Now, lets a create a vector for each variety in the same order as presented in output from m1.
-
+Now, lets a create a vector for each nitrogen treatment in the same order as presented in output from m2.
```{r}
-A1 = c(1, 0, 0)
-A2 = c(0, 1, 0)
-A3 = c(0, 0, 1)
-
-```
-
-
-```{r, echo =FALSE}
A1 = c(1, 0, 0, 0)
A2 = c(0, 1, 0, 0)
A3 = c(0, 0, 1, 0)
@@ -138,7 +122,6 @@ Let's create custom contrasts for comparing '0.0cwt' (A1) treatment to '0.2cwt'
This can be evaluated as shown below:
Here the output shows the difference in mean yield between these two varieties
```{r}
-pairs(m2, adjust = "tukey")
contrast(m2, method = list(A1 - A2) )
contrast(m2, method = list(A1 - A3) )
contrast(m2, method = list(A1 - A4) )
@@ -149,13 +132,6 @@ Using custom contrasts is strongly recommended instead of `pairs()` when you are
:::
-::: {.callout-caution}
-## `pairs()`
-Remember!!
-The `pairs()` function can be used to calculate pairwise comparison when treatment groups are less than equal to 3.
-:::
-
-
## Compact letter displays
Compact letter displays (CLDs) are a popular way to display multiple comparisons when there are more than few group means to compare. However, they are problematic as they are more prone to misinterpretation.
The R package `multcompView` (Graves et al., 2019) provides an implementation of CLDs creating a display where any two means associated with same symbol are not statistically different.
@@ -179,9 +155,49 @@ cld(m3, alpha=0.05, Letters=letters)
```
Interpretation of these letters is: Here we have a significant difference in grain yield with varieties "victory", with N treatments of 0.0cwt, 0.2cwt, 0.4cwt, and 0.6wt. Grain yield for Golden.rain variety was significantly lower with 0.0cwt N treatment compared to the 0.2cwt, 0.4cwt, and 0.6wt treatments.
-
+In the data set we used for demonstration here, we had equal number of observations in each group. However, this might not be a case every time as it is common to have missing values in the data set. In such cases, readers usually struggle to interpret significant differences among groups. For example, estimated means of two groups are substantially different but they are no statistically different. This normally happens when SE of one group is large due to its small sample size, so it's hard for it to be statistically different from other groups. In such cases, we can use alternatives to CLDs as shown below.
## Alternatives to CLD
+
+1. Equivalence test
+
+Let's assume based on subject matter considerations, if mean yield of two groups differ by less than 30 can be considered equivalent.
+Let's try equivalence test on clds of nitrogen treatment emmeans (m2)
+```{r}
+cld(m2, delta = 30, adjust = "none")
+```
+Here, two treatment groups '0.0cwt' and '0.2cwt', '0.4cwt' and '0.6cwt' can be considered equivalent.
+
+2. Significance Sets
+
+Another alternative is to simply reverse all the boolean flags we used in constructing CLDs for m3 first time.
+
+
+```{r}
+cld(m2, signif = TRUE)
+```
+## Export emmeans to excel sheet
+
+The emmean objects can be directly exported
+
+### start from here
+```{r}
+result_n <- as.data.frame(summary(m1))
+```
+
+
+```{r}
+library(writexl)
+write_xlsx(result_n)
+```
+
+
+```{r}
+
+```
+
+
+
```{r, eval=FALSE, echo = FALSE}
One-way estimated marginal means and plot
@@ -198,14 +214,6 @@ CLD = cld(marginal,
CLD
-Location emmean SE df lower.CL upper.CL .group
- Olympia 8.333333 0.6718548 16 6.449596 10.21707 a
- Northampton 11.833333 0.6718548 16 9.949596 13.71707 b
- Ventura 13.333333 0.6718548 16 11.449596 15.21707 b
- Burlington 21.833333 0.6718548 16 19.949596 23.71707 c
-
-
-
### Order the levels for printing
CLD$Location = factor(CLD$Location,
@@ -258,6 +266,12 @@ ggplot(CLD,
```
+
+
+## creating plots with emmeans
+
+
+
### Interactions using Emmeans
```{r, eval=FALSE, echo=FALSE}
diff --git a/docs/search.json b/docs/search.json
index b7e3cfe..bbc3f5f 100644
--- a/docs/search.json
+++ b/docs/search.json
@@ -859,8 +859,8 @@
"objectID": "chapters/means-and-contrasts.html#using-adjusted-p-values",
"href": "chapters/means-and-contrasts.html#using-adjusted-p-values",
"title": "12 Marginal Means & Contrasts",
- "section": "12.6 using adjusted P-values",
- "text": "12.6 using adjusted P-values\nP values, “significance”, and recommendations : https://cran.r-project.org/web/packages/emmeans/vignettes/basics.html#emms\nReference grids and emmeans() results may be plotted via plot() (for parallel confidence intervals) or emmip() (for an interaction-style plot). Be cautious with the terms “significant” and “nonsignificant”, and don’t ever interpret a “nonsignificant” result as saying that there is no effect. Follow good statistical practices such as getting the model right first, and using adjusted P values for appropriately chosen families of comparisons or contrasts.\n\n\n\n\n\n\nCautionary Note about CLD\n\n\n\nIt’s important to note that we cannot conclude that treatment levels with the same letter are the same. We can only conclude that they are not different.\nThere is a separate branch of statistics, “equivalence testing” that is for ascertaining if things are sufficiently similar to conclude they are equivalent.\nSee ?sec-cld_warning for additional warnings about problems with using compact letter display.\n\n\n\n\n\n\n\n\nMore details on emmeans\n\n\n\nIf you want to read more about emmeans, please refer to vignettes on this CRAN page.",
+ "section": "12.8 using adjusted P-values",
+ "text": "12.8 using adjusted P-values\nP values, “significance”, and recommendations : https://cran.r-project.org/web/packages/emmeans/vignettes/basics.html#emms\nReference grids and emmeans() results may be plotted via plot() (for parallel confidence intervals) or emmip() (for an interaction-style plot). Be cautious with the terms “significant” and “nonsignificant”, and don’t ever interpret a “nonsignificant” result as saying that there is no effect. Follow good statistical practices such as getting the model right first, and using adjusted P values for appropriately chosen families of comparisons or contrasts.\n\n\n\n\n\n\nCautionary Note about CLD\n\n\n\nIt’s important to note that we cannot conclude that treatment levels with the same letter are the same. We can only conclude that they are not different.\nThere is a separate branch of statistics, “equivalence testing” that is for ascertaining if things are sufficiently similar to conclude they are equivalent.\nSee ?sec-cld_warning for additional warnings about problems with using compact letter display.\n\n\n\n\n\n\n\n\nMore details on emmeans\n\n\n\nIf you want to read more about emmeans, please refer to vignettes on this CRAN page.",
"crumbs": [
"12 Marginal Means and Contrasts"
]
@@ -870,7 +870,7 @@
"href": "chapters/means-and-contrasts.html#compact-letter-displays",
"title": "12 Marginal Means & Contrasts",
"section": "12.4 Compact letter displays",
- "text": "12.4 Compact letter displays\nCompact letter displays (CLDs) are a popular way to display multiple comparisons when there are more than few group means to compare. However, they are problematic as they are more prone to misinterpretation. The R package multcompView (Graves et al., 2019) provides an implementation of CLDs creating a display where any two means associated with same symbol are not statistically different.\nThe cld() function from the multcomp package is used to implement CLDs in the form of symbols or letters. The emmeans package provides a emmGrid objects for cld() method.\nLet’s start evaluating CLDs for main effects. We will use emmean objects m1 and m2 for this.\n\ncld(m1, alpha=0.05, Letters=letters)\n\n V emmean SE df lower.CL upper.CL .group\n Victory 97.6 7.8 5 77.6 118 a \n Golden.rain 104.5 7.8 5 84.5 125 a \n Marvellous 109.8 7.8 5 89.7 130 a \n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 3 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\n\ncld(m2, alpha=0.05, Letters=letters)\n\n N emmean SE df lower.CL upper.CL .group\n 0.0cwt 79.4 7.17 5 60.9 97.8 a \n 0.2cwt 98.9 7.17 5 80.4 117.3 b \n 0.4cwt 114.2 7.17 5 95.8 132.7 c \n 0.6cwt 123.4 7.17 5 104.9 141.8 c \n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 4 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\nLet’s have a look at the CLDs for the interaction effect:\n\ncld(m3, alpha=0.05, Letters=letters)\n\n V N emmean SE df lower.CL upper.CL .group \n Victory 0.0cwt 71.5 9.11 5 48.1 94.9 a \n Golden.rain 0.0cwt 80.0 9.11 5 56.6 103.4 abcde \n Marvellous 0.0cwt 86.7 9.11 5 63.3 110.1 abc fg \n Victory 0.2cwt 89.7 9.11 5 66.3 113.1 ab d f h \n Golden.rain 0.2cwt 98.5 9.11 5 75.1 121.9 abcdefghi\n Marvellous 0.2cwt 108.5 9.11 5 85.1 131.9 abcdefghi\n Victory 0.4cwt 110.8 9.11 5 87.4 134.2 bcdefghi\n Golden.rain 0.4cwt 114.7 9.11 5 91.3 138.1 fghi\n Marvellous 0.4cwt 117.2 9.11 5 93.8 140.6 de hi\n Victory 0.6cwt 118.5 9.11 5 95.1 141.9 c e g i\n Golden.rain 0.6cwt 124.8 9.11 5 101.4 148.2 fghi\n Marvellous 0.6cwt 126.8 9.11 5 103.4 150.2 hi\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 12 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\nInterpretation of these letters is: Here we have a significant difference in grain yield with varieties “victory”, with N treatments of 0.0cwt, 0.2cwt, 0.4cwt, and 0.6wt. Grain yield for Golden.rain variety was significantly lower with 0.0cwt N treatment compared to the 0.2cwt, 0.4cwt, and 0.6wt treatments.",
+ "text": "12.4 Compact letter displays\nCompact letter displays (CLDs) are a popular way to display multiple comparisons when there are more than few group means to compare. However, they are problematic as they are more prone to misinterpretation. The R package multcompView (Graves et al., 2019) provides an implementation of CLDs creating a display where any two means associated with same symbol are not statistically different.\nThe cld() function from the multcomp package is used to implement CLDs in the form of symbols or letters. The emmeans package provides a emmGrid objects for cld() method.\nLet’s start evaluating CLDs for main effects. We will use emmean objects m1 and m2 for this.\n\ncld(m1, alpha=0.05, Letters=letters)\n\n V emmean SE df lower.CL upper.CL .group\n Victory 97.6 7.8 5 77.6 118 a \n Golden.rain 104.5 7.8 5 84.5 125 a \n Marvellous 109.8 7.8 5 89.7 130 a \n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 3 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\n\ncld(m2, alpha=0.05, Letters=letters)\n\n N emmean SE df lower.CL upper.CL .group\n 0.0cwt 79.4 7.17 5 60.9 97.8 a \n 0.2cwt 98.9 7.17 5 80.4 117.3 b \n 0.4cwt 114.2 7.17 5 95.8 132.7 c \n 0.6cwt 123.4 7.17 5 104.9 141.8 c \n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 4 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\nLet’s have a look at the CLDs for the interaction effect:\n\ncld(m3, alpha=0.05, Letters=letters)\n\n V N emmean SE df lower.CL upper.CL .group \n Victory 0.0cwt 71.5 9.11 5 48.1 94.9 a \n Golden.rain 0.0cwt 80.0 9.11 5 56.6 103.4 abcde \n Marvellous 0.0cwt 86.7 9.11 5 63.3 110.1 abc fg \n Victory 0.2cwt 89.7 9.11 5 66.3 113.1 ab d f h \n Golden.rain 0.2cwt 98.5 9.11 5 75.1 121.9 abcdefghi\n Marvellous 0.2cwt 108.5 9.11 5 85.1 131.9 abcdefghi\n Victory 0.4cwt 110.8 9.11 5 87.4 134.2 bcdefghi\n Golden.rain 0.4cwt 114.7 9.11 5 91.3 138.1 fghi\n Marvellous 0.4cwt 117.2 9.11 5 93.8 140.6 de hi\n Victory 0.6cwt 118.5 9.11 5 95.1 141.9 c e g i\n Golden.rain 0.6cwt 124.8 9.11 5 101.4 148.2 fghi\n Marvellous 0.6cwt 126.8 9.11 5 103.4 150.2 hi\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 12 estimates \nsignificance level used: alpha = 0.05 \nNOTE: If two or more means share the same grouping symbol,\n then we cannot show them to be different.\n But we also did not show them to be the same. \n\n\nInterpretation of these letters is: Here we have a significant difference in grain yield with varieties “victory”, with N treatments of 0.0cwt, 0.2cwt, 0.4cwt, and 0.6wt. Grain yield for Golden.rain variety was significantly lower with 0.0cwt N treatment compared to the 0.2cwt, 0.4cwt, and 0.6wt treatments.\nIn the data set we used for demonstration here, we had equal number of observations in each group. However, this might not be a case every time as it is common to have missing values in the data set. In such cases, readers usually struggle to interpret significant differences among groups. For example, estimated means of two groups are substantially different but they are no statistically different. This normally happens when SE of one group is large due to its small sample size, so it’s hard for it to be statistically different from other groups. In such cases, we can use alternatives to CLDs as shown below.",
"crumbs": [
"12 Marginal Means and Contrasts"
]
@@ -880,7 +880,7 @@
"href": "chapters/means-and-contrasts.html#alternatives-to-cld",
"title": "12 Marginal Means & Contrasts",
"section": "12.5 Alternatives to CLD",
- "text": "12.5 Alternatives to CLD\n\n12.5.1 Interactions using Emmeans\n\n\n12.5.2 Contrasts using Emmeans\n\n(warp.emm <- emmeans(warp.lm, ~ tension | wool))\n\ncontrast(warp.emm, \"poly\")\n\nCompact letter display\n\n#library(multcomp); library(multcompView)\n\n\n#cld(m1, Letters= letters)\n\nThe letters indicating significant differences can be generated using cld() function from the ‘multcomp’ package”. In the output below, groups sharing a letter in the .group are not statistically different from each other.",
+ "text": "12.5 Alternatives to CLD\n\nEquivalence test\n\nLet’s assume based on subject matter considerations, if mean yield of two groups differ by less than 30 can be considered equivalent. Let’s try equivalence test on clds of nitrogen treatment emmeans (m2)\n\ncld(m2, delta = 30, adjust = \"none\")\n\n N emmean SE df lower.CL upper.CL .equiv.set\n 0.0cwt 79.4 7.17 5 60.9 97.8 1 \n 0.2cwt 98.9 7.17 5 80.4 117.3 12 \n 0.4cwt 114.2 7.17 5 95.8 132.7 23 \n 0.6cwt 123.4 7.17 5 104.9 141.8 3 \n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nStatistics are tests of equivalence with a threshold of 30 \nP values are left-tailed \nsignificance level used: alpha = 0.05 \nEstimates sharing the same symbol test as equivalent \n\n\nHere, two treatment groups ‘0.0cwt’ and ‘0.2cwt’, ‘0.4cwt’ and ‘0.6cwt’ can be considered equivalent.\n\nSignificance Sets\n\nAnother alternative is to simply reverse all the boolean flags we used in constructing CLDs for m3 first time.\n\ncld(m2, signif = TRUE)\n\n N emmean SE df lower.CL upper.CL .signif.set\n 0.0cwt 79.4 7.17 5 60.9 97.8 12 \n 0.2cwt 98.9 7.17 5 80.4 117.3 12 \n 0.4cwt 114.2 7.17 5 95.8 132.7 1 \n 0.6cwt 123.4 7.17 5 104.9 141.8 2 \n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \nP value adjustment: tukey method for comparing a family of 4 estimates \nsignificance level used: alpha = 0.05 \nEstimates sharing the same symbol are significantly different",
"crumbs": [
"12 Marginal Means and Contrasts"
]
@@ -900,7 +900,27 @@
"href": "chapters/means-and-contrasts.html#contrasts-using-emmeans",
"title": "12 Marginal Means & Contrasts",
"section": "12.3 Contrasts using emmeans",
- "text": "12.3 Contrasts using emmeans\nFirstly, the pairs() function from emmeans package can be used to evaluate the pairwise comparison among treatment objects. The emmean object (m1, m2) will be passed through pairs() function which will provide a p-value adjustment equivalent to the Tukey test.\n\npairs(m1, adjust = \"tukey\")\n\n contrast estimate SE df t.ratio p.value\n Golden.rain - Marvellous -5.29 7.08 10 -0.748 0.7419\n Golden.rain - Victory 6.88 7.08 10 0.971 0.6104\n Marvellous - Victory 12.17 7.08 10 1.719 0.2458\n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nP value adjustment: tukey method for comparing a family of 3 estimates \n\n\n\npairs(m2)\n\n contrast estimate SE df t.ratio p.value\n 0.0cwt - 0.2cwt -19.50 4.44 45 -4.396 0.0004\n 0.0cwt - 0.4cwt -34.83 4.44 45 -7.853 <.0001\n 0.0cwt - 0.6cwt -44.00 4.44 45 -9.919 <.0001\n 0.2cwt - 0.4cwt -15.33 4.44 45 -3.457 0.0064\n 0.2cwt - 0.6cwt -24.50 4.44 45 -5.523 <.0001\n 0.4cwt - 0.6cwt -9.17 4.44 45 -2.067 0.1797\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nP value adjustment: tukey method for comparing a family of 4 estimates \n\n\nHere if we look at the results from code chunk above, it’s easy to interpret results from pairs() function in case of varietey comparison becuase there were only 3 groups. It’s bit confusing in case of Nitrogen treatments where we had 4 groups. We can further simplify it by using custom contrasts.\n\n12.3.1 Custom contrasts\n\nTreatment\n\nFirstly, let’s run emmean object ‘m1’ for variety compariosn.\n\nm2\n\n N emmean SE df lower.CL upper.CL\n 0.0cwt 79.4 7.17 5 60.9 97.8\n 0.2cwt 98.9 7.17 5 80.4 117.3\n 0.4cwt 114.2 7.17 5 95.8 132.7\n 0.6cwt 123.4 7.17 5 104.9 141.8\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\n\ncoef(pairs(m1))\n\n V c.1 c.2 c.3\nGolden.rain Golden.rain 1 1 0\nMarvellous Marvellous -1 0 1\nVictory Victory 0 -1 -1\n\n\nNow, lets a create a vector for each variety in the same order as presented in output from m1.\n\nA1 = c(1, 0, 0)\nA2 = c(0, 1, 0)\nA3 = c(0, 0, 1)\n\nThese vectors (A1, A2, A3, A4) represent each Nitrogen treatment in an order as presented in m2 emmeans object. A1, A2, and A3, A4 vectors represents 0.0cwt, 0.2cwt, 0.4cwt, and 0.6cwt treatments, respectively.\nLet’s create custom contrasts for comparing ‘0.0cwt’ (A1) treatment to ‘0.2cwt’ (A2), ‘0.4cwt’ (A3), and ‘0.6cwt’ (A4) treatments. This can be evaluated as shown below: Here the output shows the difference in mean yield between these two varieties\n\npairs(m2, adjust = \"tukey\")\n\n contrast estimate SE df t.ratio p.value\n 0.0cwt - 0.2cwt -19.50 4.44 45 -4.396 0.0004\n 0.0cwt - 0.4cwt -34.83 4.44 45 -7.853 <.0001\n 0.0cwt - 0.6cwt -44.00 4.44 45 -9.919 <.0001\n 0.2cwt - 0.4cwt -15.33 4.44 45 -3.457 0.0064\n 0.2cwt - 0.6cwt -24.50 4.44 45 -5.523 <.0001\n 0.4cwt - 0.6cwt -9.17 4.44 45 -2.067 0.1797\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nP value adjustment: tukey method for comparing a family of 4 estimates \n\ncontrast(m2, method = list(A1 - A2) )\n\n contrast estimate SE df t.ratio p.value\n c(1, -1, 0, 0) -19.5 4.44 45 -4.396 0.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\ncontrast(m2, method = list(A1 - A3) )\n\n contrast estimate SE df t.ratio p.value\n c(1, 0, -1, 0) -34.8 4.44 45 -7.853 <.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\ncontrast(m2, method = list(A1 - A4) )\n\n contrast estimate SE df t.ratio p.value\n c(1, 0, 0, -1) -44 4.44 45 -9.919 <.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\n\n\n\nUsing custom contrasts is strongly recommended instead of pairs() when you are comparing multiple treatment groups (>5).\n\n\n\n\n\n\npairs()\n\n\n\nRemember!! The pairs() function can be used to calculate pairwise comparison when treatment groups are less than equal to 3.",
+ "text": "12.3 Contrasts using emmeans\nFirstly, the pairs() function from emmeans package can be used to evaluate the pairwise comparison among treatment objects. The emmean object (m1, m2) will be passed through pairs() function which will provide a p-value adjustment equivalent to the Tukey test.\n\npairs(m1, adjust = \"tukey\")\n\n contrast estimate SE df t.ratio p.value\n Golden.rain - Marvellous -5.29 7.08 10 -0.748 0.7419\n Golden.rain - Victory 6.88 7.08 10 0.971 0.6104\n Marvellous - Victory 12.17 7.08 10 1.719 0.2458\n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nP value adjustment: tukey method for comparing a family of 3 estimates \n\n\n\npairs(m2)\n\n contrast estimate SE df t.ratio p.value\n 0.0cwt - 0.2cwt -19.50 4.44 45 -4.396 0.0004\n 0.0cwt - 0.4cwt -34.83 4.44 45 -7.853 <.0001\n 0.0cwt - 0.6cwt -44.00 4.44 45 -9.919 <.0001\n 0.2cwt - 0.4cwt -15.33 4.44 45 -3.457 0.0064\n 0.2cwt - 0.6cwt -24.50 4.44 45 -5.523 <.0001\n 0.4cwt - 0.6cwt -9.17 4.44 45 -2.067 0.1797\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nP value adjustment: tukey method for comparing a family of 4 estimates \n\n\nHere if we look at the results from code chunk above, it’s easy to interpret results from pairs() function in case of varietey comparison becuase there were only 3 groups. It’s bit confusing in case of Nitrogen treatments where we had 4 groups. We can further simplify it by using custom contrasts.\n\n\n\n\n\n\npairs()\n\n\n\nRemember!! The pairs() function can be used to calculate pairwise comparison when treatment groups are less than equal to 3.\n\n\n\n12.3.1 Custom contrasts\nFirstly, let’s run emmean object ‘m2’ for nitrogen treatment comparison.\n\nm2\n\n N emmean SE df lower.CL upper.CL\n 0.0cwt 79.4 7.17 5 60.9 97.8\n 0.2cwt 98.9 7.17 5 80.4 117.3\n 0.4cwt 114.2 7.17 5 95.8 132.7\n 0.6cwt 123.4 7.17 5 104.9 141.8\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\nNow, lets a create a vector for each nitrogen treatment in the same order as presented in output from m2.\n\nA1 = c(1, 0, 0, 0)\nA2 = c(0, 1, 0, 0)\nA3 = c(0, 0, 1, 0)\nA4 = c(0, 0, 0, 1)\n\nThese vectors (A1, A2, A3, A4) represent each Nitrogen treatment in an order as presented in m2 emmeans object. A1, A2, and A3, A4 vectors represents 0.0cwt, 0.2cwt, 0.4cwt, and 0.6cwt treatments, respectively.\nLet’s create custom contrasts for comparing ‘0.0cwt’ (A1) treatment to ‘0.2cwt’ (A2), ‘0.4cwt’ (A3), and ‘0.6cwt’ (A4) treatments. This can be evaluated as shown below: Here the output shows the difference in mean yield between these two varieties\n\ncontrast(m2, method = list(A1 - A2) )\n\n contrast estimate SE df t.ratio p.value\n c(1, -1, 0, 0) -19.5 4.44 45 -4.396 0.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\ncontrast(m2, method = list(A1 - A3) )\n\n contrast estimate SE df t.ratio p.value\n c(1, 0, -1, 0) -34.8 4.44 45 -7.853 <.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\ncontrast(m2, method = list(A1 - A4) )\n\n contrast estimate SE df t.ratio p.value\n c(1, 0, 0, -1) -44 4.44 45 -9.919 <.0001\n\nResults are averaged over the levels of: V \nDegrees-of-freedom method: containment \n\n\n\n\nUsing custom contrasts is strongly recommended instead of pairs() when you are comparing multiple treatment groups (>5).",
+ "crumbs": [
+ "12 Marginal Means and Contrasts"
+ ]
+ },
+ {
+ "objectID": "chapters/means-and-contrasts.html#creating-plots-with-emmeans",
+ "href": "chapters/means-and-contrasts.html#creating-plots-with-emmeans",
+ "title": "12 Marginal Means & Contrasts",
+ "section": "12.7 creating plots with emmeans",
+ "text": "12.7 creating plots with emmeans\n\n12.7.1 Interactions using Emmeans\n\n\n12.7.2 Contrasts using Emmeans\n\n(warp.emm <- emmeans(warp.lm, ~ tension | wool))\n\ncontrast(warp.emm, \"poly\")\n\nCompact letter display\n\n#library(multcomp); library(multcompView)\n\n\n#cld(m1, Letters= letters)\n\nThe letters indicating significant differences can be generated using cld() function from the ‘multcomp’ package”. In the output below, groups sharing a letter in the .group are not statistically different from each other.",
+ "crumbs": [
+ "12 Marginal Means and Contrasts"
+ ]
+ },
+ {
+ "objectID": "chapters/means-and-contrasts.html#export-emmeans-to-excel-sheet",
+ "href": "chapters/means-and-contrasts.html#export-emmeans-to-excel-sheet",
+ "title": "12 Marginal Means & Contrasts",
+ "section": "12.6 Export emmeans to excel sheet",
+ "text": "12.6 Export emmeans to excel sheet\nThe emmean objects can be directly exported\n\nresult_n <- as.data.frame(summary(m1))\n\n\nlibrary(writexl)\n\nWarning: package 'writexl' was built under R version 4.4.2\n\nwrite_xlsx(result_n)",
"crumbs": [
"12 Marginal Means and Contrasts"
]