Day-03

Pablo Gomez

Review: day 01

x <- seq(from = 5, to = 23, length.out = 10) # create a sequence of numbers
y <- seq(from = 0.1, to = 0.78, length.out = 10) # Create another sequence

mean(x*y) # Get the mean of the multiplication
[1] 7.406667

Objects:
- x
- y

Operators:
- *
- <-

Functions:
- seq()
- mean()

Arguments:
- from
- to
- lengt.out

Review: day 02


  • select() to select specific columns
  • slice() to select specific rows based on position
  • filter() to select specific rows based on a condition
  • mutate() to create new variables

Review: day 02


Other function we reviewed:

  • count() Count rows by one or more groups
  • group_by() aggregate the data by one or more groups
  • summarise() applies functions to the grouped variables

Review: figures


Components needed to define a graphic:

  • data, the data set we will use to generate the figure
  • geometry, or type of graphic we will generate (i.e. histogram, bar, scatter, etc..)
  • aesthetic or mapping, variables or arguments that will be used for the figure for example: location, color, size, etc..

Review: Maps


Types of vectors:

  • Point, Location
  • Line, Location and direction
  • Polygon, Location and area

Review: Maps


ggplot() +
  geom_stars(data = Mxst) +
  geom_sf(data = Area, fill = NA, col = 'grey60') +
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') +
  theme_void() +
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) +
  geom_sf(data = Area, fill = NA, col = 'grey60') +
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') +
  theme_void() +
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + 
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') +
  theme_void() +
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + # add polygon layer
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') +
  theme_void() +
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + # add polygon layer
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') + # add point layer
  theme_void() +
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + # add polygon layer
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') + # add point layer
  theme_void() + # theme for the figure
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) +
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + # add polygon layer
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') + # add point layer
  theme_void() + # theme for the figure
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) + # color for the gradient
  labs(fill = 'Altitude')

Review: Maps


ggplot() + # create the empty canvas
  geom_stars(data = Mxst) + # add raster layer
  geom_sf(data = Area, fill = NA, col = 'grey60') + # add polygon layer
  geom_sf(data = capturesSp, cex = 0.3, col = 'skyblue') + # add point layer
  theme_void() + # theme for the figure
  scale_fill_gradient(low = 'black', high = 'red', na.value = NA) + # color for the gradient
  labs(title = 'Map of the study area', fill = 'Altitude') # labels for the figure

Network analysis

Why represent events in a network?


Identify individuals that are very active

Identify individuals that are intermediate

What is a graph?


Elements of a network


Nodes (vertices)

\[V = [1, 2, 3, ..., i]\]

Elements of a network


Nodes (vertices)

\[V = [1, 2, 3, ..., i]\]

Elements of a network


Edges (links)

\[E = [(1, 2), (1, 3), (2, 3), ..., (i,j)]\]

Elements of a network


Network attributes

\[V = [0, 1, 1, ..., x_i]\]

Data structure


General properties


General properties


  • Size
  • Diameter
  • Average path length
  • Density
  • Fragmentation
  • Clustering Coefficient

General properties


General properties


Local properties


Local properties


Local properties


SNA in R

SNA in R


net <- as_tbl_graph(edge)

net
# A tbl_graph: 40 nodes and 1611 edges
#
# A directed multigraph with 1 component
#
# A tibble: 40 × 1
  name 
  <chr>
1 17   
2 12   
3 14   
4 11   
5 7    
6 9    
# ℹ 34 more rows
#
# A tibble: 1,611 × 6
   from    to date    pigs.moved type_orig type_dest
  <int> <int> <chr>        <int> <chr>     <chr>    
1     1     7 8/20/15        160 finisher  sow farm 
2     1     7 8/20/15         76 finisher  sow farm 
3     1     3 9/11/15        155 finisher  nursery  
# ℹ 1,608 more rows

tidygraph


  • remember %>%?
  • tidygrapgh introduces two new type of operators:
    • %N>% for nodes
    • %E>% for edges

Visualization


ggraph(net, layout = 'kk') + # this is our empty canvas
  geom_edge_link(aes(width = pigs.moved)) + # Add the edges
  geom_node_point() + # Add the nodes
  scale_edge_width(range = c(0.01, 0.9)) + # we set the range for the width of the edges
  labs(title = 'Title for the plot', edge_width = 'Number of pigs moved') # labels for the figure

It’s Lab time!

Network analysis in R

Risk assessment

Risk analysis


Risk assessment


Triage


Triage


From this we could conclude:

  • No need for further action
  • More information needed
  • Need for a RA

Hazard profiling


A description of the health event and its context, current state of knowledge and potential risk management options

  • Classification of the causative agent
  • Persistence in the environment
  • Pathogenesis
  • Epidemiology
  • Prevention and control

Formulating your question


Formulating your question


Data collection


To facilitate the search for data, eligibility criteria should be defined that take into account:

  • Population of interest
  • Variables of concern
  • Possible geographical and time restrictions

Expert opinion


  • Online questionnaire
  • Expert panel
  • Interviews
  • Focus groups discussions

Performing the assessment


Type of outputs might include:

  • Probability
    • Probability of X event happening
    • Probability of more than 10 introductions per year
  • Consequences
    • Number of animals/people infected
    • Economic impact

Performing the assessment


Performing the assessment


Risk assessment in R


Risk assessment in R


Risk assessment in R


It’s Lab time!

Risk assessment in R