From caa519012f1011500adf7c83e9678a7ca6223e13 Mon Sep 17 00:00:00 2001 From: Muyao Chen <70938621+Mia714@users.noreply.github.com> Date: Wed, 21 Oct 2020 23:58:44 -0400 Subject: [PATCH 1/2] assignment 3 --- Assignment 3.Rmd | 97 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/Assignment 3.Rmd b/Assignment 3.Rmd index 649407e..61c4113 100644 --- a/Assignment 3.Rmd +++ b/Assignment 3.Rmd @@ -96,28 +96,121 @@ plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$gender) plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$gender, edge.width=EDGE$count) -```` +``` ## Part II In Part II your task is to [look up](http://igraph.org/r/) in the igraph documentation and modify the graph above so that: * Ensure that sizing allows for an unobstructed view of the network features (For example, the arrow size is smaller) + + +```{r} +plot(g,layout=layout.fruchterman.reingold, + vertex.color=VERTEX$gender, + edge.width=EDGE$count, + edge.arrow.size = 0.5, + vertex.size=5) +``` * The vertices are colored according to major +```{r} +plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$major,edge.width=EDGE$count,edge.arrow.size = 0.5) +``` * The vertices are sized according to the number of comments they have recieved - +```{r} +#create a new data frame +EDGE<- EDGE%>% group_by(EDGE$to) %>% mutate(received = sum(count)) +plot(g,layout=layout.fruchterman.reingold, + vertex.color=VERTEX$major, + edge.width=EDGE$count, + edge.arrow.size = 0.5, + vertex.size=EDGE$received*3, + edge.color="gray", + weight.edge.lengths=0.2) +``` ## Part III Now practice with data from our class. This data is real class data directly exported from Qualtrics and you will need to wrangle it into shape before you can work with it. Import it into R as a data frame and look at it carefully to identify problems. Please create a **person-network** with the data set hudk4050-classes.csv. To create this network you will need to create a person-class matrix using the tidyr functions and then create a person-person matrix using `t()`. You will then need to plot a matrix rather than a to/from data frame using igraph. +```{r} +library(stringr) +library(tidyr) +#import data +C1 <- read.csv("hudk4050-classes.csv", stringsAsFactors=FALSE,header = TRUE) +C2<-C1 +``` +```{r} +colnames(C2) <-C2[1,] +C2<-slice(C2,3:49) +C2<-select (C2,1:8) +C2<- unite(C2,"name",`First Name`,`Last Name`,sep=" ") +C2$name <- str_replace(C2$name, "`","") +C2 <- C2 %>% mutate_at(2:7,list(toupper)) +C2 <- C2 %>% mutate_at(2:7,str_replace_all," ","") +``` +```{r} +C3<- C2 %>% gather(label, class,2:7,na.rm=TRUE,convert=FALSE)%>% select (name,class) +C3$count<-1 +C3<-filter(C3,class!="") +C3<-unique(C3) +C3<-spread(C3,class,count) +rownames(C3)<-C3$name +C3<-select(C3,-name) +C3<-select(C3,-HUDK4050) +C3[is.na(C3)]<-0 +``` +```{r} +C4<-as.matrix(C3) +C4<-C4 %*% t(C4) +``` +```{r} +g2<-graph.adjacency(C4,mode="undirected",diag=FALSE) +plot(g2,layout=layout.fruchterman.reingold) +plot(g2,layout=layout.fruchterman.reingold,vertex.size=4,vertext.label.cex=0.8,vertex.label.color="black",vertex.color="gainsboro") +``` + + Once you have done this, also [look up](http://igraph.org/r/) how to generate the following network metrics: * Betweeness centrality and dregree centrality. **Who is the most central person in the network according to these two metrics? Write a sentence or two that describes your interpretation of these metrics** +```{r} +#betweenness centrality + +sort(betweenness(g2),decreasing=TRUE) +``` +# Degree centrality +```{r} +#degree centrality of the nodes + +sort(degree(g2),decreasing=TRUE) +``` +From the degree centrality analysis, we don't see one person has much more connections than others. 8 students have measure of degree centrality of 31, which means they are connected with 31 students in the class (taking the same course(s)) respectively, no one has particularly high degree of centrality, this matches with what we see in the graph as well. +In this case, betweenness centrality tell us more information about the network than degree of centrality. If we wanted to find the influential person in the class, we should look at the betweenness centrality. + * Color the nodes according to interest. Are there any clusters of interest that correspond to clusters in the network? Write a sentence or two describing your interpetation. +```{r} +#Clean the data with the interest column +Ci<-C1 +colnames(Ci) <-Ci[1,] +Ci<-slice(Ci,3:49) +colnames(Ci)[c(9)] <- c( "interest") +Ci<- unite(Ci,"name",`First Name`,`Last Name`,sep=" ") +Ci$name <- str_replace(Ci$name, "`","") +Ci <- Ci %>% mutate_at(2:7,list(toupper)) +Ci <- Ci %>% mutate_at(2:7,str_replace_all," ","") +Ci <- unique(Ci) +color <- as.factor(Ci$interest) +g3<-graph.adjacency(C4,mode="undirected",diag=FALSE) +plot(g3,layout=layout.fruchterman.reingold, + vertext.label.cex=0.01, + vertex.label.color="black", + vertex.color=color) +``` +Based on the graph above, it doesn't seem like there's a pattern of interest and group cluster, it doesn't seem like the interest correspond to the cluster in our class. ### To Submit Your Assignment Please submit your assignment by first "knitting" your RMarkdown document into an html file and then comit, push and pull request both the RMarkdown file and the html file. From d3437d0eef20cef68a648d3b7aab259c0735978b Mon Sep 17 00:00:00 2001 From: Muyao Chen <70938621+Mia714@users.noreply.github.com> Date: Wed, 21 Oct 2020 23:59:19 -0400 Subject: [PATCH 2/2] html --- Assignment-3.html | 679 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 679 insertions(+) create mode 100644 Assignment-3.html diff --git a/Assignment-3.html b/Assignment-3.html new file mode 100644 index 0000000..07c3479 --- /dev/null +++ b/Assignment-3.html @@ -0,0 +1,679 @@ + + + + +
+ + + + + + + + +#degree centrality of the nodes
+
+sort(degree(g2),decreasing=TRUE)
+## Guoliang Xu Hangshi Jin Jiaao Qi
+## 31 31 31
+## Jiacong Zhu Jiahao Shen wenqi gao
+## 31 31 31
+## Xiyun Zhang Yingxin Xie Yifei Zhang
+## 31 31 24
+## Xiaojia Liu Yuxuan Ge Zhixin Zheng
+## 22 22 20
+## Stanley Si Heng Zhao Dan Lei Yuting Zhou
+## 19 16 16
+## Xueshi Wang Zhouda Wu Ruoyi Zhang
+## 14 14 12
+## Tianyu Chang Xijia Wang yunzhao wu
+## 12 12 12
+## JIE YAO Zach Friedman Nicole Schlosberg
+## 11 11 10
+## Yixiong Xu Berj Akian Kaijie Fang
+## 10 9 9
+## Rong Sang Yucheng Pan Amanda Oliveira
+## 8 7 6
+## Fei Wang Jiasheng Yu Wenning Xiao
+## 6 6 4
+## Yingxin Ye Danny Shan Fangqi Liu
+## 2 1 1
+## Hyungoo Lee Shuying Xiong Abdul Malik Muftau
+## 1 1 0
+## Ali Al Jabri Chris Kim He Chen
+## 0 0 0
+## Mahshad Davoodifard Qianhui Yuan Sara Vasquez
+## 0 0 0
+## Vidya Madhavan Yurui Wang
+## 0 0
+From the degree centrality analysis, we don’t see one person has much more connections than others. 8 students have measure of degree centrality of 31, which means they are connected with 31 students in the class (taking the same course(s)) respectively, no one has particularly high degree of centrality, this matches with what we see in the graph as well. In this case, betweenness centrality tell us more information about the network than degree of centrality. If we wanted to find the influential person in the class, we should look at the betweenness centrality.
+#Clean the data with the interest column
+Ci<-C1
+colnames(Ci) <-Ci[1,]
+Ci<-slice(Ci,3:49)
+colnames(Ci)[c(9)] <- c( "interest")
+Ci<- unite(Ci,"name",`First Name`,`Last Name`,sep=" ")
+Ci$name <- str_replace(Ci$name, "`","")
+Ci <- Ci %>% mutate_at(2:7,list(toupper))
+Ci <- Ci %>% mutate_at(2:7,str_replace_all," ","")
+Ci <- unique(Ci)
+color <- as.factor(Ci$interest)
+g3<-graph.adjacency(C4,mode="undirected",diag=FALSE)
+plot(g3,layout=layout.fruchterman.reingold,
+ vertext.label.cex=0.01,
+ vertex.label.color="black",
+ vertex.color=color)
+Based on the graph above, it doesn’t seem like there’s a pattern of interest and group cluster, it doesn’t seem like the interest correspond to the cluster in our class. ### To Submit Your Assignment
+Please submit your assignment by first “knitting” your RMarkdown document into an html file and then comit, push and pull request both the RMarkdown file and the html file.
+