Learn R Programming

sjPlot (version 1.7)

sjt.pca: Show principal component analysis as HTML table

Description

Performes a principle component analysis on a data frame or matrix and displays the factor solution as HTML table, or saves them as file. In case a data frame is used as parameter, the Cronbach's Alpha value for each factor scale will be calculated, i.e. all variables with the highest loading for a factor are taken for the reliability test. The result is an alpha value for each factor dimension.

Usage

sjt.pca(data, numberOfFactors = NULL, factorLoadingTolerance = 0.1,
  file = NULL, varlabels = NULL,
  title = "Principal Component Analysis (with varimax rotation)",
  breakLabelsAt = 40, digits = 2, showCronbachsAlpha = TRUE,
  showMSA = FALSE, showVariance = FALSE, alternateRowColors = FALSE,
  stringPov = "Proportion of Variance",
  stringCpov = "Cumulative Proportion", encoding = NULL, CSS = NULL,
  useViewer = TRUE, no.output = FALSE, remove.spaces = TRUE)

Arguments

Value

Invisibly returns a structure with
  • the web page style sheet (page.style),
  • the web page content (page.content),
  • the complete html-output (output.complete),
  • the html-table with inline-css for use with knitr (knitr),
  • thefactor.index, i.e. the column index of each variable with the highest factor loading for each factor and
  • theremoved.items, i.e. which variables have been removed because they were outside of thefactorLoadingTolerance's range.
for further use.

See Also

Examples

Run this code
# 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")

# show table
sjt.pca(likert_4)

# -------------------------------
# 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)]

sjt.pca(df)

# -------------------------------
# auto-detection of labels
# -------------------------------
efc <- set_var_labels(efc, varlabs)
sjt.pca(efc[, c(start : end)])

Run the code above in your browser using DataLab