# Omega squared for measure of effect in R?

The statistics book I am reading recommends omega squared to measure the effects of my experiments. I have already proven using a split plot design (mix of within-subjects and between-subjects design) that my within-subjects factors are statistically significant with p<0.001 and F=17.

Now I'm looking to see how big is the difference... is there an implementation of omega squared somewhere for R (or python? I know... one can dream ;) Searching on the internet for R-related stuff is a pain the *, I don't know how I manage to find stuff with C.

thanks!

• I'm not aware of such a function, but perhaps someone could look at the formulas in Olejnik and Algina (2003) cps.nova.edu/marker/olejnik2003.pdf and write a function – Jeromy Anglim Sep 22 '10 at 5:34
• @Jeromy Nice reference! This one is worth looking too: Recommended effect size statistics for repeated measures designs (BRM 2005 37(3)), j.mp/cT9uEQ – chl Sep 22 '10 at 6:56
• @chl Thanks. Apparently, ezANOVA() in the ez package in R reports generalised eta squared. – Jeromy Anglim Sep 22 '10 at 7:49

A function to compute omega squared is straightforward to write. This function takes the object returned by the aov test, and calculates and returns and omega squared:

omega_sq <- function(aovm){
sum_stats <- summary(aovm)[[1]]
SSm <- sum_stats[["Sum Sq"]][1]
SSr <- sum_stats[["Sum Sq"]][2]
DFm <- sum_stats[["Df"]][1]
MSr <- sum_stats[["Mean Sq"]][2]
W2 <- (SSm-DFm*MSr)/(SSm+SSr+MSr)
return(W2)
}


edit: updated function for n-way aov models:

omega_sq <- function(aov_in, neg2zero=T){
aovtab <- summary(aov_in)[[1]]
n_terms <- length(aovtab[["Sum Sq"]]) - 1
output <- rep(-1, n_terms)
SSr <- aovtab[["Sum Sq"]][n_terms + 1]
MSr <- aovtab[["Mean Sq"]][n_terms + 1]
SSt <- sum(aovtab[["Sum Sq"]])
for(i in 1:n_terms){
SSm <- aovtab[["Sum Sq"]][i]
DFm <- aovtab[["Df"]][i]
output[i] <- (SSm-DFm*MSr)/(SSt+MSr)
if(neg2zero & output[i] < 0){output[i] <- 0}
}
names(output) <- rownames(aovtab)[1:n_terms]

return(output)
}


I had to recently report an $\omega^2$.

partialOmegas <- function(mod){
aovMod <- mod
if(!any(class(aovMod) %in% 'aov')) aovMod <- aov(mod)
sumAov     <- summary(aovMod)[[1]]
residRow   <- nrow(sumAov)
dfError    <- sumAov[residRow,1]
msError    <- sumAov[residRow,3]
nTotal     <- nrow(model.frame(aovMod))
dfEffects  <- sumAov[1:{residRow-1},1]
ssEffects  <- sumAov[1:{residRow-1},2]
msEffects  <- sumAov[1:{residRow-1},3]
partOmegas <- abs((dfEffects*(msEffects-msError)) /
(ssEffects + (nTotal -dfEffects)*msError))
names(partOmegas) <- rownames(sumAov)[1:{residRow-1}]
partOmegas
}


It is a messy function that can easily be cleaned up. It computes the partial $\omega^2$, and should probably only be used on between-subjects factorial designs.

I'd suggest that generalized eta square is considered (ref, ref) a more appropriate measure of effect size. It is included in the ANOVA output in the ez package for R.

• Actually, eta-squared is a highly positively biased statistic. It is, therefore, much worse in this situation than omega-squared, though because of its simplicity, it is more popular. – user95417 Nov 17 '15 at 19:04
• I agree with user above. Here's a link to back it up. daniellakens.blogspot.nl/2015/06/… – CoderGuy123 Mar 15 '18 at 4:57

I found an omega squared function in somebody's .Rprofile that they made available online:

http://www.estudiosfonicos.cchs.csic.es/metodolo/1/.Rprofile

Daniel "strengejacke" Lüdecke's package sjstats can not do omega-squared, partial-omega-squared etc for ANOVA models. Check it out.

Here is a vignette that demonstrates that:

https://cran.r-project.org/web/packages/sjstats/vignettes/anova-statistics.html

install.packages("sjstats")
library(sjstats)

mod1 <- aov(y~x, data= d.frame)

anova_stats(mod1)