Connection patterns N E TW OR K AN ALYSIS IN TH E TIDYVE R SE - - PowerPoint PPT Presentation

connection patterns
SMART_READER_LITE
LIVE PREVIEW

Connection patterns N E TW OR K AN ALYSIS IN TH E TIDYVE R SE - - PowerPoint PPT Presentation

Connection patterns N E TW OR K AN ALYSIS IN TH E TIDYVE R SE Massimo Franceschet Prof . of Data Science , Uni v ersit y of Udine ( Ital y) The adjacenc y matri x ( part 1) as_adjacency_matrix(g) 1 2 3 4 5 6 1 0 1 0


slide-1
SLIDE 1

Connection patterns

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE

Massimo Franceschet

  • Prof. of Data Science, University of

Udine (Italy)

slide-2
SLIDE 2

NETWORK ANALYSIS IN THE TIDYVERSE

The adjacency matrix (part 1)

as_adjacency_matrix(g) 1 2 3 4 5 6 1 0 1 0 0 1 0 2 1 0 1 1 0 0 3 0 1 0 1 1 1 4 0 1 1 0 0 0 5 1 0 1 0 0 0 6 0 0 1 0 0 0

slide-3
SLIDE 3

NETWORK ANALYSIS IN THE TIDYVERSE

The adjacency matrix (part 2)

as_adjacency_matrix(g, attr="weight") 1 2 3 4 5 6 1 0 1 0 0 2 0 2 1 0 2 3 0 0 3 0 2 0 4 5 1 4 0 3 4 0 0 0 5 2 0 5 0 0 0 6 0 0 1 0 0 0

slide-4
SLIDE 4

NETWORK ANALYSIS IN THE TIDYVERSE

Working with adjacency matrices

# get the adjacency matrix of network g A = as_adjacency_matrix(g) # get the weighted adjacency matrix of weighted network g A = as_adjacency_matrix(g, attr = "weight") # first row of matrix A A[1, ] # first column of matrix A A[, 1] # diagonal of matrix A diag(A)

slide-5
SLIDE 5

NETWORK ANALYSIS IN THE TIDYVERSE

Pearson similarity

as_adjacency_matrix(g) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 0 0 1 0 [2,] 1 0 1 1 0 0 [3,] 0 1 0 1 1 1 [4,] 0 1 1 0 0 0 [5,] 1 0 1 0 0 0 [6,] 0 0 1 0 0 0

slide-6
SLIDE 6

Let's try some examples!

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE

slide-7
SLIDE 7

Pearson similarity

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE

Massimo Franceschet

  • Prof. of Data Science, University of

Udine (Italy)

slide-8
SLIDE 8

NETWORK ANALYSIS IN THE TIDYVERSE

Visualizing correlation

# scatterplot of degree and strength ggplot(data = nodes, mapping = aes(x = degree, y = strength)) + geom_point() + geom_smooth(method = "lm", se = FALSE)

slide-9
SLIDE 9

NETWORK ANALYSIS IN THE TIDYVERSE

Computing correlation

Positive values indicate positive correlation Negative values indicate negative correlation Null values indicate no correlation

# Pearson correlation coefficient cor(nodes$degree, nodes$strength) 0.9708946

slide-10
SLIDE 10

Let's practice!

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE

slide-11
SLIDE 11

Most similar and most dissimilar nodes

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE

Massimo Franceschet

  • Prof. of Data Science, University of

Udine (Italy)

slide-12
SLIDE 12

NETWORK ANALYSIS IN THE TIDYVERSE

slide-13
SLIDE 13

NETWORK ANALYSIS IN THE TIDYVERSE

A network as a matrix

as_adjacency_matrix(g, attr = "weight") a b c d e a 0 1 0 0 2 b 1 0 2 3 0 c 0 2 0 4 5 d 0 3 4 0 0 e 2 0 5 0 0

slide-14
SLIDE 14

NETWORK ANALYSIS IN THE TIDYVERSE

A network as a data frame

as_data_frame(g, what = "both") $nodes name a a b b c c d d e e $ties from to weight 1 a b 1 2 a e 2 3 b c 2 4 b d 3 5 c d 4 6 c e 5

slide-15
SLIDE 15

NETWORK ANALYSIS IN THE TIDYVERSE

Mapping representations

# graph to matrix A <- as_adjacency_matrix(g) # matrix to graph g <- graph_from_adjacency_matrix(A) # graph to data frame df = as_data_frame(g, what = "both") # data frame to graph g <- graph_from_data_frame(df$ties, vertices = df$nodes) # matrix to data frame df = as_data_frame(graph_from_adjacency_matrix(A), what = "both") # data frame to matrix A <- as_adjacency_matrix(graph_from_data_frame(df$ties, vertices = df$nodes))

slide-16
SLIDE 16

Let's try more examples!

N E TW OR K AN ALYSIS IN TH E TIDYVE R SE