Lecture 15 Notes

Author

Alec L. Robitaille

Published

May 22, 2024

Social networks

Social network are patterns of directed exchange. Social networks are abstractions, not data.

Social relationships are latent variables, they cannot be directly observed but the behaviours that contribute to them can be.

Relationships are paired, eg. A to B and B to A, and either of these can motivate behaviours. These relationships don’t have to be symmetrical, eg. A may perceive their relationship with B as stronger than B does. Relationships can cause other relationships.

Network permutation

A principled approach to modeling networks requires thinking generatively about social relationships. Network permutation methods do not have a generative model underpinning their approach. They consider some null network and compare if observed networks differ from the null. See eg. Hart et al 2021.

Network uncertainty

Networks are uncertain, and, using the approach described in this lecture, the uncertainty can be retained in our downstream estimates (eg. centrality) by using the entire posterior distribution of networks, instead of reducing to a single network to calculate network metrics.

Example: Koster Leckie

Food transfers between households

coords <- data.frame(
    name = c('Ha', 'Hb', 'Gab', 'Tab', 'Tba'),
    x =    c(1,       3,     2,     2,     2),
    y =    c(0,       0,  0.25,    -1,     1)
)
dagify(
    Gab ~ Ha + Hb + Tab + Tba,
    Tba ~ Ha + Hb,
    Tab ~ Ha + Hb,
    latent = c('Tab', 'Tba'),
  coords = coords
) |> ggdag_status(seed = 2, layout = 'auto') + theme_dag()

Approach: There many backdoor paths through household features, but start with the simplest model first and scaffold your way up by adding complexity slowly.

Example: gift giving

  • Ha, Hb: household A, B
    • features of households, eg. location, wealth, etc.
  • Gab: A gives to B
  • Tab: Social tie from A to B
  • Tba: Social tie from B to A
coords <- data.frame(
    name = c('Ha', 'Hb', 'Gab', 'Tab', 'Tba'),
    x =    c(1,       3,     2,     2,     2),
    y =    c(0,       0,  0.25,    -1,     1)
)
dagify(
    Gab ~ Ha + Hb + Tab + Tba,
    Tba ~ Ha + Hb,
    Tab ~ Ha + Hb,
    latent = c('Tab', 'Tba'),
  coords = coords
) |> ggdag_status(seed = 2, layout = 'auto') + theme_dag()

Generative model without backdoor paths

coords <- data.frame(
    name = c('Ha', 'Hb', 'Gab', 'Tab', 'Tba'),
    x =    c(1,       3,     2,     2,     2),
    y =    c(0,       0,  0.25,    -1,     1)
)
dagify(
    Gab ~ Tab + Tba,
    Tba ~ Ha + Hb,
    Tab ~ Ha + Hb,
    latent = c('Tab', 'Tba'),
  coords = coords
) |> ggdag_status(seed = 2, layout = 'auto') + theme_dag()

# Number of households
N <- 25

# Set up dyads
combs <- CJ(left = seq.int(N), right = seq.int(N))
dyads <- combs[left != right]
dyad_id(dyads, 'left', 'right')
Key: <left, right>
      left right dyadID
     <int> <int> <char>
  1:     1     2    1-2
  2:     1     3    1-3
  3:     1     4    1-4
  4:     1     5    1-5
  5:     1     6    1-6
 ---                   
596:    25    20  20-25
597:    25    21  21-25
598:    25    22  22-25
599:    25    23  23-25
600:    25    24  24-25
# Simulate friendships
dyads[, f := rbern(1, 0.1), by = dyadID]

# Simulate directed ties (in observed data, this is a latent variable)
# - alpha is the base rate of the ties, where inv_logit(-3) = 0.04743
alpha <- -3
# - probability of the tie is 1 if friends, and base rate if not
dyads[, p_tie := f + (1 - f) * inv_logit(alpha)]
# - tie between left and right
dyads[, y := rbern(.N, prob = p_tie)]

# Gifts
lambda <- log(c(0.5, 2))
gifts <- dyads[, n_gift := rpois(.N, exp(lambda[1 + y]))]

The known social relationships are shown here, but other than in a generative simulation, these relationships are latent and can’t be truly known - only estimated from behaviours.


Attaching package: 'igraph'
The following object is masked from 'package:modelr':

    permute
The following objects are masked from 'package:rethinking':

    compare, normalize
The following object is masked from 'package:posterior':

    E
The following object is masked from 'package:dagitty':

    edges
The following objects are masked from 'package:stats':

    decompose, spectrum
The following object is masked from 'package:base':

    union
