From 4441772ac95c2e77ae8ac82a971562b21dd89319 Mon Sep 17 00:00:00 2001 From: Xiyun Zhang Date: Mon, 26 Oct 2020 23:11:18 +0800 Subject: [PATCH] Submit Hackthon3.Rmd and .html documents --- Hackathon3.Rmd | 53 +++++++++ Hackathon3.html | 288 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 341 insertions(+) create mode 100644 Hackathon3.Rmd create mode 100644 Hackathon3.html diff --git a/Hackathon3.Rmd b/Hackathon3.Rmd new file mode 100644 index 0000000..f9c8ba4 --- /dev/null +++ b/Hackathon3.Rmd @@ -0,0 +1,53 @@ +--- +title: "Hackathon3" +author: "Xiyun Zhang" +date: "10/26/2020" +output: html_document +--- +#PArt I +```{r} +library(devtools) +library(tidyr) +library(dplyr) + +DF1 <- read.csv("engagement-data.csv") +DF2 <- read.csv("student-level.csv") +DF1.1 <- DF1 %>% group_by(id, week) %>% summarise(average= mean(measure)) +DF1.2 <- spread(DF1.1,week,average) +colnames(DF1.2) <- c("id","week1","week2","week3","week4","week5","week6") +DF1.3 <- DF1.2 %>% ungroup() %>% select(2:7) +DF1.3$engage_average <- rowMeans(DF1.3) +DF1.2$engage_average <- DF1.3$engage_average + +DF3 <- merge(DF1.2,DF2,by="id") +DF3$assignment_average <- rowMeans(subset(DF3, select= 9:13)) +DF3$quiz_average <- rowMeans(subset(DF3, select= 14:18)) + +``` +#Part II +```{r} +DF3.1 <- select(DF3,2:19) +DF3.2 <- select(DF3, 8,19,24,25) +pairs(DF3.2) + +``` +#Part III +```{r} +library(cluster) +fit <- kmeans(DF3.2, 2) +clusplot(DF3.2, fit$cluster, color=TRUE, shade=TRUE,labels=2, lines=0) + +fit2 <- kmeans(DF3.2, 3) +clusplot(DF3.2, fit2$cluster, color=TRUE, shade=TRUE,labels=2, lines=0) + +fit3 <- kmeans(DF3.2, 4) +clusplot(DF3.2, fit3$cluster, color=TRUE, shade=TRUE,labels=2, lines=0) + +fit4 <- kmeans(DF3.2, 5) +clusplot(DF3.2, fit4$cluster, color=TRUE, shade=TRUE,labels=2, lines=0) + +fit5 <- kmeans(DF3.2, 6) +clusplot(DF3.2, fit5$cluster, color=TRUE, shade=TRUE,labels=2, lines=0) + +``` + diff --git a/Hackathon3.html b/Hackathon3.html new file mode 100644 index 0000000..2f4cb18 --- /dev/null +++ b/Hackathon3.html @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + +Hackathon3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+

PArt I

+
library(devtools)
+
## Warning: package 'devtools' was built under R version 4.0.3
+
## Loading required package: usethis
+
## Warning: package 'usethis' was built under R version 4.0.3
+
library(tidyr)
+library(dplyr)
+
## 
+## Attaching package: 'dplyr'
+
## The following objects are masked from 'package:stats':
+## 
+##     filter, lag
+
## The following objects are masked from 'package:base':
+## 
+##     intersect, setdiff, setequal, union
+
DF1 <- read.csv("engagement-data.csv")
+DF2 <- read.csv("student-level.csv")
+DF1.1 <- DF1 %>% group_by(id, week) %>% summarise(average= mean(measure))
+
## `summarise()` regrouping output by 'id' (override with `.groups` argument)
+
DF1.2 <- spread(DF1.1,week,average)
+colnames(DF1.2) <- c("id","week1","week2","week3","week4","week5","week6")
+DF1.3 <- DF1.2 %>% ungroup() %>% select(2:7)
+DF1.3$engage_average <- rowMeans(DF1.3)
+DF1.2$engage_average <- DF1.3$engage_average
+
+DF3 <- merge(DF1.2,DF2,by="id")
+DF3$assignment_average <- rowMeans(subset(DF3, select= 9:13))
+DF3$quiz_average <- rowMeans(subset(DF3, select= 14:18))
+
+
+

Part II

+
DF3.1 <- select(DF3,2:19)
+DF3.2 <- select(DF3, 8,19,24,25)
+pairs(DF3.2)
+

#Part III

+
library(cluster)
+fit <- kmeans(DF3.2, 2)
+clusplot(DF3.2, fit$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
+

+
fit2 <- kmeans(DF3.2, 3)
+clusplot(DF3.2, fit2$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
+

+
fit3 <- kmeans(DF3.2, 4)
+clusplot(DF3.2, fit3$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
+

+
fit4 <- kmeans(DF3.2, 5)
+clusplot(DF3.2, fit4$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
+

+
fit5 <- kmeans(DF3.2, 6)
+clusplot(DF3.2, fit5$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
+

+
+ + + + +
+ + + + + + + + + + + + + + +