Skip to content
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
speciessexn()
Adeliefemale73
Adeliemale73
Chinstrapfemale34
Chinstrapmale34
Gentoofemale58
Gentoomale61
\n
# Fit data\nflipper_fit <- stats::aov(flipper_length_mm ~ species, data = df)\n# Run anova\nflipper_anova <- car::Anova(flipper_fit)\n\n\n# Extract estimated marginal means\nflipper_emmeans <- emmeans::emmeans(flipper_fit, specs = pairwise ~ species)\n\n# convert estimated marginal mean contrasts to dataframe\nflipper_emmeans_contrasts <- data.frame(flipper_emmeans$contrasts)\n\nknitr::kable(flipper_emmeans_contrasts)
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
contrastestimateSEdft.ratiop.value
Adelie - Chinstrap-5.720790.9796493330-5.839630
Adelie - Gentoo-27.132550.8240767330-32.924790
Chinstrap - Gentoo-21.411761.0143492330-21.108870
\n
effectsize::t_to_d(t = flipper_emmeans_contrasts[flipper_emmeans_contrasts$contrast == \"Adelie - Chinstrap\", \"t.ratio\"],\n                   df_error = flipper_emmeans_contrasts[flipper_emmeans_contrasts$contrast == \"Adelie - Chinstrap\", \"df\"]\n                   )\n#> d     |         95% CI\n#> ----------------------\n#> -0.64 | [-0.86, -0.42]
\n

Created on 2023-11-05 with reprex v2.0.2

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hey, this will give approximate d effect sizes (see discussion here #212). But if you are using {emmeans} you can use emmeans::eff_size() to get d effect sizes directly:

\n
library(palmerpenguins) # dataset\nlibrary(car) # anova functions\nlibrary(effectsize) # effect sizes\nlibrary(dplyr)\n\n# assigns data to a dataframe we call \"df\"\ndf <- palmerpenguins::penguins\n\n# drop rows with missing values\ndf <- df[complete.cases(df)==TRUE, ]\n\nflipper_fit <- stats::aov(flipper_length_mm ~ species, data = df)\n\n# Extract estimated marginal means\nflipper_emmeans <- emmeans::emmeans(flipper_fit, specs = ~ species)\n\nemmeans::eff_size(\n  flipper_emmeans,\n  method = \"pairwise\",\n  sigma = sigma(flipper_fit),\n  edf = df.residual(flipper_fit)\n)\n#>  contrast             effect.size    SE  df lower.CL upper.CL\n#>  (Adelie - Chinstrap)      -0.857 0.151 330    -1.15   -0.561\n#>  (Adelie - Gentoo)         -4.066 0.201 330    -4.46   -3.671\n#>  (Chinstrap - Gentoo)      -3.209 0.197 330    -3.60   -2.822\n#> \n#> sigma used for effect sizes: 6.673 \n#> Confidence level used: 0.95
\n

(This suggestion also appears in t_to_d() documentation:

\n
\n

The resulting d effect size is an approximation to Cohen's d, and assumes two equal group sizes. When possible, it is advised to directly estimate Cohen's d, with cohens_d(), emmeans::eff_size(), or similar functions.

\n
\n

I suggest reading emmeans::eff_size() docs about how to select sigma in more complex models.

\n

Hope this helps!

","upvoteCount":2,"url":"https://github.com/easystats/effectsize/discussions/617#discussioncomment-7484856"}}}
Discussion options

You must be logged in to vote

Hey, this will give approximate d effect sizes (see discussion here #212). But if you are using {emmeans} you can use emmeans::eff_size() to get d effect sizes directly:

library(palmerpenguins) # dataset
library(car) # anova functions
library(effectsize) # effect sizes
library(dplyr)

# assigns data to a dataframe we call "df"
df <- palmerpenguins::penguins

# drop rows with missing values
df <- df[complete.cases(df)==TRUE, ]

flipper_fit <- stats::aov(flipper_length_mm ~ species, data = df)

# Extract estimated marginal means
flipper_emmeans <- emmeans::emmeans(flipper_fit, specs = ~ species)

emmeans::eff_size(
  flipper_emmeans,
  method = "pairwise",
  sigma = sigma(flipper_fit),
  edf =

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DallasNovakowski
Comment options

Answer selected by mattansb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #616 on November 06, 2023 08:32.