Skip to content

Commit 341173e

Browse files
author
Petersen
committed
20241002 - update
1 parent 5d3ccff commit 341173e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

15-Factor-Analysis-PCA.Rmd

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,32 @@ library("tinytex")
2222
library("knitr")
2323
library("rmarkdown")
2424
```
25+
26+
### Load Data {#loadData-factorAnalysis}
27+
28+
### Prepare Data {#prepareData-factorAnalysis}
29+
30+
#### Add Missing Data {#addMissingData-factorAnalysis}
31+
32+
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.
33+
For reproducibility, I set the seed below.
34+
Using the same seed will yield the same answer every time.
35+
There is nothing special about this particular seed.
36+
37+
`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.
38+
39+
```{r}
40+
set.seed(52242)
41+
42+
varNames <- names(HolzingerSwineford1939)
43+
dimensionsDf <- dim(HolzingerSwineford1939)
44+
unlistedDf <- unlist(HolzingerSwineford1939)
45+
unlistedDf[sample(
46+
1:length(unlistedDf),
47+
size = .15 * length(unlistedDf))] <- NA
48+
HolzingerSwineford1939 <- as.data.frame(matrix(
49+
unlistedDf,
50+
ncol = dimensionsDf[2]))
51+
names(HolzingerSwineford1939) <- varNames
52+
vars <- c("x1","x2","x3","x4","x5","x6","x7","x8","x9")
53+
```

0 commit comments

Comments
 (0)