{"action":"created","comment":{"url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/comments/229786463","pull_request_review_id":170369381,"id":229786463,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTc4NjQ2Mw==","diff_hunk":"@@ -0,0 +1,134 @@\n+# Assignment 2 - Social Network Analysis\n+\n+## Part I\n+Start by installing the \"igraph\" package. Once you have installed igraph, load the package.\n+\n+Now upload the data file \"discipline-data.csv\" as a data frame called \"D1\". Each row is a disciplinary action from a teacher to a student so the first line shows that teacher \"E\" sent student \"21\" to the principal. It also shows the gender of both the teacher and student and the student's main elective field of study (\"major\"\") and the field that the teacher instructs in (\"t.expertise\").\n+\n+Before you proceed, you will need to change the data type of the student id variable. Since it is a number R will automatically think it is an integer and code it as such (look at the list of variables by clicking on the data frame arrow in the Data pane. Here you will see the letters \"int\"\" next to the stid variable, that stands for integer). However, in this case we are treating the variable as a category, there is no numeric meaning in the variable. So we need to change the format to be a category, what R calls a \"factor\". We can do this with the following code:\n+\n+```{r}\n+D1$stid <- as.factor(D1$stid)\n+```\n+\n+igraph requires data to be in a particular structure. There are several structures that it can use but we will be using a combination of an \"edge list\" and a \"vertex list\". As you might imagine the edge list contains a list of all the relationships between students and teachers and any characteristics of those edges that we might be interested in. There are two essential variables in the edge list a \"from\" variable and a \"to\" variable that descibe the relationships between vertices (a disciplinary action is given \"from\" and teacher \"to\" a student). While the vertix list contains all the characteristics of those vertices, in our case gender and major.\n+\n+So let's convert our data into an edge list!\n+\n+First we will isolate the variables that are of interest: tid and stid\n+\n+```{r}\n+library(dplyr)\n+\n+D2 <- dplyr::select(D1, tid, stid)\n+```\n+\n+Since our data represnts every time a teacher sends a student to the principal there are multiple rows when the same teacher sends the same student. We want to collapse these into a single row, with a variable that shows how many times a teacher-student pair appears.\n+\n+```{r}\n+\n+EDGE <- dplyr::count(D2, tid, stid)\n+\n+names(EDGE) <- c(\"from\", \"to\", \"count\")\n+\n+```\n+\n+EDGE is your edge list. Now we need to make the vertex list, a list of all the teachers and students and their characteristics in our network.\n+\n+```{r}\n+\n+#First we will separate the teachers from our original data frame\n+V.TCH <- dplyr::select(D1, tid, t.gender, t.expertise)\n+#Remove all the repeats so that we just have a list of each teacher and their characteristics\n+V.TCH <- unique(V.TCH)\n+#Add a variable that describes that they are teachers\n+V.TCH$group <- \"teacher\"\n+\n+#Now repeat this process for the students\n+V.STD <- dplyr::select(D1, stid, s.gender, s.major)\n+V.STD <- unique(V.STD)\n+V.STD$group <- \"student\"\n+\n+#Make sure that the student and teacher data frames have the same variables names\n+names(V.TCH) <- c(\"id\", \"gender\", \"topic\", \"group\")\n+names(V.STD) <- c(\"id\", \"gender\", \"topic\", \"group\")\n+\n+#Bind the two data frames together (you will get a warning because the teacher data frame has 5 types of id (A,B,C,D,E) and the student has 25 (1-30), this isn't a problem)\n+VERTEX <- dplyr::bind_rows(V.TCH, V.STD)\n+\n+```\n+\n+Now we have both a Vertex and Edge list it is time to plot our graph!\n+\n+```{r}\n+#Load the igraph package\n+\n+library(igraph)\n+\n+#First we will make an object that contains the graph information using our two dataframes EDGE and VERTEX. Notice that we have made \"directed = TRUE\" - our graph is directed since discipline is being given from a teacher to a student.\n+\n+g <- graph.data.frame(EDGE, directed=TRUE, vertices=VERTEX)\n+\n+#Now we can plot our graph using the force directed graphing technique - our old friend Fruchertman-Reingold!\n+\n+plot(g,layout=layout.fruchterman.reingold)\n+\n+#There are many ways to change the attributes of the graph to represent different characteristics of the newtork. For example, we can color the nodes according to gender.\n+\n+plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$gender)\n+\n+#We can change the thickness of the edge according to the number of times a particular teacher has sent a particular student to the principal.\n+\n+plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$gender, edge.width=EDGE$count)\n+````\n+\n+## Part II\n+\n+In Part II your task is to [look up](http://igraph.org/r/) in the igraph documentation and create a graph that sizes the student vertices in terms of the number of disciplinary actions they have recieved, and the teachers in terms of the number of disciplinary actions they have given out.\n+\n+```{r}\n+N.tid <- EDGE %>% group_by(from) %>% summarise(sum(count))\n+N.sid <- EDGE %>% group_by(to) %>% summarise(sum(count))","path":"Jingyi Lin- Assignment 2.Rmd","position":91,"original_position":91,"commit_id":"c92bfc04cfb57ffa3f4d4772958b201ad4fe08cd","original_commit_id":"c92bfc04cfb57ffa3f4d4772958b201ad4fe08cd","user":{"login":"charles-lang","id":16405180,"node_id":"MDQ6VXNlcjE2NDA1MTgw","avatar_url":"https://avatars3.githubusercontent.com/u/16405180?v=4","gravatar_id":"","url":"https://api.github.com/users/charles-lang","html_url":"https://github.com/charles-lang","followers_url":"https://api.github.com/users/charles-lang/followers","following_url":"https://api.github.com/users/charles-lang/following{/other_user}","gists_url":"https://api.github.com/users/charles-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/charles-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charles-lang/subscriptions","organizations_url":"https://api.github.com/users/charles-lang/orgs","repos_url":"https://api.github.com/users/charles-lang/repos","events_url":"https://api.github.com/users/charles-lang/events{/privacy}","received_events_url":"https://api.github.com/users/charles-lang/received_events","type":"User","site_admin":false},"body":"Well done, an elegant solution to the problem 👍 ","created_at":"2018-10-31T17:08:20Z","updated_at":"2018-10-31T17:12:22Z","html_url":"https://github.com/core-methods-in-edm/assignment2/pull/48#discussion_r229786463","pull_request_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/comments/229786463"},"html":{"href":"https://github.com/core-methods-in-edm/assignment2/pull/48#discussion_r229786463"},"pull_request":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48","id":225575157,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI1NTc1MTU3","html_url":"https://github.com/core-methods-in-edm/assignment2/pull/48","diff_url":"https://github.com/core-methods-in-edm/assignment2/pull/48.diff","patch_url":"https://github.com/core-methods-in-edm/assignment2/pull/48.patch","issue_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/48","number":48,"state":"open","locked":false,"title":"Assignment 2 - Jingyi Lin","user":{"login":"jl5191","id":43050072,"node_id":"MDQ6VXNlcjQzMDUwMDcy","avatar_url":"https://avatars1.githubusercontent.com/u/43050072?v=4","gravatar_id":"","url":"https://api.github.com/users/jl5191","html_url":"https://github.com/jl5191","followers_url":"https://api.github.com/users/jl5191/followers","following_url":"https://api.github.com/users/jl5191/following{/other_user}","gists_url":"https://api.github.com/users/jl5191/gists{/gist_id}","starred_url":"https://api.github.com/users/jl5191/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl5191/subscriptions","organizations_url":"https://api.github.com/users/jl5191/orgs","repos_url":"https://api.github.com/users/jl5191/repos","events_url":"https://api.github.com/users/jl5191/events{/privacy}","received_events_url":"https://api.github.com/users/jl5191/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-24T22:53:45Z","updated_at":"2018-10-31T17:12:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"934da279c8c58f8758bf1c12201e7a9e1fa8a86b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48/commits","review_comments_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48/comments","review_comment_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/48/comments","statuses_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/statuses/c92bfc04cfb57ffa3f4d4772958b201ad4fe08cd","head":{"label":"jl5191:master","ref":"master","sha":"c92bfc04cfb57ffa3f4d4772958b201ad4fe08cd","user":{"login":"jl5191","id":43050072,"node_id":"MDQ6VXNlcjQzMDUwMDcy","avatar_url":"https://avatars1.githubusercontent.com/u/43050072?v=4","gravatar_id":"","url":"https://api.github.com/users/jl5191","html_url":"https://github.com/jl5191","followers_url":"https://api.github.com/users/jl5191/followers","following_url":"https://api.github.com/users/jl5191/following{/other_user}","gists_url":"https://api.github.com/users/jl5191/gists{/gist_id}","starred_url":"https://api.github.com/users/jl5191/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl5191/subscriptions","organizations_url":"https://api.github.com/users/jl5191/orgs","repos_url":"https://api.github.com/users/jl5191/repos","events_url":"https://api.github.com/users/jl5191/events{/privacy}","received_events_url":"https://api.github.com/users/jl5191/received_events","type":"User","site_admin":false},"repo":{"id":153359966,"node_id":"MDEwOlJlcG9zaXRvcnkxNTMzNTk5NjY=","name":"assignment2","full_name":"jl5191/assignment2","private":false,"owner":{"login":"jl5191","id":43050072,"node_id":"MDQ6VXNlcjQzMDUwMDcy","avatar_url":"https://avatars1.githubusercontent.com/u/43050072?v=4","gravatar_id":"","url":"https://api.github.com/users/jl5191","html_url":"https://github.com/jl5191","followers_url":"https://api.github.com/users/jl5191/followers","following_url":"https://api.github.com/users/jl5191/following{/other_user}","gists_url":"https://api.github.com/users/jl5191/gists{/gist_id}","starred_url":"https://api.github.com/users/jl5191/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl5191/subscriptions","organizations_url":"https://api.github.com/users/jl5191/orgs","repos_url":"https://api.github.com/users/jl5191/repos","events_url":"https://api.github.com/users/jl5191/events{/privacy}","received_events_url":"https://api.github.com/users/jl5191/received_events","type":"User","site_admin":false},"html_url":"https://github.com/jl5191/assignment2","description":null,"fork":true,"url":"https://api.github.com/repos/jl5191/assignment2","forks_url":"https://api.github.com/repos/jl5191/assignment2/forks","keys_url":"https://api.github.com/repos/jl5191/assignment2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jl5191/assignment2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jl5191/assignment2/teams","hooks_url":"https://api.github.com/repos/jl5191/assignment2/hooks","issue_events_url":"https://api.github.com/repos/jl5191/assignment2/issues/events{/number}","events_url":"https://api.github.com/repos/jl5191/assignment2/events","assignees_url":"https://api.github.com/repos/jl5191/assignment2/assignees{/user}","branches_url":"https://api.github.com/repos/jl5191/assignment2/branches{/branch}","tags_url":"https://api.github.com/repos/jl5191/assignment2/tags","blobs_url":"https://api.github.com/repos/jl5191/assignment2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jl5191/assignment2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jl5191/assignment2/git/refs{/sha}","trees_url":"https://api.github.com/repos/jl5191/assignment2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jl5191/assignment2/statuses/{sha}","languages_url":"https://api.github.com/repos/jl5191/assignment2/languages","stargazers_url":"https://api.github.com/repos/jl5191/assignment2/stargazers","contributors_url":"https://api.github.com/repos/jl5191/assignment2/contributors","subscribers_url":"https://api.github.com/repos/jl5191/assignment2/subscribers","subscription_url":"https://api.github.com/repos/jl5191/assignment2/subscription","commits_url":"https://api.github.com/repos/jl5191/assignment2/commits{/sha}","git_commits_url":"https://api.github.com/repos/jl5191/assignment2/git/commits{/sha}","comments_url":"https://api.github.com/repos/jl5191/assignment2/comments{/number}","issue_comment_url":"https://api.github.com/repos/jl5191/assignment2/issues/comments{/number}","contents_url":"https://api.github.com/repos/jl5191/assignment2/contents/{+path}","compare_url":"https://api.github.com/repos/jl5191/assignment2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jl5191/assignment2/merges","archive_url":"https://api.github.com/repos/jl5191/assignment2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jl5191/assignment2/downloads","issues_url":"https://api.github.com/repos/jl5191/assignment2/issues{/number}","pulls_url":"https://api.github.com/repos/jl5191/assignment2/pulls{/number}","milestones_url":"https://api.github.com/repos/jl5191/assignment2/milestones{/number}","notifications_url":"https://api.github.com/repos/jl5191/assignment2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jl5191/assignment2/labels{/name}","releases_url":"https://api.github.com/repos/jl5191/assignment2/releases{/id}","deployments_url":"https://api.github.com/repos/jl5191/assignment2/deployments","created_at":"2018-10-16T22:01:14Z","updated_at":"2018-10-24T22:51:13Z","pushed_at":"2018-10-24T22:51:12Z","git_url":"git://github.com/jl5191/assignment2.git","ssh_url":"git@github.com:jl5191/assignment2.git","clone_url":"https://github.com/jl5191/assignment2.git","svn_url":"https://github.com/jl5191/assignment2","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"core-methods-in-edm:master","ref":"master","sha":"756fa3061e47b07df58836306e69d4eddd343649","user":{"login":"core-methods-in-edm","id":21262497,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjYyNDk3","avatar_url":"https://avatars2.githubusercontent.com/u/21262497?v=4","gravatar_id":"","url":"https://api.github.com/users/core-methods-in-edm","html_url":"https://github.com/core-methods-in-edm","followers_url":"https://api.github.com/users/core-methods-in-edm/followers","following_url":"https://api.github.com/users/core-methods-in-edm/following{/other_user}","gists_url":"https://api.github.com/users/core-methods-in-edm/gists{/gist_id}","starred_url":"https://api.github.com/users/core-methods-in-edm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/core-methods-in-edm/subscriptions","organizations_url":"https://api.github.com/users/core-methods-in-edm/orgs","repos_url":"https://api.github.com/users/core-methods-in-edm/repos","events_url":"https://api.github.com/users/core-methods-in-edm/events{/privacy}","received_events_url":"https://api.github.com/users/core-methods-in-edm/received_events","type":"Organization","site_admin":false},"repo":{"id":70741774,"node_id":"MDEwOlJlcG9zaXRvcnk3MDc0MTc3NA==","name":"assignment2","full_name":"core-methods-in-edm/assignment2","private":false,"owner":{"login":"core-methods-in-edm","id":21262497,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjYyNDk3","avatar_url":"https://avatars2.githubusercontent.com/u/21262497?v=4","gravatar_id":"","url":"https://api.github.com/users/core-methods-in-edm","html_url":"https://github.com/core-methods-in-edm","followers_url":"https://api.github.com/users/core-methods-in-edm/followers","following_url":"https://api.github.com/users/core-methods-in-edm/following{/other_user}","gists_url":"https://api.github.com/users/core-methods-in-edm/gists{/gist_id}","starred_url":"https://api.github.com/users/core-methods-in-edm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/core-methods-in-edm/subscriptions","organizations_url":"https://api.github.com/users/core-methods-in-edm/orgs","repos_url":"https://api.github.com/users/core-methods-in-edm/repos","events_url":"https://api.github.com/users/core-methods-in-edm/events{/privacy}","received_events_url":"https://api.github.com/users/core-methods-in-edm/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/core-methods-in-edm/assignment2","description":null,"fork":false,"url":"https://api.github.com/repos/core-methods-in-edm/assignment2","forks_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/forks","keys_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/teams","hooks_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/hooks","issue_events_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/events{/number}","events_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/events","assignees_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/assignees{/user}","branches_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/branches{/branch}","tags_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/tags","blobs_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/git/refs{/sha}","trees_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/statuses/{sha}","languages_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/languages","stargazers_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/stargazers","contributors_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/contributors","subscribers_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/subscribers","subscription_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/subscription","commits_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/commits{/sha}","git_commits_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/git/commits{/sha}","comments_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/comments{/number}","issue_comment_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/comments{/number}","contents_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/contents/{+path}","compare_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/merges","archive_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/downloads","issues_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues{/number}","pulls_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls{/number}","milestones_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/milestones{/number}","notifications_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/labels{/name}","releases_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/releases{/id}","deployments_url":"https://api.github.com/repos/core-methods-in-edm/assignment2/deployments","created_at":"2016-10-12T21:08:32Z","updated_at":"2018-10-30T03:55:14Z","pushed_at":"2018-10-30T21:38:19Z","git_url":"git://github.com/core-methods-in-edm/assignment2.git","ssh_url":"git@github.com:core-methods-in-edm/assignment2.git","clone_url":"https://github.com/core-methods-in-edm/assignment2.git","svn_url":"https://github.com/core-methods-in-edm/assignment2","homepage":null,"size":23,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":101,"mirror_url":null,"archived":false,"open_issues_count":53,"license":null,"forks":101,"open_issues":53,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48"},"html":{"href":"https://github.com/core-methods-in-edm/assignment2/pull/48"},"issue":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/48"},"comments":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/core-methods-in-edm/assignment2/statuses/c92bfc04cfb57ffa3f4d4772958b201ad4fe08cd"}},"author_association":"NONE"}}
{"actor":{"display_login":"charles-lang"}}