R ANOVA Effect Size – How to Measure Omega Squared

anovaeffect-sizersplit-plot

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!

Best Answer

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)
}
Related Question