(lecture_15)=

Social Networks

:::{post} Jan 7, 2024 :tags: statistical rethinking, bayesian inference, social networks :category: intermediate :author: Dustin Stansbury :::

This notebook is part of the PyMC port of the Statistical Rethinking 2023 lecture series by Richard McElreath.

Video - Lecture 15 - Social Networks# Lecture 15 - Social Networks

What Motivates Sharing?

Koster & Leckie (2014) Arang Dak dataset

  • year of food transfers between 25 households
  • 300 dyads, i.e. $\binom{25}{2} = 300$
  • 2871 observations of food transfers ("gifts")

Scientific Questions: Estimand(s)

  • How much sharing is explained by reciprocity?
  • How much by generalized giving?

Improve analysis with a causal graph

Social Network Analysis

  • $T_{AB}$ and $T_{BA}$ are not observable
  • Social network is Pattern of direct exchange
  • Social network is an abstraction, not data
  • what's a principled approach?
    • bad approach -> Null network analysis
      • no correct way to permute
      • we care about causality, not testing a null hypothesis

Drawing the Social Owl 🦉

  1. Estimand(s): Reciprocity & what explains it
  2. Generative model
  3. Statistical model
  4. Analyze data

We'll loop between 2 and 3 often as we build the complexity of our model

1) Estimand

Starting Simpler, ignoring household effects for now

At first, we'll ignore the backdoor paths to get a good flow, and get the model running, then add them in later

2) Generative Model

Simulating a Social Network

Simulate Gift-giving from social net

3) Statistical Model

Likelihood

GABPoisson(λAB)GBAPoisson(λBA)log(λAB)=α+TABlog(λBA)=α+TBA\begin{align*} G_{AB} &\sim \text{Poisson}(\lambda_{AB}) \\ G_{BA} &\sim \text{Poisson}(\lambda_{BA}) \\ \log(\lambda_{AB}) &= \alpha + T_{AB} \\ \log(\lambda_{BA}) &= \alpha + T_{BA} \\ \end{align*}

Global gift-giving prior

αNormal(0,1)\alpha \sim \text{Normal}(0, 1) \\

Correlated Social Ties prior

(TABTBA)=MVNormal([00],[σ2ρσ2ρσ2σ2])ρLKJCorr(η)σExponential(1)\begin{align*} \begin{pmatrix} T_{AB} \\ T_{BA} \end{pmatrix} &= \text{MVNormal} \left( \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \begin{bmatrix} \sigma^2 & \rho \sigma^2 \\ \rho \sigma^2 & \sigma^2 \end{bmatrix} \right) \\ \rho &\sim \text{LKJCorr}(\eta) \\ \sigma &\sim \text{Exponential}(1) \end{align*}
  • Symmetric Likelihood
  • Global intercept, but tie-specific offset
  • We model the (symmetric) correlation between social $T_{AB}, T_{BA}$
  • Priors give us partial pooling, allowing us to share information from ties that have a lot of activity to those ties that have less activity

Fitting the social ties model

Notes
  • We use LKJCholeskyCov instead of LKJCorr for numerical stability/efficiency

Posterior Ties

4) Analyze Data

Run the model on the real data samples

Posterior correlation

Introducing Household Giving/Receiving Confounds

2) Generative Model

Simulate Including Unmeasured Household Wealth

We use the same social ties network, but augment gift-giving behavior based on (unmeasured) household wealth:

  • Wealthier households give more
  • Poorer households recieve more

3) Statistical Model

  • $G_{A,B}$ - househould $A,B$'s generalized giving
  • $R_{A,B}$ - househould $A,B$'s generalized receiving
  • Model Giving and Receiving covariance vian $\text{MVNormal}$

Likelihood

GABPoisson(λAB)GBAPoisson(λBA)log(λAB)=α+TAB+GA+RBlog(λBA)=α+TBA+GB+RA\begin{align*} G_{AB} &\sim \text{Poisson}(\lambda_{AB}) \\ G_{BA} &\sim \text{Poisson}(\lambda_{BA}) \\ \log(\lambda_{AB}) &= \alpha + T_{AB} + G_{A} + R_{B} \\ \log(\lambda_{BA}) &= \alpha + T_{BA} + G_{B} + R_{A} \end{align*}

Global gift-giving prior

αNormal(0,1)\alpha \sim \text{Normal}(0, 1)

Correlated Social Ties prior

(TABTBA)=MVNormal([00],[σ2ρσ2ρσ2σ2])ρLKJCorr(η)σExponential(1)\begin{align*} \begin{pmatrix} T_{AB} \\ T_{BA} \end{pmatrix} &= \text{MVNormal} \left( \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \begin{bmatrix} \sigma^2 & \rho \sigma^2 \\ \rho \sigma^2 & \sigma^2 \end{bmatrix} \right) \\ \rho &\sim \text{LKJCorr}(\eta) \\ \sigma &\sim \text{Exponential}(1) \end{align*}

