class: left, bottom, title-slide .title[ # 3a. Class Network ] .subtitle[ ## Analytics Sandbox ] .author[ ### K. Bret Staudt Willet | Florida State University ] .date[ ### February 1, 2023 ] --- class: inverse, center, middle #
<br><br> **Part 3a:** <br> Class Network --- #
Class Network data ```r edgelist1 <- read_csv("data/edgelist.csv", show_col_types = FALSE) %>% mutate(group = week, week = substr(week, 1, 1) ) %>% group_by(from, to) %>% mutate(weight = n()) glimpse(edgelist1) ``` ``` ## Rows: 317 ## Columns: 5 ## Groups: from, to [182] ## $ week <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"… ## $ 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… ## $ group <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"… ## $ weight <int> 1, 1, 1, 1, 2, 3, 1, 2, 2, 2, 1, 2, 1, 1, 1, 3, 1, 2, 1, 1, 1, … ``` --- #
Class Network data ```r head(edgelist1, 10) ``` ``` ## # A tibble: 10 × 5 ## # Groups: from, to [10] ## week from to group weight ## <chr> <chr> <chr> <chr> <int> ## 1 1 AL RN 1 1 ## 2 1 VW RN 1 1 ## 3 1 RN KW 1 1 ## 4 1 CH RN 1 1 ## 5 1 KW CH 1 2 ## 6 1 KJ CH 1 3 ## 7 1 Kwi CH 1 1 ## 8 1 AM KW 1 2 ## 9 1 KW AM 1 2 ## 10 1 KW AL 1 2 ``` --- class: inverse, center, middle #
<br><br> Try it Out! --- #
Try it Out! What do you think this code will do? ```r network_graph <- tidygraph::as_tbl_graph(edgelist1) %>% mutate(popularity = centrality_degree(mode = 'in')) network_graph ``` ``` ## # A tbl_graph: 23 nodes and 317 edges ## # ## # A directed multigraph with 1 component ## # ## # Node Data: 23 × 2 (active) ## name popularity ## <chr> <dbl> ## 1 AL 24 ## 2 VW 4 ## 3 RN 30 ## 4 CH 17 ## 5 KW 18 ## 6 KJ 20 ## # … with 17 more rows ## # ## # Edge Data: 317 × 5 ## from to week group weight ## <int> <int> <chr> <chr> <int> ## 1 1 3 1 1 1 ## 2 2 3 1 1 1 ## 3 3 5 1 1 1 ## # … with 314 more rows ``` --- #
Try it Out! What do you think this code will do? ```r network_graph %>% ggraph(layout = 'kk') ``` ![](3-class-network_files/figure-html/unnamed-chunk-4-1.png)<!-- --> --- #
Try it Out! What do you think this code will do? ```r network_graph %>% ggraph(layout = 'kk') + geom_edge_arc() ``` ![](3-class-network_files/figure-html/unnamed-chunk-5-1.png)<!-- --> --- #
Try it Out! What do you think this code will do? ```r network_graph %>% ggraph(layout = 'kk') + geom_edge_arc() + geom_node_point() ``` ![](3-class-network_files/figure-html/unnamed-chunk-6-1.png)<!-- --> --- #
Try it Out! What do you think this code will do? ```r network_graph %>% ggraph(layout = 'kk') + geom_edge_arc() + geom_node_point(alpha = .4, aes(size = popularity)) + scale_size(range = c(1,10)) ``` ![](3-class-network_files/figure-html/unnamed-chunk-7-1.png)<!-- --> --- #
Try it Out! What do you think this code will do? ```r network_graph %>% 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)) ``` ![](3-class-network_files/figure-html/unnamed-chunk-8-1.png)<!-- --> --- #
Try it Out! What do you think this code will do? ```r network_graph %>% 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()) ``` ![](3-class-network_files/figure-html/unnamed-chunk-9-1.png)<!-- --> --- #
Picture it! <img src="output/3-class-network.png" width="600px" style="display: block; margin: auto;" /> --- #
Look closer! **Online Class Discussion - Social Network Analysis** There are quite a few descriptive measures of networks: - **Order:** number of nodes/vertices (students, in this case) - **Size:** number of edges/connections (responses, in this case) - **Reciprocity:** mutuality - **Transitivity:** clustering - **Diameter:** similar to degrees of separation - **Density:** out of all possible connections, percentage that have been made - **Node degree:** number of connections - **Sentiment score:** how positive or negative in aggregate - Character count, Word count, Length of threads --- #
Look closer! **Order:** number of nodes/vertices (students, in this case) ```r library(igraph) gorder(network_graph) ``` ``` ## [1] 23 ``` <hr> **Size:** number of edges/connections (responses, in this case) ```r gsize(network_graph) ``` ``` ## [1] 317 ``` --- #
Look closer! **Reciprocity:** mutuality ```r reciprocity(network_graph) ``` ``` ## [1] 0.5874587 ``` <hr> **Transitivity:** clustering ```r transitivity(network_graph) ``` ``` ## [1] 0.6530769 ``` --- #
Look closer! **Diameter:** similar to degrees of separation ```r diameter(network_graph) ``` ``` ## [1] 4 ``` <hr> **Density:** out of all possible connections, percentage that have been made ```r edge_density(network_graph) ``` ``` ## [1] 0.6264822 ``` --- #
Look closer! **Node degree:** number of connections ```r mean(degree(network_graph)) ``` ``` ## [1] 27.56522 ``` <hr> ```r degree(network_graph) %>% mean() ``` ``` ## [1] 27.56522 ``` <hr> ```r median(degree(network_graph)) ``` ``` ## [1] 26 ``` --- class: inverse, center, middle #
<br> <br> **Try it differently!** <br><br> Interact with a Shiny App https://fsuksu.shinyapps.io/fsuksu/ --- class: inverse, center, middle #
<br><br> Try on your own! --- #
Try on your own! - Download a copy of this repository. - Use the saved data in the "data" folder to play around a bit more, changing different parameters. - Reflect: - What other comparisons might you make? - How else might you analyze these data? --- 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!](https://bretsw.com) - General strategies on learning more: [Chapter 17 of *Data Science in Education Using R*](https://datascienceineducation.com/c17.html)