diff --git a/assignment5.Rmd b/assignment5.Rmd index 288bcb3..5222cbd 100644 --- a/assignment5.Rmd +++ b/assignment5.Rmd @@ -1,6 +1,8 @@ --- title: "Principle Component Aanalysis" -output: html_document +output: + html_document: default + pdf_document: default --- ## Data The data you will be using comes from the Assistments online intelligent tutoring system (https://www.assistments.org/). It describes students working through online math problems. Each student has the following data associated with them: @@ -16,7 +18,7 @@ The data you will be using comes from the Assistments online intelligent tutorin ## Start by uploading the data ```{r} -D1 <- +D1 <- read.csv("Assistments-confidence.csv", header = TRUE) ``` @@ -26,7 +28,11 @@ D1 <- #You can install the corrplot package to plot some pretty correlation matrices (sometimes called correlograms) library(ggplot2) +library(tidyr) library(GGally) +library(tidyverse) +library(dplyr) + ggpairs(D1, 2:8, progress = FALSE) #ggpairs() draws a correlation plot between all the columns you identify by number (second option, you don't need the first column as it is the student ID) and progress = FALSE stops a progress bar appearing as it renders your plot @@ -38,7 +44,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 <- D1[,1] ``` @@ -67,21 +73,22 @@ plot(pca, type = "lines") ``` ## Decide which components you would drop and remove them from your data set. - +##I want to remove 1.4 ## Part II ```{r} #Now, create a data frame of the transformed data from your pca. -D3 <- +D3 <- data.frame(pca$x) +D4 <- data.frame(D3, D1[-1.4]) #Attach the variable "mean_correct" from your original data frame to D3. - +D3$mean_correct <- 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? - +##I'm running the code but for some reason, the 1.4 component is still there ``` ## Now print out the loadings for the components you generated: @@ -105,6 +112,14 @@ 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} +D4 <- read.csv("tc-program-combos.csv") +D5 <- D4[,1] +#principal component +pca <- prcomp(D5) +#the variance formula is the standard deviation squared +pca$sdev^2 +plot(pca, type = lines) + ```