Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 3 #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
50 changes: 50 additions & 0 deletions Assignment 3.Rmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Assignment 3 - Social Network Analysis
Daniel Kwak

## Part I
Start by installing the "igraph" package. Once you have installed igraph, load the package.

Now upload the data file "comment-data.csv" as a data frame called "D1". Each row represents a comment from one student to another so the first line shows that student "28" commented on the comment of student "21". It also shows the gender of both students and the students' main elective field of study ("major"").

```{r}
library(igraph)

D1 <- read.csv("comment-data.csv", header = TRUE)
```

Expand Down Expand Up @@ -106,11 +109,58 @@ In Part II your task is to [look up](http://igraph.org/r/) in the igraph documen
* The vertices are colored according to major
* The vertices are sized according to the number of comments they have recieved

```{r}



tocount <- EDGE %>% group_by(to) %>% summarise(count =sum(count))
a <- rep(0, length(VERTEX$id))
for (i in 1:length(VERTEX$id)){
if(i %in% tocount$to){
a[i] <- tocount$count[which(tocount$to==i)]
}
}
plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$major, vertex.label.dist=0, vertex.size= a*3,margin=-0.1,edge.arrow.size=0.4, )
```
## 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(dplyr)
library(igraph)
library(readr)
library(tidyr)
library(stringr)

prsnet <-read.csv("hudk4050-classes.csv",stringsAsFactors = FALSE, header = TRUE)
col2 <- prsnet
colnames(col2) <- col2[1,]
col2 <- slice(col2, 3:49)
col2 <- select(col2,1:8)

col2<-tidyr::unite(col2,"student_name", `First Name`, `Last Name`,sep =" ")
col2$student_name<-str_replace(col2$student_name,"`","")
col2$student_name<-str_to_title(col2$student_name)
col2<-col2 %>% mutate_at(2:7, list(toupper))
col2 <- col2 %>% mutate_at(2:7, str_replace_all, " ", "")

stud<-col2%>%gather(label,class,2:7,na.rm=T,convert = F) %>% select(student_name,class)

stud$count <- 1

stud<-filter(stud,class!="")
rownames(stud) <- stud$name
stud<-unique(stud)
stud <-spread(stud, class, count)
stud<-select(stud, student_name, HUDK4050)
stud[is.na(stud)]<-0
head(stud,5)


#I wasn't able to figure out how to make a matrix without an error popping up and preventing me from knitting the document.
```

Once you have done this, also [look up](http://igraph.org/r/) how to generate the following network metrics:

Expand Down
Loading