Eta/Eta-squared routines in R

只谈情不闲聊 提交于 2019-12-11 21:12:23

问题


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?


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/3002638/eta-eta-squared-routines-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!