Skip to content

Commit

Permalink
formatting change
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidhuharp97 committed Dec 2, 2024
1 parent 8917c16 commit de17e6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
13 changes: 2 additions & 11 deletions chapters/means-and-contrasts.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Interpretation of these letters is: Here we have a significant difference in gra


## Alternatives to CLD
```{r, eval=FALSE}
```{r, eval=FALSE, echo = FALSE}
One-way estimated marginal means and plot
library(multcomp)
Expand Down Expand Up @@ -237,10 +237,6 @@ ggplot(CLD,

### Interactions using Emmeans

```{r}
```

```{r, eval=FALSE, echo=FALSE}
Interaction plot of estimated marginal means
Expand Down Expand Up @@ -373,12 +369,7 @@ The letters indicating significant differences can be generated using cld() func
P values, “significance”, and recommendations : https://cran.r-project.org/web/packages/emmeans/vignettes/basics.html#emms


Reference 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.



Reference 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.


::: {.callout-caution}
Expand Down
4 changes: 2 additions & 2 deletions docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@
"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\nSummary of main points EMMs are derived from a model. A different model for the same data may lead to different EMMs. EMMs are based on a reference grid consisting of all combinations of factor levels, with each covariate set to its average (by default). For purposes of defining the reference grid, dimensions of a multivariate response are treated as levels of a factor. EMMs are then predictions on this reference grid, or marginal averages thereof (equally weighted by default). Reference grids may be modified using at or other arguments for ref_grid() Reference 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.",
"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.",
"crumbs": [
"<span class='chapter-number'>12</span>  <span class='chapter-title'>Marginal Means and Contrasts</span>"
]
Expand All @@ -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\nOne-way estimated marginal means and plot\n\nlibrary(multcomp)\nlibrary(emmeans)\n\nmarginal = emmeans(model, ~ Location)\n\nCLD = cld(marginal,\n alpha=0.05,\n Letters=letters,\n adjust=\"tukey\")\n\nCLD\n\n\nLocation emmean SE df lower.CL upper.CL .group\n Olympia 8.333333 0.6718548 16 6.449596 10.21707 a \n Northampton 11.833333 0.6718548 16 9.949596 13.71707 b \n Ventura 13.333333 0.6718548 16 11.449596 15.21707 b \n Burlington 21.833333 0.6718548 16 19.949596 23.71707 c \n\n\n\n### Order the levels for printing\n\nCLD$Location = factor(CLD$Location,\n levels=c(\"Olympia\", \"Ventura\", \"Northampton\", \"Burlington\"))\n\n### Remove spaces in .group \n\nCLD$.group=gsub(\" \", \"\", CLD$.group)\n\n\n### Plot\n\nlibrary(ggplot2)\n\nggplot(CLD,\n aes(x = Location,\n y = emmean,\n label = .group)) +\n\n geom_point(shape = 15,\n size = 4) +\n\n geom_errorbar(aes(ymin = lower.CL,\n ymax = upper.CL),\n width = 0.2,\n size = 0.7) +\n\n theme_bw() +\n theme(axis.title = element_text(face = \"bold\"),\n axis.text = element_text(face = \"bold\"),\n plot.caption = element_text(hjust = 0)) +\n\n ylab(\"Estimated marginal mean\\nmidichlorian count\") +\n ggtitle (\"Midichlorian counts\",\n\n subtitle = \"In four U.S. cities\") +\n\n labs(caption = paste0(\"\\nMidichlorian counts for four locations. \",\n \"Boxes indicate the EM mean. \\n\",\n \"Error bars indicate the 95% \",\n \"confidence interval of the EM mean. \\n\",\n \"Means sharing a letter are not \",\n \"significantly different (Tukey-adjusted \\n\",\n \"comparisons).\"),\n hjust=0.5) +\n\n geom_text(nudge_x = c(0, 0, 0, 0),\n nudge_y = c(4, 4, 4, 4),\n color = \"black\")\n\n\n12.5.1 Interactions using Emmeans\n\nInteraction plot of estimated marginal means\n\nlibrary(multcomp)\nlibrary(emmeans)\n\nmarginal = emmeans(model,\n ~ Tribe:Location)\n\nCLD = cld(marginal,\n alpha=0.05,\n Letters=letters,\n adjust=\"tukey\")\n\nCLD\n\n\nTribe Location emmean SE df lower.CL upper.CL .group\n Sith Olympia 4.333333 0.9501462 16 1.354477 7.31219 a \n Jedi Northampton 8.666667 0.9501462 16 5.687810 11.64552 ab \n Sith Ventura 10.666667 0.9501462 16 7.687810 13.64552 bc \n Jedi Olympia 12.333333 0.9501462 16 9.354477 15.31219 bcd\n Sith Northampton 15.000000 0.9501462 16 12.021143 17.97886 cd\n Jedi Ventura 16.000000 0.9501462 16 13.021143 18.97886 d\n Jedi Burlington 20.666667 0.9501462 16 17.687810 23.64552 e\n Sith Burlington 23.000000 0.9501462 16 20.021143 25.97886 e\n\n\n\n### Order the levels for printing\n\nCLD$Location = factor(CLD$Location,\n levels=c(\"Olympia\", \"Ventura\", \"Northampton\", \"Burlington\"))\n\nCLD$Tribe = factor(CLD$Tribe,\n levels=c(\"Jedi\", \"Sith\"))\n\n### Remove spaces in .group \n\nCLD$.group=gsub(\" \", \"\", CLD$.group)\n\n\nCLD\n\n\n### Plot\n\nlibrary(ggplot2)\n\npd = position_dodge(0.4) ### How much to jitter the points on the plot\n\nggplot(CLD,\n aes(x = Location,\n y = emmean,\n color = Tribe,\n label = .group)) +\n\n geom_point(shape = 15,\n size = 4,\n position = pd) +\n\n geom_errorbar(aes(ymin = lower.CL,\n ymax = upper.CL),\n width = 0.2,\n size = 0.7,\n position = pd) +\n\n theme_bw() +\n theme(axis.title = element_text(face = \"bold\"),\n axis.text = element_text(face = \"bold\"),\n plot.caption = element_text(hjust = 0)) +\n\n ylab(\"Estimated marginal mean\\nmidichlorian count\") +\n ggtitle (\"Midichlorian counts for Jedi and Sith\",\n subtitle = \"In four U.S. cities\") +\n \n labs(caption = paste0(\"\\nMidichlorian counts for two tribes across \",\n \"four locations. Boxes indicate \\n\",\n \"the EM mean. \",\n \"Error bars indicate the 95% confidence \",\n \"interval \",\n \"of the EM \\n\",\n \"mean. Means sharing a letter are \",\n \"not significantly different \\n\",\n \"(Tukey-adjusted comparisons).\"),\n hjust=0.5) +\n \n geom_text(nudge_x = c(0.1, -0.1, 0.1, -0.1, 0.1, -0.1, -0.1, 0.1),\n nudge_y = c(4.5, 4.5, 4.5, 4.5, 4.5 , 4.5, 4.5, 4.5),\n color = \"black\") +\n \n scale_color_manual(values = c(\"blue\", \"red\"))\n\n\n\n12.5.2 Contrasts using Emmeans\n\n(warp.emm &lt;- 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\n12.5.1 Interactions using Emmeans\n\n\n12.5.2 Contrasts using Emmeans\n\n(warp.emm &lt;- 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": [
"<span class='chapter-number'>12</span>  <span class='chapter-title'>Marginal Means and Contrasts</span>"
]
Expand Down

0 comments on commit de17e6d

Please sign in to comment.