[R] Item Analysis and Cronbach's Alpha (Code Attached)
Magill, Brett
MagillB at usa.redcross.org
Mon Mar 26 19:30:33 CEST 2001
A short function I wrote for the purpose of evaluating scales made up of a
number of questionnaire items. It provides Cronbach's Alpha, both
unstandardized and based on standardized items. It also provides item
statistics which include item-total correlations (corrected) and
item-removed alpha. Thought some of you might find it useful. I would also
appreciate any programming tips or suggestions for improving the function as
I am still relatively new to R and statistical programming in general.
Cheers!
Alpha<-
function(x){
xmat<-as.matrix(na.omit(x))
xmat.z<-scale(xmat)
N<-dim(xmat)[2]
Correlation.Matrix<-cor(xmat)
Item.Tot.Cor<-rep(NA,N)
for (a in 1:N) Item.Tot.Cor[a]<-(cor(apply(xmat[,- a],1,sum),xmat[,a]))
Item.Rem.Alpha<-rep(NA,N)
for (b in 1:N) Item.Rem.Alpha[b]<- ((N-1)/(N-2)) * (1
-((sum(diag(var(xmat[,-b])))) / (sum(var(xmat[,-b])))))
Item.Mean<-apply(xmat,2,mean)
Item.SD<-apply(xmat,2,sd)
Item.Var<-apply(xmat,2,var)
N.Cases<-rep(dim(xmat)[1],N)
ITEM.STATISTICS<-cbind(Item.Mean, Item.Var,
Item.SD,Item.Tot.Cor,Item.Rem.Alpha,N.Cases)
Cronbachs.Alpha<- (N/(N-1)) * (1 -((sum(diag(var(xmat )))) /
(sum(var(xmat )))))
Standardized.Alpha<- (N/(N-1)) * (1 -((sum(diag(var(xmat.z)))) /
(sum(var(xmat.z)))))
Total.Mean<-mean(apply(xmat,1,sum))
Total.Var<-var(apply(xmat,1,sum))
Total.SD<-sd(apply(xmat,1,sum))
N.Items<-N
TOTAL.STATISTICS<-cbind(Cronbachs.Alpha,Standardized.Alpha,Total.Mean,Total.
Var,Total.SD, N.Items)
row.names(TOTAL.STATISTICS)<-"TOTAL"
print("Cronbach's Alpha and Item Analysis")
print("----------------------------------")
print("Correlation.Matrix")
print(Correlation.Matrix,digits=4)
print("---------------------------------------------------------")
print(ITEM.STATISTICS,digits=4)
print("------------------------------------------------------------------")
print(TOTAL.STATISTICS,digits=4)
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list