brief intro - basic functionsacaimo.github.io/bergm/0_bergm_intro.pdf · brief intro - basic...

15
Brief Intro - Basic functions Alberto Caimo acaimo.github.io

Upload: others

Post on 15-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Brief Intro - Basic functions

Alberto Caimoacaimo.github.io

Page 2: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Definitions and notation

I Networks are generally represented by graphs of nodes (actors)and edges (relations)

I N number of nodes (fixed)

I Y random N ×N adjacency matrix where:I Yij = 1, if i and j are connectedI Yij = 0, if i and j are not connected

I y realisation of Y

(or edge) between node i and node j:

yij =

⎧⎨⎩

1 if there is a link between node i and node j

0 otherwise

Two nodes are called adjacent if there is an link between them. If yij = yji then the

adjacency matrix is symmetric and the network is called undirected, otherwise it is called

directed (Figure 1.1). Self-links (yii = 1) are generally not allowed in many applications

and will not be considered in this thesis.

⎛⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎝

0 1 0 1 0 1

1 0 0 1 1 1

0 0 0 0 1 1

1 1 0 0 0 0

0 1 1 0 0 0

1 1 1 0 0 0

⎞⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎠

Binary symmetric

1

23 4

5

6

Undirected network

⎛⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎝

0 0 0 1 0 1

0 0 1 0 0 0

1 0 0 0 0 0

0 0 1 0 1 1

0 1 0 1 0 0

0 0 0 0 0 0

⎞⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎠

Binary asymmetric

1

2

3

4

5

6

Directed network

Figure 1.1: Undirected (top) and directed (bottom) networks

Two-mode networks are particular networks in which the sender nodes and the receiver

nodes belong to two separates sets (Figure 1.2). The adjacency matrix of a two-mode

networks is an (N × M) matrix, where N is the number of sender nodes and M the

number of receiver nodes.

An example of two-mode network is the U.S. Congressional Voting (Congressional

Quarterly Almanac, 1984) presented in Section 5.7.2. The sender nodes are represented by

the 435 House of Representatives congressmen who voted on 16 issues which are considered

the receiver nodes.

