y <- attitude #from the datasets package
x <- rowSums(y) #find the sum of the seven attitudes
alpha.scale(x,y)
#[1] 0.8431428
#compare with standardized alpha:
st.alpha <- cluster.cor(rep(1,7),cor(attitude),digits=4)
st.alpha
#compare with score.items
si <- score.items(rep(1,7), attitude,digits=3)
si$alpha
## The function is currently defined as
function (x,y) #find coefficient alpha given a scale and
#a data.frame of the items in the scale
{
n=length(y) #number of variables
Vi=sum(diag(var(y,na.rm=TRUE))) #sum of item variance
Vt=var(x,na.rm=TRUE) #total test variance
((Vt-Vi)/Vt)*(n/(n-1))} #alpha
Run the code above in your browser using DataLab