Miranda
Miranda

Reputation: 11

request effect size for Each pair of the ANOVA pairwise comparisons?

I'm wondering if anyone knows the R code to obtain the effect size for EACH PAIR of the pairwise comparisons? My codes:

two.way.contrast <- emmeans(two.way.esm, specs= pairwise~emotionF*typeF, adjust=NULL) %>%
  summary(level=0.90)
summary(two.way.contrast)

I'm wondering how can I get partial eqta sqaure for each pair of the pairwise comparisons? Cohen's d is fine to. I could do my own conversion.

I could only get effect size for the ANOVA model, but couldn't figure out the effect size code for each pair of the pairwise comparisons.

Upvotes: 1

Views: 262

Answers (1)

Francisco Maria Calisto
Francisco Maria Calisto

Reputation: 3240

As you demonstrated, you can use that emmeans package to compute the pairwise comparison. Then, you can calculate Cohen's d based on the means and SDs of each group.

For instance, you can do like:

two.way.contrast <- emmeans(two.way.esm, specs= pairwise ~ emotionF * typeF, adjust=NULL) %>%
  summary(level=0.90)

group_means_se <- summary(emmeans(two.way.esm, specs = ~ emotionF * typeF), type = "response")$results[, c("emmean", "SE")]

get_cohens_d <- function(pair, group_means_se) {
  group1 <- pair[1]
  group2 <- pair[2]
  mean1 <- group_means_se[group1, "emmean"]
  mean2 <- group_means_se[group2, "emmean"]
  se1 <- group_means_se[group1, "SE"]
  se2 <- group_means_se[group2, "SE"]
  pooled_sd <- sqrt(((two.way.esm$df.residual - 1) * se1^2 + (two.way.esm$df.residual - 1) * se2^2) / (2 * (two.way.esm$df.residual - 1)))
  cohen_d <- (mean1 - mean2) / pooled_sd
  return(cohen_d)
}

pairwise_cohens_d <- apply(two.way.contrast$comparisons, 1, get_cohens_d, group_means_se)

results <- cbind(two.way.contrast, cohen_d = unlist(pairwise_cohens_d))

print(results)

Upvotes: 0

Related Questions