g <- graph_from_data_frame(dyads[f == 1])
plot(g)

Statistical model without backdoor paths

\[G_{AB} \sim Poisson(\lambda_{AB})\]

\[log(\lambda_{AB}) = \alpha + T_{AB}\]

  • Gift giving is a count, modeled using a Poisson
  • \(\alpha\) is the average rate of gift giving, independent of social ties
  • \(T_{AB}\) is the tie between A and B

We also include the relationships from the opposite directions

\[G_{BA} \sim Poisson(\lambda_{BA})\]

\[log(\lambda_{BA}) = \alpha + T_{BA}\]

  • \(T_{BA}\) is the tie between B and A

\[\begin{pmatrix}P \\ B \end{pmatrix} \sim MVNormal \begin{pmatrix} \begin{bmatrix}0 \\ 0\end{bmatrix}, \begin{bmatrix} \sigma^{2}, \rho\sigma^{2} \\ \rho\sigma^{2}, \sigma^{2}\end{bmatrix}\end{pmatrix}\]

  • \(\rho\sigma^{2}\) is the covariance within dyads
  • \(\sigma^{2}\) is the variance among ties
  • the covariance matrix is symmetric, so there is only one standard deviation (this is a simpler covariance matrix than the generalized ones from L14)

\[\rho \sim LKJCorr(2)\]

\[\sigma \sim Exponential(1)\]

\[\alpha \sim Normal(0, 1)\]

This is a model with partial pooling for network ties.

More details on this model in the textbook section 14.4.

At the moment (2024), the {brms} package can’t be used to fit these kinds of models. Here is a first go at using the {STRAND} package for fitting the simulated gift giving network.

conflicted::conflicts_prefer(STRAND::rmvnorm)
[conflicted] Will prefer STRAND::rmvnorm over any other package.
mat <- as.matrix(dcast(gifts, left ~ right, value.var = 'n_gift')[, -1])
mat[is.na(mat)] <- 0
dimnames(mat) <- list(colnames(mat), colnames(mat))
outcome <- list(mat)

dat <- make_strand_data(
    outcome = outcome,
    block_covariates = NULL,
    individual_covariates = NULL,
    dyadic_covariates = NULL,
    outcome_mode = "poisson",
    exposure = NULL
)

m <- fit_social_relations_model(
    data = dat,
    focal_regression = ~ 1,
    target_regression = ~ 1,
    dyad_regression = ~ 1,
    stan_mcmc_parameters = list(chains = 4)
)
Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 2 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 4 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 1 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 3 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 4 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 2 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 1 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 4 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 2 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 3 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 1 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 4 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 2 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 3 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 1 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 2 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 4 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 1 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 4 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 2 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 2 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 4 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 3 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 1 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 2 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 4 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 1 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 3 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 2 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 4 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 1 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 3 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 2 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 1 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 2 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 3 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 4 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 1 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 2 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 3 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 4 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 1 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 2 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 1 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 3 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 4 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 2 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 1 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 2 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 1 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 3 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 4 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 2 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 1 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 3 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 4 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 2 finished in 7.9 seconds.
Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 1 finished in 8.1 seconds.
Chain 4 finished in 8.1 seconds.
Chain 3 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 3 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 9.0 seconds.

All 4 chains finished successfully.
Mean chain execution time: 8.3 seconds.
Total execution time: 9.1 seconds.
sum_m <- data.table(summarize_strand_results(m)$summary)
$`Focal effects: Out-degree`
     Variable           Median  HPDI:0.05 HPDI:0.95 Mean    SD     
[1,] "focal effects sd" "0.097" "0"       "0.217"   "0.109" "0.077"

$`Target effects: In-degree`
     Variable            Median  HPDI:0.05 HPDI:0.95 Mean    SD     
[1,] "target effects sd" "0.122" "0.001"   "0.242"   "0.129" "0.082"

$`Dyadic effects`
     Variable            Median  HPDI:0.05 HPDI:0.95 Mean    SD     
[1,] "dyadic effects sd" "0.625" "0.493"   "0.764"   "0.625" "0.083"

$`Other estimates`
     Variable                                            Median   HPDI:0.05
[1,] "focal-target effects rho (generalized recipocity)" "0.083"  "-0.563" 
[2,] "dyadic effects rho (dyadic recipocity)"            "0.522"  "0.218"  
[3,] "intercept, any to any"                             "-0.489" "-0.623" 
     HPDI:0.95 Mean     SD     