Two-mode networks can be analyzed using methods for multivariate data (eg. latent

2

Page 3: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Exponential random graph models (ERGMs)

Basic assumptions

I The observed network y is generated by a stochastic process inwhich edges are created because of the presence or absence ofother edges.

I Local effects are represented by network statistics s(y) thatgenerate dyadic relations and may depend on the surroundingenvironment.

For example:

I Similar attributes are generally more likely to form friendshipedges (homophily)

I Two nodes connected to a third node are likely to form an edgebetween them (clustering)

Page 4: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Exponential random graph models (ERGMs)

Definition

Pr(Y = y) =exp{θT s(y)}

c(θ)

I Describe the probability of y as a function of the parameter θ;

I s(y) is a vector of network statistics (e.g. number of edges,number of triangles, etc.) associated to effects of interest;

I θ is the vector of parameters associated to the network statisticss(y);

I c(θ) is a normalising constant which is intractable for nottrivially small networks.

Page 5: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Bayesian inference for ERGMs with Bergm

Bayesian inference for ERGMs is based on the posterior distributionof θ given the data y:

p(θ|y) =exp{θts(y)}

c(θ)

p(θ)

p(y),

where:

I p(θ) is the prior distribution of the parameter

I p(y) is the marginal likelihood of y which is typicallyintractable.

Page 6: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Bayesian inference for ERGMs with Bergm

I Bergm is an R package which provides a comprehensiveframework for Bayesian estimation and model adequacy forERGMs using advanced Monte Carlo algorithms (see, e.g., Caimoand Friel, 2011).

I Bergm is based on the statnet suite of packages (Handcock et al.,2007) and makes use of the same model set-up and networksimulation procedures.

Page 7: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

The Bergm package

Main functions

I bergm(): function to fit Bayesian exponential random graphsmodels using the approximate exchange algorithm

I bergm.output(): function to return the posterior parameterdensity estimate and creates simple diagnostic plots for theMCMC produced from a fit.

I bgof(): function to calculate summaries for degree, minimumgeodesic distances, and edgewise shared partner distributions todiagnose Bayesian goodness-of-fit.

Page 8: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

library(statnet)data(zach) # 34 interacting members of a karate cluby <- zachplot(y, vertex.col = "skyblue", vertex.cex = 2)

Page 9: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

ERGM specification:

Pr(Y = y) ∝ exp{θ1 edges(y) + θ2 gwdegree(y) + θ3 gwesp(y)}

edges degrees edgewise shared partners

library(Bergm)

model <- y ˜ edges +gwdegree(0.2, fixed = TRUE) +gwesp(0.2, fixed = TRUE)

Page 10: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

Prior specification:

I vague normal prior distribution with no correlation between theparameters;

I we assume low density of the network: θ1 < 0;

So, for example:

θ ∼ N

−200

,

5 0 00 5 00 0 5

mean.prior <- c(-2, 0, 0)sigma.prior <- diag(5, 3)

Page 11: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

The approximate exchange algorithm (bergm() function):

for main.iters× n.chains iterations:

1. simulate θ′ from ε(·|θ, gamma)

2. simulate y′ from f(·|θ′) using aux.iters iterations

3. update θ → θ′ with the log of the probability:

min

(0, [θ − θ′]t [s(y′)− s(y)] + log

p(θ′)

p(θ)

)

end for

Page 12: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!posterior <- bergm(

model,main.iters = 1500,n.chains = 6, # 6×1.5k = 9k iterationsaux.iters = 3000, # for network simulationgamma = 0.9, # tuned to get ∼20% acceptance ratemean.prior = mean.prior,sigma.prior = sigma.prior)

bergm.output(posterior)

## Posterior Density Estimate for Model:## y ˜ edges + gwdegree(0.2, fixed = TRUE) + gwesp(0.2, fixed = TRUE)#### Mean SD Naive SE Time-series SE## theta1 (edges) -3.810812 0.3650827 0.003848309 0.01942382## theta2 (gwdegree) 5.169665 3.0124907 0.031754440 0.16939821## theta3 (gwesp) 1.347093 0.2483486 0.002617824 0.01265695#### 2.5% 25% 50% 75% 97.5%## theta1 (edges) -4.501821 -4.053643 -3.811498 -3.565977 -3.107281## theta2 (gwdegree) 0.913240 2.875273 4.633890 7.005652 12.135357## theta3 (gwesp) 0.874649 1.178549 1.353660 1.514104 1.830226#### Acceptance rate: 0.201

Page 13: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

θ1 (edges)

-5.5 -4.5 -3.5 -2.5

0.0

0.4

0.8

1.2

0 2000 4000 6000 8000

-5.0

-4.0

-3.0

Iterations

0 10 20 30 40

-1.0

-0.5

0.0

0.5

1.0

Lag

Autocorrelation

θ2 (gwdegree)

0 5 10 15 20

0.00

0.04

0.08

0.12

0 2000 4000 6000 8000

05

1015

20

Iterations

0 10 20 30 40

-1.0

-0.5

0.0

0.5

1.0

Lag

Autocorrelation

θ3 (gwesp.fixed.0.2)

0.5 1.0 1.5 2.0 2.5

0.0

0.5

1.0

1.5

0 2000 4000 6000 8000

0.5

1.0

1.5

2.0

Iterations

0 10 20 30 40

-1.0

-0.5

0.0

0.5

1.0

Lag

Autocorrelation

MCMC output for Model: y ~ edges + gwdegree(0.2, fixed = TRUE) + gwesp(0.2, fixed = TRUE)

Page 14: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

Bayesian GoF diagnostics (bgof() function):

1. Draws sample.size parameters {θ1, θ2, · · · } from the estimatedposterior

2. Simulate networks {y1, y2, · · · } from each {θ1, θ2, · · · } usingaux.iters iterations

3. Compare some network statistics distributions of the {y1, y2, · · · }to the observed network y

Page 15: Brief Intro - Basic functionsacaimo.github.io/Bergm/0_Bergm_Intro.pdf · Brief Intro - Basic functions Alberto Caimo acaimo.github.io. De nitions and notation I Networks are generally

Example - Bergm in action!

bgof(posterior, sample.size = 100, aux.iters = 3000,n.deg = 18, n.dist = 10, n.esp = 8)

0.0

0.1

0.2

0.3

degree

prop

ortio

n of

nod

es

0 2 4 6 8 10 13 16

Bayesian goodness-of-fit diagnostics

0.0

0.1

0.2

0.3

0.4

0.5

minimum geodesic distance

prop

ortio

n of

dya

ds

1 2 3 4 5 6 7 8 90.0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

edge-wise shared partners

prop

ortio

n of

edg

es0 1 2 3 4 5 6 7