Question

Apart from graphical estimation of linearity (gaze-at-scatterplot method), which is utilized before applying some technique from GLM family, there are several ways to do this estimation arithmetically (i.e. without graphs).

Right now, I'll focus on Fisher's eta-squared - correlation ratio: arithmetically, it's equal to squared Pearson's r (coef. of determination: r2) if relationship between two variables is linear. Hence, you can compare values of eta and r and make an assessment about type of relation (linear or not). It provides an information about percent of variance in the dependent variable explained (linearly or not) by the independent variable. Therefore, you can apply it when linearity assumptions are not met.

Simply stated: is there a routine for eta/eta-squared in R?

Was it helpful?

Solution

I'm still quite stunned, I must admit... there's no easy and straightforward way for calculating η or η2 in R... So I wrote a function according to Wikipedia page. Here goes:

eta <- function(x, squared = FALSE, ...) {
    stopifnot(is.list(x))
    ## unlist
    y <- unlist(x)
    ## group mean
    mg <- rapply(x, mean, ...)
    ## group size
    ng <- rapply(x, length, ...)
    ## total mean
    mtot <- mean(y, ...)
    ## SSb
    ssb <- sum(ng * (mg - mtot) ^ 2)
    ## SSt
    sst <- sum((y - mtot) ^ 2)
    # get eta-squared
    if (squared) {
      res <- ssb/sst
    # get eta
    } else {
      res <- sqrt(ssb/sst)
    }
    return(res)
}

So this yields another question, which I'm about to post shortly... what do you use to check linearity? However, I can't calculate p-values, so if anyone knows how to do it... please, let me know!

OTHER TIPS

After reading this Question, and trying the function in the answer, I just found this the library "sjstats". There is an Eta-Squared-function included. Maybe it is helpful for future seekers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top