[1,] "0.723"   "0.071"  "0.396"
[2,] "0.856"   "0.51"   "0.198"
[3,] "-0.35"   "-0.491" "0.085"
sum_m[, colnames(sum_m)[-1] := lapply(.SD,  as.numeric), 
            .SDcols = colnames(sum_m)[-1]]

ggplot(data = sum_m) + 
    geom_segment(aes(y = Variable, x = `HPDI:0.05`, xend = `HPDI:0.95`)) +
    geom_point(aes(y = Variable, x = Mean)) +
    geom_vline(xintercept = 0, alpha = 0.2) + 
    expand_limits(x = 0) +
    labs(y = '', x = 'HPDI 0.05-0.95') + 
    theme_bw()

Generative model with wealth considered

coords <- data.frame(
    name = c('Ha', 'Hb', 'Gab', 'Tab', 'Tba'),
    x =    c(1,       3,     2,     2,     2),
    y =    c(0,       0,  0.25,    -1,     1)
)
dagify(
    Gab ~ Tab + Tba + Ha + Hb,
    Tba ~ Ha + Hb,
    Tab ~ Ha + Hb,
    latent = c('Tab', 'Tba'),
  coords = coords
) |> ggdag_status(seed = 2, layout = 'auto') + theme_dag()

# Number of households
N <- 25

# Set up dyads
combs <- CJ(left = seq.int(N), right = seq.int(N))
dyads <- combs[left != right]
dyad_id(dyads, 'left', 'right')
Key: <left, right>
      left right dyadID
     <int> <int> <char>
  1:     1     2    1-2
  2:     1     3    1-3
  3:     1     4    1-4
  4:     1     5    1-5
  5:     1     6    1-6
 ---                   
596:    25    20  20-25
597:    25    21  21-25
598:    25    22  22-25
599:    25    23  23-25
600:    25    24  24-25
# Simulate friendships
dyads[, f := rbern(1, 0.1), by = dyadID]

# Simulate wealth
wealth_key <- dyads[, .(id = unique(c(left, right)))][, wealth := rnorm(.N)]
dyads[wealth_key, left_wealth := wealth, on = .(left == id)]
dyads[wealth_key, right_wealth := wealth, on = .(right == id)]

# Simulate directed ties
# - alpha is the base rate of the ties, where inv_logit(-3) = 0.04743
alpha <- -3
# - probability of the tie if 1 if friends, and base rate if not
dyads[, p_tie := f + (1 - f) * inv_logit(alpha)]
# - tie between left and right
dyads[, y := rbern(.N, prob = p_tie)]

# Gifts
bWG <- 0.5
bWR <- -1
lambda <- log(c(0.5, 2))
gifts <- dyads[, n_gift := rpois(
    .N, exp(lambda[1 + y] + bWG * left_wealth +  bWR * right_wealth)
)]

Statistical model with wealth considered

We also add generalized giving and receiving variables to account for households that may, disregarding reciprocity, receive/give more frequently.

Again, a first go using the {STRAND} package.

mat <- as.matrix(dcast(gifts, left ~ right, value.var = 'n_gift')[, -1])
mat[is.na(mat)] <- 0
dimnames(mat) <- list(colnames(mat), colnames(mat))
outcome <- list(mat)

dat <- make_strand_data(
    outcome = outcome,
    block_covariates = NULL,
    individual_covariates = unique(dyads[, .(id = left, wealth = left_wealth)]),
    dyadic_covariates = NULL,
    outcome_mode = "poisson",
    exposure = NULL
)

