1

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.

user438383
  • 5,716
  • 8
  • 28
  • 43
Miranda
  • 11
  • 1

1 Answers1

0

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)
Francisco Maria Calisto
  • 2,841
  • 4
  • 22
  • 54
  • 1
    Thanks so much for your help, Francisco! Thanks for taking time out of your busy day to help me with my R codes :) much appreciated! – Miranda Mar 21 '23 at 19:35
  • No worries! Any question, please be free to comment here. I also have some open-source code in the R language available across my repositories on GitHub. Just follow my profile link and you will find my GitHub profile. If this is a working solution for you, just vote as you want and mark it as an answer. – Francisco Maria Calisto Mar 21 '23 at 19:41
  • 1
    Sorry, a follow up question. I ran the codes, and there is an error message: > pairwise_cohens_d <- apply(two.way.contrast$comparisons, 1, get_cohens_d, group_means_se) Error in apply(two.way.contrast$comparisons, 1, get_cohens_d, group_means_se) : dim(X) must have a positive length. Could you please help me take a look? Thanks again!! – Miranda Mar 21 '23 at 19:42
  • It seems that the error might be caused by an empty or missing value in the `two.way.contrast$comparisons` part of the code. Try to check the content of that `two.way.contrast$comparisons` part and look at the `group_mean_se` also. – Francisco Maria Calisto Mar 21 '23 at 21:08
  • Try to do `print(two.way.contrast$comparisons)` and `print(group_mean_se)`. – Francisco Maria Calisto Mar 21 '23 at 21:09