# NOT RUN {
library(sjlabelled)
# Data from the EUROFAMCARE sample dataset
data(efc)
# retrieve variable and value labels
varlabs <- get_label(efc)
# recveive first item of COPE-index scale
start <- which(colnames(efc) == "c82cop1")
# recveive last item of COPE-index scale
end <- which(colnames(efc) == "c90cop9")
# create data frame with COPE-index scale
x <- efc[, c(start:end)]
colnames(x) <- varlabs[c(start:end)]
# reliability tests
reliab_test(x)
# split-half-reliability
split_half(x)
# cronbach's alpha
cronb(x)
# mean inter-item-correlation
mic(x)
# item difficulty
difficulty(x)
# }
# NOT RUN {
library(sjPlot)
sjt.df(reliab_test(x), describe = FALSE, show.cmmn.row = TRUE,
string.cmmn = sprintf("Cronbach's α=%.2f", cronb(x)))
# Compute PCA on Cope-Index, and perform a
# reliability check on each extracted factor.
factors <- sjt.pca(x)$factor.index
findex <- sort(unique(factors))
library(sjPlot)
for (i in seq_len(length(findex))) {
rel.df <- subset(x, select = which(factors == findex[i]))
if (ncol(rel.df) >= 3) {
sjt.df(reliab_test(rel.df), describe = FALSE, show.cmmn.row = TRUE,
use.viewer = FALSE, title = "Item-Total-Statistic",
string.cmmn = sprintf("Scale's overall Cronbach's α=%.2f",
cronb(rel.df)))
}
}
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab