Appropriate to use t_to_d() on estimated marginal mean contrasts from ANOVA? #617
-
Question and context I'm running some factorial anova analyses, and would like to use t_to_d() with emmeans to retrieve cohen's d effect sizes for my pairwise contrasts. I'm just wondering whether this is statistically sound? I see the degrees of freedom are the same all across the contrasts, and am not sure whether these large df values might lead to some inflated and inaccurate estimates of cohen's d. Reprex: library(palmerpenguins) # dataset
#> Warning: package 'palmerpenguins' was built under R version 4.1.3
library(car) # anova functions
#> Warning: package 'car' was built under R version 4.1.3
#> Loading required package: carData
#> Warning: package 'carData' was built under R version 4.1.3
library(effectsize) # effect sizes
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.1.3
#>
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:car':
#>
#> recode
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# assigns data to a dataframe we call "df"
df <- palmerpenguins::penguins
# drop rows with missing values
df <- df[complete.cases(df)==TRUE, ]
df %>%
group_by(species, sex) %>% # Group by the specified variables
dplyr::summarise(n()) %>%
knitr::kable()
#> `summarise()` has grouped output by 'species'. You can override using the
#> `.groups` argument.
# Fit data
flipper_fit <- stats::aov(flipper_length_mm ~ species, data = df)
# Run anova
flipper_anova <- car::Anova(flipper_fit)
# Extract estimated marginal means
flipper_emmeans <- emmeans::emmeans(flipper_fit, specs = pairwise ~ species)
# convert estimated marginal mean contrasts to dataframe
flipper_emmeans_contrasts <- data.frame(flipper_emmeans$contrasts)
knitr::kable(flipper_emmeans_contrasts)
effectsize::t_to_d(t = flipper_emmeans_contrasts[flipper_emmeans_contrasts$contrast == "Adelie - Chinstrap", "t.ratio"],
df_error = flipper_emmeans_contrasts[flipper_emmeans_contrasts$contrast == "Adelie - Chinstrap", "df"]
)
#> d | 95% CI
#> ----------------------
#> -0.64 | [-0.86, -0.42] Created on 2023-11-05 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, this will give approximate d effect sizes (see discussion here #212). But if you are using 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 = df.residual(flipper_fit)
)
#> contrast effect.size SE df lower.CL upper.CL
#> (Adelie - Chinstrap) -0.857 0.151 330 -1.15 -0.561
#> (Adelie - Gentoo) -4.066 0.201 330 -4.46 -3.671
#> (Chinstrap - Gentoo) -3.209 0.197 330 -3.60 -2.822
#>
#> sigma used for effect sizes: 6.673
#> Confidence level used: 0.95 (This suggestion also appears in
I suggest reading Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey, this will give approximate d effect sizes (see discussion here #212). But if you are using
{emmeans}
you can useemmeans::eff_size()
to get d effect sizes directly: