achristoffersen
2009-Feb-03 23:47 UTC
[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.
John Fox
2009-Feb-04 00:47 UTC
[R] cronbachs alpha - score.items(psych) vs reliability(Rcmdr)
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 tiresometo> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Christopher W. Ryan
2009-Feb-04 13:50 UTC
[R] cronbachs alpha - score.items(psych) vs reliability(Rcmdr)
The item.total command in the "multilevel" package will give you what you want. --Chris Christopher W. Ryan, MD SUNY Upstate Medical University Clinical Campus at Binghamton 40 Arch Street, Johnson City, NY 13790 cryanatbinghamtondotedu PGP public keys available at http://home.stny.rr.com/ryancw/ "If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery] achristoffersen wrote:> 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
Greg Snow
2009-Feb-04 19:09 UTC
[R] cronbachs alpha - score.items(psych) vs reliability(Rcmdr)
You can run a function from a package by doing something like:> Rcmdr::reliability(cov(DavisThin))This will load the package in the background, but not run the gui and other things. So you can use the function(s) that you want without running everything like when you do library(Rcmdr). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of achristoffersen > Sent: Tuesday, February 03, 2009 4: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.