From 341173ec97192f5237af88c0f919bc833adcda97 Mon Sep 17 00:00:00 2001 From: Petersen Date: Wed, 2 Oct 2024 11:47:39 -0500 Subject: [PATCH] 20241002 - update --- 15-Factor-Analysis-PCA.Rmd | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/15-Factor-Analysis-PCA.Rmd b/15-Factor-Analysis-PCA.Rmd index c91e5064..41c9db9e 100644 --- a/15-Factor-Analysis-PCA.Rmd +++ b/15-Factor-Analysis-PCA.Rmd @@ -22,3 +22,32 @@ library("tinytex") library("knitr") library("rmarkdown") ``` + +### Load Data {#loadData-factorAnalysis} + +### Prepare Data {#prepareData-factorAnalysis} + +#### Add Missing Data {#addMissingData-factorAnalysis} + +Adding missing data to dataframes helps make examples more realistic to real-life data and helps you get in the habit of programming to account for missing data. +For reproducibility, I set the seed below. +Using the same seed will yield the same answer every time. +There is nothing special about this particular seed. + +`HolzingerSwineford1939` is a data set from the `lavaan` package [@R-lavaan] that contains mental ability test scores (`x1`–`x9`) for seventh- and eighth-grade children. + +```{r} +set.seed(52242) + +varNames <- names(HolzingerSwineford1939) +dimensionsDf <- dim(HolzingerSwineford1939) +unlistedDf <- unlist(HolzingerSwineford1939) +unlistedDf[sample( + 1:length(unlistedDf), + size = .15 * length(unlistedDf))] <- NA +HolzingerSwineford1939 <- as.data.frame(matrix( + unlistedDf, + ncol = dimensionsDf[2])) +names(HolzingerSwineford1939) <- varNames +vars <- c("x1","x2","x3","x4","x5","x6","x7","x8","x9") +```