diff --git a/chapters/means-and-contrasts.qmd b/chapters/means-and-contrasts.qmd index 1b608ca..c63eb44 100644 --- a/chapters/means-and-contrasts.qmd +++ b/chapters/means-and-contrasts.qmd @@ -26,7 +26,7 @@ Let's start the analysis by loading the required libraries for fitting linear mi ```{r, warning=FALSE, message=FALSE} library(nlme); library(performance); library(emmeans) library(dplyr); library(broom.mixed); library(multcompView) -library(multcomp) +library(multcomp); library(ggplot2) ``` ### Import data Let's import oats data from the MASS package. @@ -151,7 +151,8 @@ cld(m2, alpha=0.05, Letters=letters) Let's have a look at the CLDs for the interaction effect: ```{r} -cld(m3, alpha=0.05, Letters=letters) +cld3 <- cld(m3, alpha=0.05, Letters=letters) +cld3 ``` 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. @@ -180,21 +181,42 @@ cld(m2, signif = TRUE) 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) ``` +## Graphical display of emmeans + +The results of emmeans() object can be plotted in two different ways. +Firstly, we can use base `plot()` function in R. ```{r} +plot(m1) +plot(m4) +``` +Or we can use 'ggplot2' library. We can plot cld3 object in ggplot, with Variety on x-axis and estimated means of yield on y-axis. Different N treatments are presented in groups of different colors. +```{r} +ggplot(cld3) + + aes(x = V, y = emmean, color = N) + + geom_point(position = position_dodge(width = 0.9)) + + geom_errorbar(mapping = aes(ymin = lower.CL, ymax = upper.CL), + position = position_dodge(width = 1), + width = 0.1) + + geom_text(mapping = aes(label = .group, y = upper.CL * 1.05), + position = position_dodge(width = 0.8), + show.legend = F)+ + theme_bw()+ + theme(axis.text= element_text(color = "black", + size =12)) ``` +Recall: groups that do not differ significantly from each other share the same letter. + diff --git a/docs/search.json b/docs/search.json index bbc3f5f..3cfaf88 100644 --- a/docs/search.json +++ b/docs/search.json @@ -840,7 +840,7 @@ "href": "chapters/means-and-contrasts.html#analysis-examples", "title": "12  Marginal Means & Contrasts", "section": "12.2 Analysis Examples", - "text": "12.2 Analysis Examples\n\nlibrary(nlme); library(performance); library(emmeans)\nlibrary(dplyr); library(broom.mixed); library(multcompView)\nlibrary(multcomp)\n\n\n12.2.1 Import data\nLet’s import oats data from the MASS package.\n\n\nTo read more about data and model fitting explanation please refer to Chapter 6.\n\ndata1 <- MASS::oats\n\n\n\n12.2.2 Model fitting\n\nmodel1 <- lme(Y ~ V + N + V:N ,\n random = ~1|B/V,\n data = data1, \n na.action = na.exclude)\ntidy(model1)\n\nWarning in tidy.lme(model1): ran_pars not yet implemented for multiple levels\nof nesting\n\n\n# A tibble: 12 × 7\n effect term estimate std.error df statistic p.value\n <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n 1 fixed (Intercept) 80 9.11 45 8.78 2.56e-11\n 2 fixed VMarvellous 6.67 9.72 10 0.686 5.08e- 1\n 3 fixed VVictory -8.50 9.72 10 -0.875 4.02e- 1\n 4 fixed N0.2cwt 18.5 7.68 45 2.41 2.02e- 2\n 5 fixed N0.4cwt 34.7 7.68 45 4.51 4.58e- 5\n 6 fixed N0.6cwt 44.8 7.68 45 5.84 5.48e- 7\n 7 fixed VMarvellous:N0.2cwt 3.33 10.9 45 0.307 7.60e- 1\n 8 fixed VVictory:N0.2cwt -0.333 10.9 45 -0.0307 9.76e- 1\n 9 fixed VMarvellous:N0.4cwt -4.17 10.9 45 -0.383 7.03e- 1\n10 fixed VVictory:N0.4cwt 4.67 10.9 45 0.430 6.70e- 1\n11 fixed VMarvellous:N0.6cwt -4.67 10.9 45 -0.430 6.70e- 1\n12 fixed VVictory:N0.6cwt 2.17 10.9 45 0.199 8.43e- 1\n\n\n\n\n12.2.3 Check Model Assumptions\n\ncheck_model(model1, check = c('normality', 'linearity'))\n\n\n\n\n\n\n\n\n\n\n12.2.4 Model Inference\n\nanova(model1, type = \"marginal\")\n\n numDF denDF F-value p-value\n(Intercept) 1 45 77.16729 <.0001\nV 2 10 1.22454 0.3344\nN 3 45 13.02273 <.0001\nV:N 6 45 0.30282 0.9322\n\n\n\n\n12.2.5 Estimated Marginal Means\nNow that we have a good model, let’s use the emmeans() function to obtain EMMs.\nNow 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.\n\n12.2.5.1 Main effects\n\nm1 <- emmeans(model1, ~V, level = 0.95)\n\nNOTE: Results may be misleading due to involvement in interactions\n\nm1\n\n V emmean SE df lower.CL upper.CL\n Golden.rain 104.5 7.8 5 84.5 125\n Marvellous 109.8 7.8 5 89.7 130\n Victory 97.6 7.8 5 77.6 118\n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\n\nm2 <- emmeans(model1, ~N)\n\nNOTE: Results may be misleading due to involvement in interactions\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\nMake sure to read and interpret EMMs carefully. Here, when we calculated EMMs for main effects for V and N, these were averaged over the levels of other factor in experiment. For example, estimated means for each variety were averaged over it’s N treatments, respectively.\n\n\n12.2.5.2 Interaction effects\nNow let’s evaluate the interaction effect EMMs for V and N. These can be calculated either using V*N or V|N.\n\nm3 <- emmeans(model1, ~V*N)\nm3\n\n V N emmean SE df lower.CL upper.CL\n Golden.rain 0.0cwt 80.0 9.11 5 56.6 103.4\n Marvellous 0.0cwt 86.7 9.11 5 63.3 110.1\n Victory 0.0cwt 71.5 9.11 5 48.1 94.9\n Golden.rain 0.2cwt 98.5 9.11 5 75.1 121.9\n Marvellous 0.2cwt 108.5 9.11 5 85.1 131.9\n Victory 0.2cwt 89.7 9.11 5 66.3 113.1\n Golden.rain 0.4cwt 114.7 9.11 5 91.3 138.1\n Marvellous 0.4cwt 117.2 9.11 5 93.8 140.6\n Victory 0.4cwt 110.8 9.11 5 87.4 134.2\n Golden.rain 0.6cwt 124.8 9.11 5 101.4 148.2\n Marvellous 0.6cwt 126.8 9.11 5 103.4 150.2\n Victory 0.6cwt 118.5 9.11 5 95.1 141.9\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\n\nm4 <- emmeans(model1, ~V|N)\nm4\n\nN = 0.0cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 80.0 9.11 5 56.6 103.4\n Marvellous 86.7 9.11 5 63.3 110.1\n Victory 71.5 9.11 5 48.1 94.9\n\nN = 0.2cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 98.5 9.11 5 75.1 121.9\n Marvellous 108.5 9.11 5 85.1 131.9\n Victory 89.7 9.11 5 66.3 113.1\n\nN = 0.4cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 114.7 9.11 5 91.3 138.1\n Marvellous 117.2 9.11 5 93.8 140.6\n Victory 110.8 9.11 5 87.4 134.2\n\nN = 0.6cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 124.8 9.11 5 101.4 148.2\n Marvellous 126.8 9.11 5 103.4 150.2\n Victory 118.5 9.11 5 95.1 141.9\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95", + "text": "12.2 Analysis Examples\n\nlibrary(nlme); library(performance); library(emmeans)\nlibrary(dplyr); library(broom.mixed); library(multcompView)\nlibrary(multcomp); library(ggplot2)\n\n\n12.2.1 Import data\nLet’s import oats data from the MASS package.\n\n\nTo read more about data and model fitting explanation please refer to Chapter 6.\n\ndata1 <- MASS::oats\n\n\n\n12.2.2 Model fitting\n\nmodel1 <- lme(Y ~ V + N + V:N ,\n random = ~1|B/V,\n data = data1, \n na.action = na.exclude)\ntidy(model1)\n\nWarning in tidy.lme(model1): ran_pars not yet implemented for multiple levels\nof nesting\n\n\n# A tibble: 12 × 7\n effect term estimate std.error df statistic p.value\n <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n 1 fixed (Intercept) 80 9.11 45 8.78 2.56e-11\n 2 fixed VMarvellous 6.67 9.72 10 0.686 5.08e- 1\n 3 fixed VVictory -8.50 9.72 10 -0.875 4.02e- 1\n 4 fixed N0.2cwt 18.5 7.68 45 2.41 2.02e- 2\n 5 fixed N0.4cwt 34.7 7.68 45 4.51 4.58e- 5\n 6 fixed N0.6cwt 44.8 7.68 45 5.84 5.48e- 7\n 7 fixed VMarvellous:N0.2cwt 3.33 10.9 45 0.307 7.60e- 1\n 8 fixed VVictory:N0.2cwt -0.333 10.9 45 -0.0307 9.76e- 1\n 9 fixed VMarvellous:N0.4cwt -4.17 10.9 45 -0.383 7.03e- 1\n10 fixed VVictory:N0.4cwt 4.67 10.9 45 0.430 6.70e- 1\n11 fixed VMarvellous:N0.6cwt -4.67 10.9 45 -0.430 6.70e- 1\n12 fixed VVictory:N0.6cwt 2.17 10.9 45 0.199 8.43e- 1\n\n\n\n\n12.2.3 Check Model Assumptions\n\ncheck_model(model1, check = c('normality', 'linearity'))\n\n\n\n\n\n\n\n\n\n\n12.2.4 Model Inference\n\nanova(model1, type = \"marginal\")\n\n numDF denDF F-value p-value\n(Intercept) 1 45 77.16729 <.0001\nV 2 10 1.22454 0.3344\nN 3 45 13.02273 <.0001\nV:N 6 45 0.30282 0.9322\n\n\n\n\n12.2.5 Estimated Marginal Means\nNow that we have a good model, let’s use the emmeans() function to obtain EMMs.\nNow 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.\n\n12.2.5.1 Main effects\n\nm1 <- emmeans(model1, ~V, level = 0.95)\n\nNOTE: Results may be misleading due to involvement in interactions\n\nm1\n\n V emmean SE df lower.CL upper.CL\n Golden.rain 104.5 7.8 5 84.5 125\n Marvellous 109.8 7.8 5 89.7 130\n Victory 97.6 7.8 5 77.6 118\n\nResults are averaged over the levels of: N \nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\n\nm2 <- emmeans(model1, ~N)\n\nNOTE: Results may be misleading due to involvement in interactions\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\nMake sure to read and interpret EMMs carefully. Here, when we calculated EMMs for main effects for V and N, these were averaged over the levels of other factor in experiment. For example, estimated means for each variety were averaged over it’s N treatments, respectively.\n\n\n12.2.5.2 Interaction effects\nNow let’s evaluate the interaction effect EMMs for V and N. These can be calculated either using V*N or V|N.\n\nm3 <- emmeans(model1, ~V*N)\nm3\n\n V N emmean SE df lower.CL upper.CL\n Golden.rain 0.0cwt 80.0 9.11 5 56.6 103.4\n Marvellous 0.0cwt 86.7 9.11 5 63.3 110.1\n Victory 0.0cwt 71.5 9.11 5 48.1 94.9\n Golden.rain 0.2cwt 98.5 9.11 5 75.1 121.9\n Marvellous 0.2cwt 108.5 9.11 5 85.1 131.9\n Victory 0.2cwt 89.7 9.11 5 66.3 113.1\n Golden.rain 0.4cwt 114.7 9.11 5 91.3 138.1\n Marvellous 0.4cwt 117.2 9.11 5 93.8 140.6\n Victory 0.4cwt 110.8 9.11 5 87.4 134.2\n Golden.rain 0.6cwt 124.8 9.11 5 101.4 148.2\n Marvellous 0.6cwt 126.8 9.11 5 103.4 150.2\n Victory 0.6cwt 118.5 9.11 5 95.1 141.9\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95 \n\n\n\nm4 <- emmeans(model1, ~V|N)\nm4\n\nN = 0.0cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 80.0 9.11 5 56.6 103.4\n Marvellous 86.7 9.11 5 63.3 110.1\n Victory 71.5 9.11 5 48.1 94.9\n\nN = 0.2cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 98.5 9.11 5 75.1 121.9\n Marvellous 108.5 9.11 5 85.1 131.9\n Victory 89.7 9.11 5 66.3 113.1\n\nN = 0.4cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 114.7 9.11 5 91.3 138.1\n Marvellous 117.2 9.11 5 93.8 140.6\n Victory 110.8 9.11 5 87.4 134.2\n\nN = 0.6cwt:\n V emmean SE df lower.CL upper.CL\n Golden.rain 124.8 9.11 5 101.4 148.2\n Marvellous 126.8 9.11 5 103.4 150.2\n Victory 118.5 9.11 5 95.1 141.9\n\nDegrees-of-freedom method: containment \nConfidence level used: 0.95", "crumbs": [ "12  Marginal Means and Contrasts" ] @@ -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.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.", + "section": "12.9 using adjusted P-values", + "text": "12.9 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.\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.", + "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\ncld3 <- cld(m3, alpha=0.05, Letters=letters)\ncld3\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" ] @@ -909,8 +909,8 @@ "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.", + "section": "12.8 creating plots with emmeans", + "text": "12.8 creating plots with emmeans\n\n12.8.1 Interactions using Emmeans\n\n\n12.8.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" ] @@ -924,5 +924,15 @@ "crumbs": [ "12  Marginal Means and Contrasts" ] + }, + { + "objectID": "chapters/means-and-contrasts.html#graphical-display-of-emmeans", + "href": "chapters/means-and-contrasts.html#graphical-display-of-emmeans", + "title": "12  Marginal Means & Contrasts", + "section": "12.7 Graphical display of emmeans", + "text": "12.7 Graphical display of emmeans\nThe results of emmeans() object can be plotted in two different ways.\nFirstly, we can use base plot() function in R.\n\nplot(m1)\n\n\n\n\n\n\n\nplot(m4)\n\n\n\n\n\n\n\n\nOr we can use ‘ggplot2’ library.\n\nggplot(cld3) +\n aes(x = V, y = emmean, color = N) +\n geom_point(position = position_dodge(width = 0.9)) +\n geom_errorbar(mapping = aes(ymin = lower.CL, ymax = upper.CL), \n position = position_dodge(width = 0.9),\n width = 0.1) +\n geom_text(mapping = aes(label = .group, y = upper.CL * 1.05), \n position = position_dodge(width = 0.9), \n show.legend = F)", + "crumbs": [ + "12  Marginal Means and Contrasts" + ] } ] \ No newline at end of file