Class 10 Prep (1)

Rmd

School

University of New Mexico, Main Campus *

*We aren’t endorsed by this school

Course

491

Subject

Computer Science

Date

Feb 20, 2024

Type

Rmd

Pages

3

Uploaded by CaptainWhaleMaster1019

Report
--- title: "Class 10 Prep" output: html_document date: "2022-11-21" --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` 1) Load the igraph and ggraph packages ```{r} library("igraph") library("ggraph") ``` 2) Load personal network data ```{r} node <- read.csv("Nodelist.csv") node ``` ```{r} edge <- read.csv("Edge_List.csv") edge ``` 1) Create an igraph object and visualize your network. ```{r} net <- graph_from_data_frame(edge, directed = F, vertices = node) net ``` ```{r} ggraph(net) + geom_edge_link(color = "black", alpha = 0.3) + geom_node_point(color = "#efd9d3") + theme_graph() ``` 2) Manipulate your network. Add 4 ties and 4 nodes, remove 3 ties and 3 nodes, and rewire your network with a 50% probability and no loops. 3) Plot the new network. ```{r} new_net <- net %>% add_vertices(nv = 4) %>% add_edges(c(1,3,5,7)) %>% rewire(each_edge(p = .50, loops = F)) %>%
delete_vertices(c(2, 4, 6)) %>% delete_edges(c(11, 9, 10)) #all steps together ggraph(new_net) + geom_edge_link0() + geom_node_point() ``` ```{r} #### Packages#### library(igraph) library(ggraph) library(EpiModel) library(dplyr) library(ndtv) ``` 4) Run an igraph SIR model (beta 10, gamma 5) over the original graph and your new graph. (Your graph may need to be made simple and undirected.) ```{r} ### SIR Model#### # Steps to run the Susceptible-Infected-Recovered model are the same as before, except: # 3) Like the SIS model there is a rec.rate term, but now it represents the average rate of recovery # beta is the rate of infection, gamma is the rate of recovery # igraph's sir function does require the network to be simple (no loops or multiplex ties) is.simple(net) #False, this means it is not simple is_simple <- simplify(net) is.simple(is_simple) #True, means it is simple # igraph's sir function *also* needs the graph to be undirected un_net <- is_directed(net) #FALSE un_net ``` ```{r} # The igraph function uses different arguments than EpiModel # beta is the rate of infection, gamma is the rate of recovery sir52 <- sir(graph = is_simple, beta = 10, gamma = 5) class(sir52) # output is a sir object/list. Use indexing to look inside. sir52 # lots of pieces sir52[[1]] # the first simulation sir52[[1]]$times # times of events sir52[[1]]$NS # number susceptible sir52[[1]]$NI # number infected sir52[[1]]$NR # number recovered plot(sir52) # shows all simulations at once ``` 5) How did the changes to network structure impact spread? ```{r} #The changes to my network structure impacted the spead in a negative way because there is a downwards slope. Node 10 was susceptible and nodes 1 and 0 were
infected. ```
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help