fit_latent_network_model: A function to run latent network models using the STRAND...

View source: R/fit_latent_network_model.R

fit_latent_network_modelR Documentation

A function to run latent network models using the STRAND framework

Description

This function allows users to analyse empirical or simulated data using a Bayesian latent network model in Stan. The user must supply a STRAND data object, and a series of formulas following standard lm() style syntax.

Usage

fit_latent_network_model(
  data,
  fpr_regression,
  rtt_regression,
  theta_regression,
  block_regression,
  focal_regression,
  target_regression,
  dyad_regression,
  mode = "mcmc",
  return_predicted_network = FALSE,
  stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1,
    iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL),
  priors = NULL
)

Arguments

data

A data object of class STRAND, prepared using the make_strand_data() function. The data object must include all covariates used in the formulas listed below.

fpr_regression

A formula for the predictors of false positive rate. Specified as in lm(), e.g.: ~ Age + Education

rtt_regression

A formula for the predictors of the recall rate of true ties. Specified as in lm(), e.g.: ~ Age + Education

theta_regression

A formula for the predictors of theta, the probability that a given individual duplicates a response from layer 1 into layer 2. Specified as in lm(), e.g.: ~ 1

block_regression

A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.

focal_regression

A formula for the predictors of out-degree (i.e., focal effects, or the effects of individual covariates on outgoing ties). This should be specified as in lm(), e.g.: ~ Age * Education

target_regression

A formula for the predictors of in-degree (i.e., target effects, or the effects of individual covariates on incoming ties). This should be specified as in lm(), e.g.: ~ Age * Education

dyad_regression

A formula for the predictors of dyadic relationships. This should be specified as in lm(),, e.g.: ~ Kinship + Friendship

mode

A string giving the mode stan should use to fit the model. "mcmc" is default and recommended, and STRAND has functions to make processing the mcmc samples easier. Other options are "optim", to use the optimizer provided by Stan, and "vb" to run the variational inference routine provided by Stan. "optim" and "vb" are fast and can be used for test runs. To process their output, however, users must be familar with [cmdstanr](https://mc-stan.org/users/interfaces/cmdstan). We recommmend that users refer to the [Stan user manual](https://mc-stan.org/users/documentation/) for more information about the different modes that Stan can use.

return_predicted_network

Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.

stan_mcmc_parameters

A list of Stan parameters that often need to be tuned. Defaults set to: list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL) We recommend 1000 sampling and warmup iterations on a single chain for exploratory model fitting. For final runs, we recommend running 2 to 4 chains for twice as long. Be sure to check r_hat, effective sample size, and traceplots.

priors

A labeled list of priors for the model. Only edits of the values are permitted. Distributions are fixed.

Details

It is important to note that all individuals' block (or group) assignment must be supplied as data. Latent groups will be supported in future releases of STRAND.

Value

A STRAND model object containing the data used, and the Stan results.

Examples

## Not run: 
fit = fit_latent_network_model(data=model_dat,
                               fpr_regression = ~ Age + Education,
                               rtt_regression = ~ Age + Education,
                               theta_regression = ~ 1,
                               block_regression = ~ Ethnicity,
                               focal_regression = ~ Age * NoFood,
                               target_regression = ~ Age * NoFood,
                               dyad_regression = ~ Relatedness + Friends * SameSex,
                               mode="mcmc",
                               stan_mcmc_parameters = list(seed = 1, chains = 1, 
                                 parallel_chains = 1, 
                                 refresh = 1, iter_warmup = 100, iter_sampling = 100,
                                 max_treedepth = NULL, adapt_delta = NULL)
                               )

## End(Not run)


ctross/STRAND documentation built on Nov. 14, 2024, 11:50 p.m.