m <- fit_social_relations_model(
    data = dat,
    focal_regression = ~ wealth,
    target_regression = ~ wealth,
    dyad_regression = ~ 1,
    stan_mcmc_parameters = list(chains = 4)
)
Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1 
Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 
Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 
Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 94, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: lkj_corr_cholesky_lpdf: Random variable[2] is 0, but must be positive! (in '/tmp/RtmpYKF0w6/model-a904533e4e0b.stan', line 80, column 4 to column 43)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 
Chain 2 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 3 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 4 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 1 Iteration:  100 / 2000 [  5%]  (Warmup) 
Chain 2 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 4 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 1 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 3 Iteration:  200 / 2000 [ 10%]  (Warmup) 
Chain 2 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 4 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 1 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 2 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 3 Iteration:  300 / 2000 [ 15%]  (Warmup) 
Chain 4 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 1 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 3 Iteration:  400 / 2000 [ 20%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 2 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 1 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 4 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 2 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 3 Iteration:  600 / 2000 [ 30%]  (Warmup) 
Chain 1 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 4 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 2 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 3 Iteration:  700 / 2000 [ 35%]  (Warmup) 
Chain 1 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 4 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 2 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 3 Iteration:  800 / 2000 [ 40%]  (Warmup) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration:  900 / 2000 [ 45%]  (Warmup) 
Chain 4 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 2 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 1 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 2 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 3 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
Chain 1 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 4 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 2 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 3 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
Chain 4 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 1 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 2 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 3 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 1 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
Chain 4 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 2 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 1 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 2 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 3 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
Chain 4 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 1 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 2 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 3 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
Chain 4 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 1 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 2 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 3 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 finished in 8.3 seconds.
Chain 1 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 2 finished in 8.5 seconds.
Chain 3 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 1 finished in 8.9 seconds.
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 9.0 seconds.

All 4 chains finished successfully.
Mean chain execution time: 8.6 seconds.
Total execution time: 9.1 seconds.
sum_m <- data.table(summarize_strand_results(m)$summary)
$`Focal effects: Out-degree`
     Variable                                    Median  HPDI:0.05 HPDI:0.95
[1,] "focal effects sd"                          "0.112" "0"       "0.225"  
[2,] "focal effects coeffs (out-degree), wealth" "0.506" "0.39"    "0.617"  
     Mean    SD     
[1,] "0.12"  "0.076"
[2,] "0.506" "0.07" 

$`Target effects: In-degree`
     Variable                                    Median   HPDI:0.05 HPDI:0.95
[1,] "target effects sd"                         "0.067"  "0"       "0.162"  
[2,] "target effects coeffs (in-degree), wealth" "-1.049" "-1.154"  "-0.944" 
     Mean    SD     
[1,] "0.08"  "0.06" 
[2,] "-1.05" "0.065"

$`Dyadic effects`
     Variable            Median  HPDI:0.05 HPDI:0.95 Mean    SD     
[1,] "dyadic effects sd" "0.603" "0.509"   "0.709"   "0.605" "0.061"

$`Other estimates`
     Variable                                            Median   HPDI:0.05
[1,] "focal-target effects rho (generalized recipocity)" "0.096"  "-0.625" 
[2,] "dyadic effects rho (dyadic recipocity)"            "0.571"  "0.235"  
[3,] "intercept, any to any"                             "-0.484" "-0.616" 
     HPDI:0.95 Mean     SD     
[1,] "0.709"   "0.082"  "0.411"
[2,] "0.896"   "0.551"  "0.207"
[3,] "-0.345"  "-0.486" "0.083"
sum_m[, colnames(sum_m)[-1] := lapply(.SD,  as.numeric), 
            .SDcols = colnames(sum_m)[-1]]

ggplot(data = sum_m) + 
    geom_segment(aes(y = Variable, x = `HPDI:0.05`, xend = `HPDI:0.95`)) +
    geom_point(aes(y = Variable, x = Mean)) +
    geom_vline(xintercept = 0, alpha = 0.2) + 
    expand_limits(x = 0) +
    labs(y = '', x = 'HPDI 0.05-0.95') + 
    theme_bw()

Note the two new parameters, target and focal coefficients (in degree and out degree), wealth.

Statistical model with generalized household traits

\[G_{AB} \sim Poisson(\lambda_{AB})\] \[log(\lambda_{AB}) = \alpha + \texttt{T}_{AB} + \texttt{G}_{A} + \texttt{R}_{B}\]

We have linear models for the tie strength with \(T_{AB}\) representing a varying effect and \(\beta_{A}A_{AB}\) representing the effect of the association between A and B.

\[\texttt{T}_{AB} = T_{AB} + \beta_{A}A_{AB}\]

And we have linear models for giving with \(G_{A}\) representing a varying effect and \(\beta_{W,G}W_{A}\) representing the effect of A’s wealth on giving.

\[\texttt{G}_{A} = G_{A} + \beta_{W,G}W_{A}\]

And we have linear models for receiving with \(R_{B}\) representing a varying effect and \(\beta_{W,R}W_{B}\) representing the effect of B’s wealth on receiving.

\[\texttt{R}_{B} = G_{B} + \beta_{W,R}W_{B}\] These three linear models are symmetrical, so we include them again with directions inverted:

\[G_{BA} \sim Poisson(\lambda_{BA})\] \[log(\lambda_{BA}) = \alpha + \texttt{T}_{BA} + \texttt{G}_{B} + \texttt{R}_{A}\] \[\texttt{T}_{BA} = T_{BA} + \beta_{B}B_{BA}\] \[\texttt{G}_{B} = G_{B} + \beta_{W,G}W_{B}\] \[\texttt{R}_{A} = G_{A} + \beta_{W,R}W_{A}\]

\[\begin{pmatrix}P \\ B \end{pmatrix} \sim MVNormal \begin{pmatrix} \begin{bmatrix}0 \\ 0\end{bmatrix}, \begin{bmatrix} \sigma^{2}, \rho\sigma^{2} \\ \rho\sigma^{2}, \sigma^{2}\end{bmatrix}\end{pmatrix}\]

\[\rho \sim LKJCorr(2)\]

\[\sigma \sim Exponential(1)\]

\[\alpha \sim Normal(0, 1)\]

Additional structures: triangles

Relationships tend to come in triangles, termed triangle closures.

coords <- data.frame(
    name = c('A', 'B', 'C'),
    x =    c(1, 3, 2),
    y =    c(1, 1, 0)
)
dagify(
    A ~ B + C,
    B ~ C + A,
    C ~ A + B,
  coords = coords
) |> ggdag(seed = 2, layout = 'auto') + theme_dag()

Lots of generative reasons why this might occur, eg.

  • Block models where ties are more common within certain groups eg. families, groups, etc
  • Relationships cause relationships eg. A friends with B and C, B and C meet through A and and become friends

For example, Ka and Kb represent the block membership for individuals A, B respectively.

coords <- data.frame(
    name = c('Ha', 'Hb', 'Gab', 'Tab', 'Tba', 'Ka', 'Kb'),
    x =    c(1,       3,     2,     2,     2,    0,    4),
    y =    c(0,       0,  0.25,    -1,     1,    0,    0)
)
dagify(
    Gab ~ Ha + Hb + Tab + Tba,
    Tba ~ Ha + Hb + Ka + Kb,
    Tab ~ Ha + Hb + Ka + Kb,
    latent = c('Tab', 'Tba'),
  coords = coords
) |> ggdag(seed = 2, layout = 'auto') + theme_dag()

Bonus: constructed variables

Folk tradition of building outcome variables as a back-alley form of “control”: ratios, differences, transformations.

  • BMI
  • ratios/rates eg. per capita, per unit time
  • differences eg. change scores, difference from reference

Arithmetic is not stratification. It assumes a fixed relationship, which you should instead be estimating it. It also ignores uncertainty.

Do not use model predictions as data. (Stats on stats).

Use causal logic, justify, test. Model what you measure.

Example: dividing GDP by population

Outcome variable log GDP per capita. Ratio assumes the effect of population on GDP is linear. “we do not include population density since dependent variable is already in per capita terms” - dividing is not way to control for a variable.

coords <- data.frame(
    name = c('P', 'per', 'GDP', 'X'),
    x =    c(0,   0,     1,      1),
    y =    c(1,   0,     0,      1)
)
dagify(
    per ~ P + GDP,
    GDP ~ P + X,
    X ~ P,
  coords = coords
) |> ggdag(seed = 2, layout = 'auto') + theme_dag()

  • “per” represents GPD / P (GDP per capita)
  • dividing does not stratify GDP by P
  • the division implies the arrow between P and GDP
  • the backdoor path from the variable X through P is not closed by dividing by P

Example: per unit time

  • T is observation time
  • Y is number of observed transfers
  • X is cause of interest
  • per is Y / T
coords <- data.frame(
    name = c('T', 'per', 'Y', 'X'),
    x =    c(0,   0,     1,      1),
    y =    c(1,   0,     0,      1)
)
dagify(
    per ~ T + Y,
    Y ~ T + X,
  coords = coords
) |> ggdag(seed = 2, layout = 'auto') + theme_dag()

Problem: attempting to correct for observation differences in sampling across units, eg. number contacts across time for individuals with varying sample rates, by dividing by the number of observations.

See section 11.2.3 on Poisson regression for including exposure to account for differences in sampling.

The number of observations over time is not the true rate, we should be
estimating them since they are a latent variable. When T is larger, precision increases, and when T is smaller, precision decreases. Units with the smallest sampling effort have overweighted contributions to estimates.

Example: change score

  • H0 is baseline height
  • H1 is post-treatment height
  • X is cause of interest
  • delta is H1 - H0, change score
coords <- data.frame(
    name = c('H0', 'delta', 'H1', 'X'),
    x =    c(0,   0,     1,      1),
    y =    c(1,   0,     0,      1)
)
dagify(
    delta ~ H0 + H1,
    H1 ~ H0 + X,
  coords = coords
) |> ggdag(seed = 2, layout = 'auto') + theme_dag()

Modeling the change score implies there is a linear relationship. If there are any floor/ceiling effects, eg. max observable height, then the linear assumption is not held.