Correlated Giving/Recieving prior

(GA,BRA,B)=MVNormal([00],RGR,SGR)RGRLKJCorr(η)SGRExponential(1)\begin{align*} \begin{pmatrix} G_{A,B} \\ R_{A,B} \end{pmatrix} &= \text{MVNormal} \left( \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \textbf{R}_{GR}, \textbf{S}_{GR} \right) \\ \textbf{R}_{GR} &\sim \text{LKJCorr}(\eta) \\ \textbf{S}_{GR} &\sim \text{Exponential}(1) \end{align*}

Fit Wealth Gifting model on simulated data (validation)

Fit on real data

Plot the posterior mean social graph

Posterior Mean social network from gifting model

Posterior mean social network for model that also incorporates Wealth

Reminder: Social Networks Don't Exist

  • They are abstraction for things we can't measure directly
    • if we can account for all confounds, the network becomes less useful
  • Networks models aren't point estimates (though we plot the mean below)
    • Like all other posteriors, any quantities calculated from the graph model (e.g. centrality, degree, etc) should also use distributions

Including Predictive Household features

Now we'll add predictor featurs to the model. Specifically, we'll add GLM parameters for

  • an association feature $A_{AB}$ for each diad (e.g. friendship), $\beta_A$.
  • the effect of household wealth $W_{A,B}$ on giving, $\beta_G$
  • the effect of household wealth $W_{A,B}$ on receiving, $\beta_R$

Likelihood

GABPoisson(λAB)GBAPoisson(λBA)log(λAB)=α+TAB+GA+RBlog(λBA)=α+TBA+GB+RATAB=TAB+βAAABGA=GA+βGWARB=RA+βRWB\begin{align*} G_{AB} &\sim \text{Poisson}(\lambda_{AB}) \\ G_{BA} &\sim \text{Poisson}(\lambda_{BA}) \\ \log(\lambda_{AB}) &= \alpha + \mathcal{T}_{AB} + \mathcal{G}_{A} + \mathcal{R}_{B} \\ \log(\lambda_{BA}) &= \alpha + \mathcal{T}_{BA} + \mathcal{G}_{B} + \mathcal{R}_{A} \\ \mathcal{T}_{AB} &= T_{AB} + \beta_A A_{AB} \\ \mathcal{G}_{A} &= G_{A} + \beta_G W_{A} \\ \mathcal{R}_{B} &= R_{A} + \beta_R W_{B} \end{align*}

Global priors

αNormal(0,1)βA,G,RNormal(0,1)\begin{align*} \alpha &\sim \text{Normal}(0, 1) \\ \beta_{A, G, R} &\sim \text{Normal}(0, 1) \end{align*}

Correlated Social Ties prior

(TABTBA)=MVNormal([00],[σ2ρσ2ρσ2σ2])ρLKJCorr(η)σExponential(1)\begin{align*} \begin{pmatrix} T_{AB} \\ T_{BA} \end{pmatrix} &= \text{MVNormal} \left( \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \begin{bmatrix} \sigma^2 & \rho \sigma^2 \\ \rho \sigma^2 & \sigma^2 \end{bmatrix} \right) \\ \rho &\sim \text{LKJCorr}(\eta) \\ \sigma &\sim \text{Exponential}(1) \end{align*}

Correlated Giving/Recieving prior

(GARA)=MVNormal([00],RGR,SGR)RGRLKJCorr(η)SGRExponential(1)\begin{align*} \begin{pmatrix} G_{A} \\ R_{A} \end{pmatrix} &= \text{MVNormal} \left( \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \textbf{R}_{GR}, \textbf{S}_{GR} \right) \\ \textbf{R}_{GR} &\sim \text{LKJCorr}(\eta) \\ \textbf{S}_{GR} &\sim \text{Exponential}(1) \end{align*}

Add observed confounds variables to simulated dataset

We can see that including parameters for giving and receiving reduces posterior standard deviation associated with social ties. This is expected because, we're explaining away more variance with those additional parameters.

Model coefficients

Using this model--which is highly aligned with the data simulation--we're able to recover the coefficients from the underlying generative model.

  • Association (in this case friendship) gets positive coefficient $\beta_A$. All friendship associations result in giving
  • Wealth positively affects giving, $\beta_G$
  • Wealth negatively affects receiving $\beta_R$

Model Comparison

Controlling for the correct confounds provides a better model of the data, in terms of cross-validation scores

Accounting for the confounding features makes social network abstraction less important

