-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcode-workout.Rmd
More file actions
40 lines (24 loc) · 1001 Bytes
/
code-workout.Rmd
File metadata and controls
40 lines (24 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
title: "Principle Component Aanalysis"
output: html_document
---
## Iin this repository is a data set and codebook from Rod Martin, Patricia Puhlik-Doris, Gwen Larsen, Jeanette Gray, Kelly Weir at the University of Western Ontario about people's sense of humor.
```{r}
library(dplyr)
library(tidyr)
#Upload data and separate questions from composites
H1 <- read.csv("humor_data.csv", header = TRUE)
H2 <- select(H1, 1:32)
#Run pca on the questions
pca <- prcomp(H2, scale = TRUE)
summary(pca)
#Sum of Squared Distances/Eigenvalues
plot(pca$sdev)
# Loadings
pca$rotation
#Look at biplot, see how the questions resolve into four clear directions
biplot(pca)
#Look at the loadings, and compare them to the question text in the humor_codebook.txt, do they align with the composites that the authors generated (affiliative, selfenhancing, aggressive, self-defeating)?
pca$rotation
#They match closely, this is because the survey was designed to resolve into these four components.
```