[R] cronbachs alpha - score.items(psych) vs reliability(Rcmdr)

John Fox jfox at mcmaster.ca
Wed Feb 4 01:47:01 CET 2009


Dear Andreas,

I don't know whether there's another comparable function, but reliability()
from the Rcmdr package is very simple; here it is printed out (as you could
have done simply by typing its name -- I added the assignment arrow):

reliability <-
function (S) 
{
    reliab <- function(S, R) {
        k <- dim(S)[1]
        ones <- rep(1, k)
        v <- as.vector(ones %*% S %*% ones)
        alpha <- (k/(k - 1)) * (1 - (1/v) * sum(diag(S)))
        rbar <- mean(R[lower.tri(R)])
        std.alpha <- k * rbar/(1 + (k - 1) * rbar)
        c(alpha = alpha, std.alpha = std.alpha)
    }
    result <- list()
    if ((!is.numeric(S)) || !is.matrix(S) || (nrow(S) != ncol(S)) || 
        any(abs(S - t(S)) > max(abs(S)) * 1e-10) || nrow(S) < 
        2) 
        stop(gettextRcmdr("argument must be a square, symmetric, numeric
covariance matrix"))
    k <- dim(S)[1]
    s <- sqrt(diag(S))
    R <- S/(s %o% s)
    rel <- reliab(S, R)
    result$alpha <- rel[1]
    result$st.alpha <- rel[2]
    if (k < 3) {
        warning(gettextRcmdr("there are fewer than 3 items in the scale"))
        return(invisible(NULL))
    }
    rel <- matrix(0, k, 3)
    for (i in 1:k) {
        rel[i, c(1, 2)] <- reliab(S[-i, -i], R[-i, -i])
        a <- rep(0, k)
        b <- rep(1, k)
        a[i] <- 1
        b[i] <- 0
        cov <- a %*% S %*% b
        var <- b %*% S %*% b
        rel[i, 3] <- cov/(sqrt(var * S[i, i]))
    }
    rownames(rel) <- rownames(S)
    colnames(rel) <- c("Alpha", "Std.Alpha", "r(item, total)")
    result$rel.matrix <- rel
    class(result) <- "reliability"
    result
}

As an alternative to loading the package, you could just put the function
definition in a file -- editing out the calls to gettextRcmdr, which are for
translation of the error messages -- and source() the file when you want to
use it. You'll probably also want the print method (obtained by
Rcmdr:::print.reliability):

print.reliability <-
function (x, digits = 4, ...) 
{
    cat(paste("Alpha reliability = ", round(x$alpha, digits), 
        "\n"))
    cat(paste("Standardized alpha = ", round(x$st.alpha, digits), 
        "\n"))
    cat("\nReliability deleting each item in turn:\n")
    print(round(x$rel.matrix, digits))
    invisible(x)
}

I hope this helps,
 John

------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
> Behalf Of achristoffersen
> Sent: February-03-09 6:47 PM
> To: r-help at r-project.org
> Subject: [R] cronbachs alpha - score.items(psych) vs reliability(Rcmdr)
> 
> 
> Dear all,
> 
> I like the way the Rcmdr package computes reliability. E.g
> 
> reliability(cov(d[,c("q1", "q2", "q3", "q4", "q5", "q6")],
> use="complete.obs"))
> 
> will not only give me the alpha score, but also for each variable,
> alpha.score if deleted. However - when writing scripts it's very tiresome
to
> load the whole Rcmdr GUI just for this purpose. So I'm looking for an
> another package that delivers the same feature.
> 
> the score.items function in the psych package i find is too complicated
(it
> requires a keys vector) and it doesn't report the "alpha if deleted"
score.
> 
> What have I missed when googling for an alternative?
> 
> Thx in advance
> 
> Andreas
> --
> View this message in context: http://www.nabble.com/cronbachs-alpha---
> score.items%28psych%29-vs-reliability%28Rcmdr%29-tp21821595p21821595.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list