Giving/receiving is mostly explained by friendship and/or household wealth, so after accounting for those variables, the giving receiving dynamics defined in the dyads has less signal

Social ties become more independent when controlling for correct predictors

The x-shape in the joint is indicative of an independent set of variables. m

When accounting for confounds, a majority of the connection probabilities are around 0.5

This indicates social ties are more-or-less random after accounting for freindship and wealth

Fitting Giving-receiving Features Model to Real Data

In the lecture McElreath reports results on the real data, but given the version of the dataset I have in hand, it's somewhat unclear how to move forward.

To fit the model we need to know which columns in the real dataset are associated with

  • The association metric $A_{AB}$
  • Wealth of Household A $W_A$
  • Wealth of Household B $W_B$

Looking at the dataset, it's not entirely clear which columns we should/could associate with each of those variables to replicate the figure in lecture. That said, if we DID know those columns--or how to derive them--it would be easy to fit the model via

python

Additional Structure: Triangle Closures

  • Relationships tend to come in triads
  • Block models -- social ties are more common within a social group
    • families
    • classrooms
    • actual city blocks
  • Adds additional confounds

Posterior Network is regularized

  • Social networks try to express regularities in the observations
  • Inferred networks are regularized

Blocks and clusters are still discrete subgroups, what about "continuous clusters" like age or spatial distance? The goal of next lecture on Gaussian Processes

Comparing Gifting Observations to Model Trained on those observations

⚠️ The example below is using the simulated data

The observed gifting network is denser than the social ties network estimated from the data, indicating that the model's pooling is adding regularization (compression) to the network's of social ties.

Varying effects as technology

  • Social nets try to express regularities in observed data
  • Inferred nets are thus regularized, capturing those structured regular effects
  • What happens when clusters are not discrete?
    • Age, distance, spatial location
    • We need a way to stratify or perform local poolling by "continuous clusters"
      • This is where Gaussian Processes come in next lecture.
      • Allows us to attack problems that require phylogenic and spatial models

BONUS: Constructed Variables $\neq$ Stratification

  • Outcomes that are deterministic functions of e.g.
    • Body Mass Index: $BMI = \frac{mass}{height^2}$
    • "*per capita", "*per unit time"
    • % changes, difference from reference value
  • It's a common misunderstanding that dividing or rescaling by a variable is equivalent to controlling for that variable.
  • Causal inference can provide a means to combine variables in a more principled manner.

Example: Dividing GDP by population

  • makes the assumption that population scales GDP linearly
  • dividing by population is not equivalent to stratifying by population

it gets worse, though. In the scenario below, where we want to estimate the causal effect of $X$ on GDP/P, the fork created by $P$ isn't removed by simply calculating GDP/P

Another Example: Rates

  • Rates are often calculated as $\frac{\text{# events}}{\text{unit time}}$ and modeled as outcomes
  • Does not consider the varying precision for different amounts of time
    • assuming all Y/T has the same precision, despite larger Y generally having more time to occur, and thus having higher precision
    • collapsing to point estimates removes our ability to talk about uncertainty in rates (e.g. distributions)
    • datapoints with less time/less prcision are given as much credibility to the estimate as data with longer/better precision
  • Division by time does not control for time
  • If rates are the focus of scientific question, model the counts (e.g. Poisson regression) to estimate the rate parameter

Another Example: Difference scores

For example the plant growth experiment, where H0 and H1 are the starting and ending heights of the plant, X is the antifungal treatment.

  • difference score H1-H0 makes strong assumptions about the effect of H0 on H1, namely that
    • growth effects are constant for all starting heights
    • there is no floor or ceiling effects on plant height
  • need to model H0 on the right side of the GLM (linear regression), as it is a cause of H1. This is what we did in the plant growth example

Review: Constructed Variables are Bad

  • arithmetic is not stratification
  • implicity assume fixed functional relationships amongst causes; you should be estimating these functional relationships
  • generally ignores uncertainty
  • using residuals as new data does not control for variables; don't use in causal inference (though it is often common to do so in predictive settings)

Adhockery

  • adhoc procedures that have intuitive justifications
    • "we expect to see a correlation".
      • Why do you expect to see correlation (make assumptions explicit)?
      • Also, if you don't see a correlation, why does that mean some NULL contingent on that correlation is disproven?
  • if an adhoc procedure does work (they sometimes can be correct by chance), it needs to be justified by causal logic and testing
  • Simple rule: Model what you measure
    • don't try to model new metrics that are derived from measures

Authors

  • Ported to PyMC by Dustin Stansbury (2024)
  • Based on Statistical Rethinking (2023) lectures by Richard McElreath

:::{include} ../page_footer.md :::