# randomly create data frame with 7 items, each consisting of 4 categories
likert_4 <- data.frame(sample(1:4, 500, replace = TRUE, prob = c(0.2,0.3,0.1,0.4)),
sample(1:4, 500, replace = TRUE, prob = c(0.5,0.25,0.15,0.1)),
sample(1:4, 500, replace = TRUE, prob = c(0.4,0.15,0.25,0.2)),
sample(1:4, 500, replace = TRUE, prob = c(0.25,0.1,0.4,0.25)),
sample(1:4, 500, replace = TRUE, prob = c(0.1,0.4,0.4,0.1)),
sample(1:4, 500, replace = TRUE),
sample(1:4, 500, replace = TRUE, prob = c(0.35,0.25,0.15,0.25)))
# Create variable labels
colnames(likert_4) <- c("V1", "V2", "V3", "V4", "V5", "V6", "V7")
# plot results from PCA as square-tiled "heatmap"
sjp.pca(likert_4)
# manually compute PCA
pca <- prcomp(na.omit(likert_4), retx = TRUE, center = TRUE, scale. = TRUE)
# plot results from PCA as circles, including Eigenvalue-diagnostic.
# note that this plot does not compute the Cronbach's Alpha
sjp.pca(pca, plotEigenvalues = TRUE, type = "circle")
# -------------------------------
# Data from the EUROFAMCARE sample dataset
# -------------------------------
data(efc)
# retrieve variable and value labels
varlabs <- get_var_labels(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
df <- as.data.frame(efc[,c(start:end)])
colnames(df) <- varlabs[c(start:end)]
sjp.pca(df)
# -------------------------------
# auto-detection of labels
# -------------------------------
efc <- set_var_labels(efc, varlabs)
sjp.pca(efc[, c(start:end)])
Run the code above in your browser using DataLab