class: left, bottom, title-slide # Part 3: Network Description ## #aectRTD workshop ### K. Bret Staudt Willet | Florida State University ### March 4, 2022 --- class: inverse, center, middle #
<br><br> Workshop Information --- #
Important Links ## Homebase - **Workshop website:** https://bretsw.github.io/aect22-workshop - **Workshop code repository:** https://github.com/bretsw/aect22-workshop - **tidytags R package:** https://github.com/ropensci/tidytags ## Agenda - **Part 1: Introduction to Networks** - Slides: [Part 1 - Networks](1-networks.html) - **Part 2: Introduction to R** - Slides: [Part 2 - R](2-intro-R.html) - **Part 3: Network Description** - Slides: [Part 3 - Description](3-description.html) - **Part 4: Network Inference** - Slides: [Part 4 - Inference](4-inference.html) ## Help - Ask questions in the Zoom chat! - Or, reach out directly: - Email: [bret.staudtwillet@fsu.edu](mailto:bret.staudtwillet@fsu.edu) - Twitter: [@bretsw](https://twitter.com/bretsw) --- class: inverse, center, middle #
<br><br> **Part 3:** <br> Network Description --- #
Useful R packages <img src="img/tools.jpg" width="600px" style="display: block; margin: auto;" /> -- -
[**igraph**](https://CRAN.R-project.org/package=igraph) -- -
[**tidygraph**](https://CRAN.R-project.org/package=tidygraph) -- -
[**ggraph**](https://CRAN.R-project.org/package=ggraph) --- class: inverse, center, middle #
<br><br> **Network** <br> Example 1 --- #
Network Example 1
**Discussion Social Network Analysis:** [GitHub repository from @meteakca](https://github.com/meteakca/DiscussionSNA) -- What do you think this code will do? ```r edgelist1 <- read_csv("data/meteakca_edgelist.csv", show_col_types = FALSE) %>% mutate(group = week, week = substr(week, 1, 1) ) %>% group_by(from, to) %>% mutate(weight = n()) glimpse(edgelist1) ``` --- #
Network Example 1
**Discussion Social Network Analysis:** [GitHub repository from @meteakca](https://github.com/meteakca/DiscussionSNA) Let's see! ```r edgelist1 <- read_csv("data/meteakca_edgelist.csv", show_col_types = FALSE) %>% mutate(group = week, week = substr(week, 1, 1) ) %>% group_by(from, to) %>% mutate(weight = n()) %>% distinct(from, to, weight) glimpse(edgelist1) ``` ``` ## Rows: 182 ## Columns: 3 ## Groups: from, to [182] ## $ from <chr> "AL", "VW", "RN", "CH", "KW", "KJ", "Kwi", "AM", "KW", "KW", "Z… ## $ to <chr> "RN", "RN", "KW", "RN", "CH", "CH", "CH", "KW", "AM", "AL", "AL… ## $ weight <int> 1, 1, 1, 1, 2, 3, 1, 2, 2, 2, 1, 2, 1, 1, 1, 3, 1, 2, 1, 1, 1, … ``` --- #
Network Example 1 ```r head(edgelist1, 15) ``` ``` ## # A tibble: 15 × 3 ## # Groups: from, to [15] ## from to weight ## <chr> <chr> <int> ## 1 AL RN 1 ## 2 VW RN 1 ## 3 RN KW 1 ## 4 CH RN 1 ## 5 KW CH 2 ## 6 KJ CH 3 ## 7 Kwi CH 1 ## 8 AM KW 2 ## 9 KW AM 2 ## 10 KW AL 2 ## 11 ZT AL 1 ## 12 LW AL 2 ## 13 RS AL 1 ## 14 SP AL 1 ## 15 JK AL 1 ``` --- #
Network Example 1 ```r graph1 <- tidygraph::as_tbl_graph(edgelist1) ``` -- - **Order:** `igraph::gorder(graph1)` = 23 -- - **Size:** `igraph::gsize(graph1)` = 182 -- - **Diameter:** `igraph::diameter(graph1)` = 4 -- - **Density:** `igraph::edge_density(graph1)` = 0.36 -- - **Node degree:** `igraph::degree(graph1, mode = 'all')` = 15 -- - *In-degree:* `igraph::degree(graph1, mode = 'in')` = 8 -- - *Out-degree:* `igraph::degree(graph1, mode = 'out')` = 8 -- - **Reciprocity:** `igraph::reciprocity(graph1)` = 0.663 -- - **Transitivity:** `igraph::transitivity(graph1)` = 0.653 --- #
Network Example 1 What do you think this code will do? ```r sociogram1 <- graph1 %>% mutate(popularity = centrality_degree(mode = 'in')) %>% ggraph(layout = 'kk') + geom_edge_arc(alpha = .2, width = .5, strength = .5, color = 'steelblue' ) + geom_node_point(alpha = .4, aes(size = popularity)) + scale_size(range = c(1,10)) + theme_wsj() + scale_colour_wsj("colors6") + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks.x =element_blank(), axis.ticks.y =element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_blank(), panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank()) ``` --- #
Network Example 1 Let's see! ```r sociogram1 <- graph1 %>% mutate(popularity = centrality_degree(mode = 'in')) %>% ggraph(layout = 'kk') + geom_edge_arc(alpha = .2, width = .5, strength = .5, color = 'steelblue' ) + geom_node_point(alpha = .4, aes(size = popularity)) + scale_size(range = c(1,10)) + theme_wsj() + scale_colour_wsj("colors6") + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks.x =element_blank(), axis.ticks.y =element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_blank(), panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank()) ``` --- #
Network Example 1 <img src="img/sociogram1.png" width="100%" style="display: block; margin: auto;" /> -- ###
**Next step:** Look at the network by group or by week --- class: inverse, center, middle #
<br><br> **Network** <br> Example 2 --- #
Network Example 2 <img src="img/article-cover.png" width="700px" style="display: block; margin: auto;" /> **Article:** [A social network perspective on peer supported learning in MOOCs for educators ](http://www.irrodl.org/index.php/irrodl/article/view/1852) (Kellogg, Booth, & Oliver, 2014) --- #
Network Example 2 <img src="img/data-cover.png" width="700px" style="display: block; margin: auto;" /> **Data source:** [Massively Open Online Course for Educators (MOOC-Ed) network dataset](https://dataverse.harvard.edu/dataset.xhtml;jsessionid=9ad052693563b29056a88d490182?persistentId=doi%3A10.7910%2FDVN%2FZZH3UB&version=&q=&fileTypeGroupFacet=&fileAccess=&fileSortField=name&fileSortOrder=desc)] --- #
Network Example 2 <img src="img/example2-rq.png" width="100%" style="display: block; margin: auto;" /> --- #
Network Example 2 What do you think this code will do? ```r edgelist2 <- read_csv("data/DLT1 Edgelist.csv", show_col_types = FALSE) %>% group_by(Sender, Receiver) %>% mutate(Weight = n()) %>% ungroup() %>% relocate(Sender, Receiver, Weight) glimpse(edgelist2) ``` --- #
Network Example 2 Let's see! ```r edgelist2 <- read_csv("data/DLT1 Edgelist.csv", show_col_types = FALSE) %>% group_by(Sender, Receiver) %>% mutate(Weight = n()) %>% distinct(Sender, Receiver, Weight) glimpse(edgelist2) ``` ``` ## Rows: 1,978 ## Columns: 3 ## Groups: Sender, Receiver [1,978] ## $ Sender <dbl> 360, 356, 344, 392, 219, 318, 4, 355, 355, 310, 248, 150, 19,… ## $ Receiver <dbl> 444, 444, 444, 444, 444, 444, 444, 356, 444, 444, 444, 444, 3… ## $ Weight <int> 1, 2, 1, 1, 3, 2, 4, 1, 2, 1, 1, 2, 1, 1, 7, 1, 3, 1, 2, 1, 1… ``` --- #
Network Example 2 ```r head(edgelist2, 15) ``` ``` ## # A tibble: 15 × 3 ## # Groups: Sender, Receiver [15] ## Sender Receiver Weight ## <dbl> <dbl> <int> ## 1 360 444 1 ## 2 356 444 2 ## 3 344 444 1 ## 4 392 444 1 ## 5 219 444 3 ## 6 318 444 2 ## 7 4 444 4 ## 8 355 356 1 ## 9 355 444 2 ## 10 310 444 1 ## 11 248 444 1 ## 12 150 444 2 ## 13 19 310 1 ## 14 216 19 1 ## 15 19 444 7 ``` --- #
Network Example 2 ```r graph2 <- tidygraph::as_tbl_graph(edgelist2) ``` - **Order:** `igraph::gorder(graph2)` = 442 - **Size:** `igraph::gsize(graph2)` = 1978 - **Diameter:** `igraph::diameter(graph2)` = 8 - **Density:** `igraph::edge_density(graph2)` = 0.01 - **Node degree:** `igraph::degree(graph2, mode = 'all')` = 4 - *In-degree:* `igraph::degree(graph2, mode = 'in')` = 1 - *Out-degree:* `igraph::degree(graph2, mode = 'out')` = 2 - **Reciprocity:** `igraph::reciprocity(graph2)` = 0.219 - **Transitivity:** `igraph::transitivity(graph2)` = 0.089 --- #
Network Example 2 ```r sociogram2 <- graph2 %>% mutate(popularity = centrality_degree(mode = 'in')) %>% ggraph(layout = 'kk') + geom_edge_arc(alpha = .2, width = .5, strength = .5, color = 'steelblue' ) + geom_node_point(alpha = .4, aes(size = popularity)) + scale_size(range = c(1,10)) + theme_wsj() + scale_colour_wsj("colors6") + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks.x =element_blank(), axis.ticks.y =element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_blank(), panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank()) ``` --- #
Network Example 2 <img src="img/sociogram2.png" width="100%" style="display: block; margin: auto;" /> --- class: inverse, center, middle #
<br><br> **Network** <br> Example 3 --- #
Network Example 3 <img src="img/tidytags-logo.png" width="360px" style="display: block; margin: auto;" /> **R package demo:** [Using tidytags with a conference hashtag](https://docs.ropensci.org/tidytags/articles/tidytags-with-conf-hashtags.html) (Staudt Willet & Rosenberg, 2022) --- #
Network Example 3 What do you think this code will do? ```r google_sheet_url <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8" google_sheet_data <- google_sheet_url %>% tidytags::read_tags() extra_tweet_data <- tidytags::pull_tweet_data(google_sheet_data) %>% tidytags::process_tweets() edgelist3 <- tidytags::create_edgelist(extra_tweet_data) %>% group_by(sender, receiver) %>% mutate(weight = n()) %>% distinct(sender, receiver, weight) ``` ```r write_csv(edgelist3, "data/tidytags-edgelist.csv") ``` --- #
Network Example 3 Let's see! ```r edgelist3 <- read_csv("data/tidytags-edgelist.csv", show_col_types = FALSE) glimpse(edgelist3) ``` ``` ## Rows: 1,577 ## Columns: 3 ## $ sender <chr> "lbukunAA", "bretsw", "bretsw", "bretsw", "AECT", "correia65"… ## $ receiver <chr> "lbukunAA", "bretsw", "eromerohall", "FakeBobGagne", "jmenglu… ## $ weight <dbl> 1, 6, 3, 4, 2, 6, 6, 6, 6, 2, 7, 2, 15, 2, 2, 4, 18, 8, 2, 6,… ``` --- #
Network Example 3 ```r head(edgelist3, 15) ``` ``` ## # A tibble: 15 × 3 ## sender receiver weight ## <chr> <chr> <dbl> ## 1 lbukunAA lbukunAA 1 ## 2 bretsw bretsw 6 ## 3 bretsw eromerohall 3 ## 4 bretsw FakeBobGagne 4 ## 5 AECT jmenglund03 2 ## 6 correia65 AnnaRoseLeach 6 ## 7 caranorth11 FredWBaker 6 ## 8 PaulineMuljana tintinluo 6 ## 9 PaulineMuljana AmyLomellini_ID 6 ## 10 PaulineMuljana WEHSLibrary 2 ## 11 PaulineMuljana robmoore3 7 ## 12 PaulineMuljana soniastic 2 ## 13 nicolapallitt aectclt 15 ## 14 nicolapallitt eromerohall 2 ## 15 michaelmgrant FakeBobGagne 2 ``` --- #
Network Example 3 ```r graph3 <- tidygraph::as_tbl_graph(edgelist3) ``` - **Order:** `igraph::gorder(graph3)` = 511 - **Size:** `igraph::gsize(graph3)` = 1577 - **Diameter:** `igraph::diameter(graph3)` = 23 - **Density:** `igraph::edge_density(graph3)` = 0.006 - **Node degree:** `igraph::degree(graph3, mode = 'all')` = 2 - *In-degree:* `igraph::degree(graph3, mode = 'in')` = 1 - *Out-degree:* `igraph::degree(graph3, mode = 'out')` = 1 - **Reciprocity:** `igraph::reciprocity(graph3)` = 0.263 - **Transitivity:** `igraph::transitivity(graph3)` = 0.09 --- #
Network Example 3 ```r sociogram3 <- graph3 %>% mutate(popularity = centrality_degree(mode = 'in')) %>% ggraph(layout = 'kk') + geom_edge_arc(alpha = .2, width = .5, strength = .5, color = 'steelblue' ) + geom_node_point(alpha = .4, aes(size = popularity)) + scale_size(range = c(1,10)) + theme_wsj() + scale_colour_wsj("colors6") + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks.x =element_blank(), axis.ticks.y =element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_blank(), panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank()) ``` --- #
Network Example 3 <img src="img/sociogram3.png" width="100%" style="display: block; margin: auto;" /> --- class: inverse, center, middle #
<br><br> **Network** <br> Comparing networks --- #
Comparing networks <img src="img/sociogram-comparison.png" width="420px" style="display: block; margin: auto;" /> --- #
Comparing networks <table class="table table-striped table-bordered" style="margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:center;"> Variable </th> <th style="text-align:center;"> Classroom </th> <th style="text-align:center;"> MOOC </th> <th style="text-align:center;"> Twitter </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;"> Order </td> <td style="text-align:center;"> 23.000 </td> <td style="text-align:center;"> 442.000 </td> <td style="text-align:center;"> 511.000 </td> </tr> <tr> <td style="text-align:center;"> Size </td> <td style="text-align:center;"> 182.000 </td> <td style="text-align:center;"> 1978.000 </td> <td style="text-align:center;"> 1577.000 </td> </tr> <tr> <td style="text-align:center;"> Diameter </td> <td style="text-align:center;"> 4.000 </td> <td style="text-align:center;"> 8.000 </td> <td style="text-align:center;"> 23.000 </td> </tr> <tr> <td style="text-align:center;"> Density </td> <td style="text-align:center;"> 0.360 </td> <td style="text-align:center;"> 0.010 </td> <td style="text-align:center;"> 0.006 </td> </tr> <tr> <td style="text-align:center;"> Median Degree </td> <td style="text-align:center;"> 15.000 </td> <td style="text-align:center;"> 4.000 </td> <td style="text-align:center;"> 2.000 </td> </tr> <tr> <td style="text-align:center;"> In-Degree </td> <td style="text-align:center;"> 8.000 </td> <td style="text-align:center;"> 1.000 </td> <td style="text-align:center;"> 1.000 </td> </tr> <tr> <td style="text-align:center;"> Out-Degree </td> <td style="text-align:center;"> 8.000 </td> <td style="text-align:center;"> 2.000 </td> <td style="text-align:center;"> 1.000 </td> </tr> <tr> <td style="text-align:center;"> Reciprocity </td> <td style="text-align:center;"> 0.663 </td> <td style="text-align:center;"> 0.219 </td> <td style="text-align:center;"> 0.263 </td> </tr> <tr> <td style="text-align:center;"> Transitivity </td> <td style="text-align:center;"> 0.653 </td> <td style="text-align:center;"> 0.089 </td> <td style="text-align:center;"> 0.090 </td> </tr> </tbody> </table> --- class: inverse, center, middle #
<br><br> Try it out! Hop over to [**Workspace 3**](workspace3.Rmd) --- class: inverse, center, middle #
<br><br> Quick Check In **(Five minutes in groups, five minutes together)** - What challenges did you encounter? - What successes did you have? - What questions remain? --- class: inverse, center, middle #
<br><br> Appendix: <br> Helpful Resources <br> and Troubleshooting --- # Resources **Beginners:** - [RStudio Beginners' Guide](https://education.rstudio.com/learn/beginner/) - Book: [*Data Science in Education Using R*](https://datascienceineducation.com) - See [Chapter 12](https://datascienceineducation.com/c12.html) - Walkthrough 6: Exploring Relationships Using Social Network Analysis With Social Media Data - [Physical copy of DSIEUR](https://www.routledge.com/Data-Science-in-Education-Using-R/Estrellado-Freer-Mostipak-Rosenberg-Velasquez/p/book/9780367422257) - [Even more resources from DSIEUR](https://datascienceineducation.com/c18.html) **Intermediates:** - [RStudio Intermediates' Guide](https://education.rstudio.com/learn/intermediate/) - [{tidytags} package notes](https://docs.ropensci.org/tidytags/index.html) - Book: [*R for Data Science*](http://r4ds.had.co.nz/) **Experts:** - [RStudio Experts' Guide](https://education.rstudio.com/learn/expert/) - Book: [*Learning Statistics with R*](https://learningstatisticswithr.com/) - [*Data Science in Education Using R*](https://datascienceineducation.com) - See [Chapter 20.3 Appendix C](https://datascienceineducation.com/c20.html#c20c) - Social Network Influence and Selection Models - SNA resources: [Dr. Ken Frank's website](https://sites.google.com/msu.edu/kenfrank/social-network-resources) --- # Troubleshooting - Try to find out what the specific problem is - Identify what is *not* causing the problem - "Unplug and plug it back in" - restart R; close and reopen R - Seek out workshops and other learning opportunities - Reach out to others! Sharing what is causing an issue can often help to clarify the problem - [RStudio Community forum](https://community.rstudio.com/) (highly recommended!) - Twitter hashtag: [#RStats](https://twitter.com/search?q=%23RStats&src=typeahead_click&f=live) - [Contact Bret!](http://bretsw.com) - General strategies on learning more: [Chapter 17 of *Data Science in Education Using R*](https://datascienceineducation.com/c17.html) --- class: inverse, center, middle #
<br><br> *Next up* <br> Part 4: <br> Network Inference [`Part 4 slide deck here`](4-inference.html)