dyadic_brm | R Documentation |
This function fits a dyadic regression model (similar to QAP and MRQAP) using Bayesian inference.
dyadic_brm(formula, sampling_effort = NULL, family = "binomial", ...)
formula |
A |
sampling_effort |
A square matrix with entries representing dyadic sampling effort. The exact way that this is measured will depend on the data collection protocol (see Details). |
family |
A description of the response distribution and link function. See brm and brmsfamily for details. |
... |
Further arguments to be passed to |
Dyadic regression refers to any analysis of a network where we're interested in how dyadic predictors (e.g. similarlity in some trait) predicts the strength or presence of edges in the network. In this setting, it's reasonable to expect that there might be some dependencies in the response that basic regression doesn't deal with. Imagine if there are individual-level differences in sociality in a social network. All the edges connecting to a very social individual might therefore be higher than expected. This is often referred to as within-row correlation. Traditionally, this has been dealt with through permutation procedures, but this has its drawbacks. While statistical "significance" can be assessed this way, it doesn't help us estimate effect sizes. Furthermore, more complicated models (or even simple ones, like those with interaction effects) don't really work in these cases.
A more elegant and useful solution is to actually model the processes we're worried about. We can do this easily in a Bayesian mixed-effect model framework. Here, we model the within-row correlations as multimembership random effects; each dyad gets effects from both of the individuals involved in the dyad. This opens up all kinds of fun possibilities. We can now use interaction effects, as well as smooth terms and random effects in our dyadic regressions.
This function uses brms
to do all the heavy lifting; it is just a wrapper to quickly set up the dataset with minimal fuss. In almost all cases, this should be preferred to a permutation method (e.g. glmqap).
If sampling_effort = NULL
(the default), no variation in sampling effort is modelled. This is not recommended unless the sampling for each dyad is in fact identical.
For association indices (or any network sampled with presence/absence data), the response matrix should be the number of times the pair was observed in association (or interaction), while the number of times they could have been observed in association (the denominator of the index) should be passed to the sampling_effort
argument. For these models, it is recommended to use logit-linear familieslike family = binomial
or family = beta_binomial
.
Similarly, for interaction rate data, the number of interactions should be the response matrix, and the observation time should be passed as sampling_effort
. For these types of data, it is recommended to use log-linear count models, like family = poisson
or family = negbinomial
.
Any other type of network data (like composite indices, interaction duration, relationship types, etc.) can be used with appropriate families (see family and brmsfamily for more information). If a matrix is passed to the sampling_effort
argument while using any of these other families, the sampling effort will be treated as proportional weights for each observation, with the assumption that greater sampling effort implies higher certainty in network measurements.
The function will incorporate multi-membership random effects in the model by default. Other random effects can be passed as well (e.g. social groups), but will need to be put into square matrices first such that each dyad belongs to one grouping level. See examples.
It is also possible to incorporate smooth terms and interaction effects, exactly as they would be passed in a glm
or gam
style formula.
Remember, this is a Bayesian model, which means that we're using priors for all of our parameters. It's important to think about what reasonable priors might look like, rather than just using the defaults.
A brmsfit
object.
# a simple model with a poisson error structure; iterations set quite low for quicker model fitting. model_1 <- dyadic_brm(srkw_contact ~ srkw_kinship, family = poisson, sampling_effort = srkw_sampling, iter = 500) summary(model_1) # a model including the sum and similarity of individual ages age_sum <- sapply(srkw_attributes$age, function(z) z + srkw_attributes$age ) age_diff <- sapply(srkw_attributes$age, function(z) abs(z-srkw_attributes$age)) model_2 <- dyadic_brm(srkw_contact ~ srkw_kinship + age_sum + age_diff, family = poisson, sampling_effort = srkw_sampling, iter = 500) summary(model_2) # you can add smooth terms as well model_3 <- dyadic_brm(srkw_contact ~ srkw_kinship + age_sum + s(age_diff), family = poisson, sampling_effort = srkw_sampling, iter = 500) summary(model_3) # you can also interact different matrices; for example, if you want to see if there's an interaction between sex and age similarity same_sex <- sapply(srkw_attributes$sex, function(z) ifelse(srkw_attributes$sex == z, 1, 0) ) model_4 <- dyadic_brm(srkw_contact ~ srkw_kinship + age_diff*same_sex, family = poisson, sampling_effort = srkw_sampling, iter = 500) summary(model_4) # a model with group-level random effects, using multi-membership terms. mat_1 <- sapply(srkw_attributes$matriline, function(z) rep(z, length(srkw_attributes$matriline))) mat_2 <- t(mat_1) model_5 <- dyadic_brm(srkw_contact ~ srkw_kinship + (1|mm(mat_1,mat_2)), family = poisson, sampling_effort = srkw_sampling, iter = 500) summary(model_5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.