Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions assignment5.Rmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
name: Fei Wang
date: 11/25/2020
title: "Principle Component Aanalysis"
output: html_document
---
Expand All @@ -16,7 +18,8 @@ The data you will be using comes from the Assistments online intelligent tutorin

## Start by uploading the data
```{r}
D1 <-
library(readr)
D1 <- read.csv(file="Assistments-confidence.csv")

```

Expand All @@ -38,7 +41,7 @@ ggcorr(D1[,-1], method = c("everything", "pearson")) #ggcorr() doesn't have an e
## Create a new data frame with the mean_correct variable removed, we want to keep that variable intact. The other variables will be included in our PCA.

```{r}
D2 <-
D2 <- subset(D1, select = -mean_correct)

```

Expand Down Expand Up @@ -67,21 +70,24 @@ plot(pca, type = "lines")
```

## Decide which components you would drop and remove them from your data set.
```{r}
#I will drop PC2, PC3, PC4, PC5, PC6, and PC7 because they are less meaningful compared to PC1.
```


## Part II

```{r}
#Now, create a data frame of the transformed data from your pca.

D3 <-
D3 <- D2[2:6]

#Attach the variable "mean_correct" from your original data frame to D3.


D3 <- c(D3, D1$mean_correct)

#Now re-run your correlation plots between the transformed data and mean_correct. If you had dropped some components would you have lost important infomation about mean_correct?


ggcorr(D3, method = c("everything", "pearson"))

```
## Now print out the loadings for the components you generated:
Expand All @@ -95,6 +101,8 @@ loadings <- abs(pca$rotation) #abs() will make all eigenvectors positive

#Now examine your components and try to come up with substantive descriptions of what some might represent?



#You can generate a biplot to help you, though these can be a bit confusing. They plot the transformed data by the first two components. Therefore, the axes represent the direction of maximum variance accounted for. Then mapped onto this point cloud are the original directions of the variables, depicted as red arrows. It is supposed to provide a visualization of which variables "go together". Variables that possibly represent the same underlying construct point in the same direction.

biplot(pca)
Expand All @@ -105,6 +113,23 @@ biplot(pca)
Also in this repository is a data set collected from TC students (tc-program-combos.csv) that shows how many students thought that a TC program was related to andother TC program. Students were shown three program names at a time and were asked which two of the three were most similar. Use PCA to look for components that represent related programs. Explain why you think there are relationships between these programs.

```{r}
T1 <- read.csv(file="tc-program-combos.csv")
T2<-T1[,-1]

ggcorr(T1, method = c("everything", "pearson"))

pca<-prcomp(T2,scale.=T)
summary(pca)
plot(pca, type = "lines")

pca$sdev
pca$sdev^2
summary(pca)
pca$rotation
loadings1 <- abs(pca$rotation)
biplot(pca)

#The graphs indicate that there are relationships between programs. The programs that are related generally would share similar funndational courses or have the same words used in the title of the program. The first few PCA indicate that there are relationship between the two main groups of programs. The first group is more human psychology related and the second group is more teaching/education related.

```

Expand Down
Loading