├── .github └── CODEOWNERS ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── R ├── AMENDS_Data.R ├── Baboon_Data.R ├── Baboon_Longitudinal_Data.R ├── Bat_Data.R ├── CES.R ├── Callithrix_Data.R ├── Colombia_Data.R ├── FoodSharing_Data.R ├── HPDI.R ├── RICH_Data.R ├── STRAND-package.R ├── bayesian_p.R ├── build_multiplex_bindings_dr_longitudinal.R ├── build_multiplex_bindings_dr_multiplex.R ├── build_multiplex_bindings_sr_longitudinal.R ├── center.R ├── colMaxs.R ├── colMins.R ├── fit_NBDA_model.R ├── fit_block_model.R ├── fit_block_plus_social_relations_model_with_measurement_bias.R ├── fit_block_plus_social_relations_model_with_measurement_bias_missings.R ├── fit_block_plus_srm_model.R ├── fit_block_plus_srm_model_missings.R ├── fit_latent_network_model.R ├── fit_latent_network_model_missings.R ├── fit_latent_network_plus_flows_model.R ├── fit_longitudinal_model.R ├── fit_longitudinal_model_missings.R ├── fit_multiplex_model.R ├── fit_multiplex_model_missings.R ├── fit_srm_model.R ├── generate_structured_correlation_matrix.R ├── import.R ├── inv_logit.R ├── inv_logit_shifted.R ├── is_numeric_not_binary.R ├── load.R ├── logit.R ├── longitudinal_plot.R ├── longitudinal_plot_b.R ├── longitudinal_plot_c.R ├── longitudinal_plot_d.R ├── longitudinal_plot_g.R ├── make_longitudinal_data.R ├── make_longitudinal_data_missings.R ├── make_priors.R ├── make_strand_data.R ├── multiplex_plot.R ├── multiplex_plot_d.R ├── multiplex_plot_g.R ├── parse_longitudinal_data.R ├── parse_longitudinal_data_missings.R ├── plot_diffusion.R ├── process_block_parameters.R ├── process_missings.R ├── random_string.R ├── rbern.R ├── rmvnorm.R ├── rmvnorm2.R ├── run_longitudinal_checks.R ├── simulate_diffusion.R ├── simulate_longitudinal_network.R ├── simulate_multiplex_network.R ├── simulate_sbm_network.R ├── simulate_sbm_plus_srm_network.R ├── simulate_sbm_plus_srm_network_with_measurement_error.R ├── simulate_selfreport_network.R ├── simulate_srm_network.R ├── standardize.R ├── strand_VPCs.R ├── strand_caterpillar_plot.R ├── sum_stats.R ├── summarize_bm_results.R ├── summarize_bsrm_results.R ├── summarize_bsrm_results_with_measurement_bias.R ├── summarize_lnm_results.R ├── summarize_lnmf_results.R ├── summarize_longitudinal_bsrm_results.R ├── summarize_multiplex_bsrm_results.R ├── summarize_srm_results.R └── summarize_strand_results.R ├── README.md ├── data ├── AMENDS_Data.RData ├── Baboon_Data.RData ├── Baboon_Longitudinal_Data.RData ├── Bat_Data.RData ├── Callithrix_Data.RData ├── Colombia_Data.RData ├── FoodSharing_Data.RData └── RICH_Data.RData ├── inst ├── block_model.stan ├── block_plus_social_relations_model.stan ├── block_plus_social_relations_model_longitudinal.stan ├── block_plus_social_relations_model_longitudinal_missings.stan ├── block_plus_social_relations_model_longitudinal_pinkney.stan ├── block_plus_social_relations_model_longitudinal_pinkney_missings.stan ├── block_plus_social_relations_model_missings.stan ├── block_plus_social_relations_model_multiplex.stan ├── block_plus_social_relations_model_multiplex_direct.stan ├── block_plus_social_relations_model_multiplex_missings.stan ├── block_plus_social_relations_model_multiplex_pinkney.stan ├── block_plus_social_relations_model_multiplex_pinkney_missings.stan ├── block_plus_social_relations_model_with_measurement_bias.stan ├── block_plus_social_relations_model_with_measurement_bias_missings.stan ├── generate_structured_correlation_matrix_cholesky.stan ├── generate_structured_correlation_matrix_l2norm.stan ├── latent_network_model.stan ├── latent_network_model_flows.stan ├── latent_network_model_missings.stan ├── network_based_diffusion_analysis.stan └── social_relations_model.stan ├── logos ├── logo.gif ├── logo1.png ├── logo10.png ├── logo11.png ├── logo2.png ├── logo3.png ├── logo4.png ├── logo5.png ├── logo6.png ├── logo7.png ├── logo8.png └── logo9.png ├── man ├── AMENDS_Data.Rd ├── Baboon_Data.Rd ├── Baboon_Longitudinal_Data.Rd ├── Bat_Data.Rd ├── CES.Rd ├── Callithrix_Data.Rd ├── Colombia_Data.Rd ├── FoodSharing_Data.Rd ├── HPDI.Rd ├── RICH_Data.Rd ├── STRAND-package.Rd ├── STRAND.Rd ├── bayesian_p.Rd ├── build_multiplex_bindings_dr_longitudinal.Rd ├── build_multiplex_bindings_dr_multiplex.Rd ├── build_multiplex_bindings_sr_longitudinal.Rd ├── center.Rd ├── colMaxs.Rd ├── colMins.Rd ├── dot-onAttach.Rd ├── fit_NBDA_model.Rd ├── fit_block_model.Rd ├── fit_block_plus_social_relations_model.Rd ├── fit_block_plus_social_relations_model_missings.Rd ├── fit_block_plus_social_relations_model_with_measurement_bias.Rd ├── fit_block_plus_social_relations_model_with_measurement_bias_missings.Rd ├── fit_latent_network_model.Rd ├── fit_latent_network_model_missings.Rd ├── fit_latent_network_plus_flows_model.Rd ├── fit_longitudinal_model.Rd ├── fit_longitudinal_model_missings.Rd ├── fit_multiplex_model.Rd ├── fit_multiplex_model_missings.Rd ├── fit_social_relations_model.Rd ├── generate_structured_correlation_matrix.Rd ├── inv_logit.Rd ├── inv_logit_shifted.Rd ├── is_numeric_not_binary.Rd ├── logit.Rd ├── longitudinal_plot.Rd ├── longitudinal_plot_b.Rd ├── longitudinal_plot_c.Rd ├── longitudinal_plot_d.Rd ├── longitudinal_plot_g.Rd ├── make_longitudinal_data.Rd ├── make_longitudinal_data_missings.Rd ├── make_priors.Rd ├── make_strand_data.Rd ├── multiplex_plot.Rd ├── multiplex_plot_d.Rd ├── multiplex_plot_g.Rd ├── parse_longitudinal_data.Rd ├── parse_longitudinal_data_missings.Rd ├── plot_diffusion.Rd ├── process_block_parameters.Rd ├── process_missings.Rd ├── random_string.Rd ├── rbern.Rd ├── rmvnorm.Rd ├── rmvnorm2.Rd ├── run_longitudinal_checks.Rd ├── simulate_diffusion.Rd ├── simulate_longitudinal_network.Rd ├── simulate_multiplex_network.Rd ├── simulate_sbm_network.Rd ├── simulate_sbm_plus_srm_network.Rd ├── simulate_sbm_plus_srm_network_with_measurement_bias.Rd ├── simulate_selfreport_network.Rd ├── simulate_srm_network.Rd ├── standardize.Rd ├── strand_VPCs.Rd ├── strand_caterpillar_plot.Rd ├── sum_stats.Rd ├── summarize_bm_results.Rd ├── summarize_bsrm_results.Rd ├── summarize_bsrm_results_with_measurement_bias.Rd ├── summarize_lnm_results.Rd ├── summarize_lnmf_results.Rd ├── summarize_longitudinal_bsrm_results.Rd ├── summarize_multiplex_bsrm_results.Rd ├── summarize_srm_results.Rd └── summarize_strand_results.Rd └── tutorials ├── Bernoulli_Between_Level_Interaction_Example.R ├── Bernoulli_Callithrix_Example.R ├── Bernoulli_Example.R ├── Bernoulli_Example_With_Imputation.R ├── Bernoulli_Probit_v_Logit_Example.R ├── Binomial_Example.R ├── Binomial_Measurement_Error_Example.R ├── Binomial_Measurement_Error_Example_With_Imputation.R ├── ChangingPriors_Example.R ├── Gaussian_Example.R ├── Gaussian_Measurement_Example.R ├── Interaction_Example.R ├── LatentNetwork_Example.R ├── LatentNetwork_Example_With_Imputation.R ├── Longitudinal_Bernoulli_Example.R ├── Longitudinal_Bernoulli_Example_With_Imputation.R ├── Longitudinal_Binomial_Example.R ├── Longitudinal_Simulation_Example.R ├── Multiplex_Bernoulli_Example.R ├── Multiplex_Bernoulli_Example_Dyadic_Modes.R ├── Multiplex_Bernoulli_Probit_v_Logit_Example.R ├── Multiplex_Binomial_Example.R ├── Multiplex_Binomial_Simulation_Example.R ├── Multiplex_Gaussian_Simulation_Example.R ├── Multiplex_Poisson_Example_With_Imputation.R ├── Multiplex_Poisson_Simulation_Example.R ├── Network_Based_Diffusion_Analysis_Example.R ├── Poisson_Example.R ├── Probit_Measurement_Example.R └── Undirected_Example.R /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ctross 2 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: STRAND 2 | Title: An R package for simulating and analyzing social network data in R and Stan 3 | Version: 1.1.2.01 4 | Authors@R: c(person(given = "Cody", family = "Ross", email = "ctross@ucdavis.edu", role = c("aut", "cre"))) 5 | Description: An R package for simulating and analyzing social network data using full Bayesian inference in Stan. 6 | Imports: coda,cmdstanr,ggplot2,grid,posterior,utils,jsonlite 7 | URL: https://github.com/ctross/STRAND 8 | BugReports: https://github.com/ctross/STRAND/issues 9 | License: GPL-3 10 | Encoding: UTF-8 11 | LazyData: true 12 | GitHubRelease: phosphorescent_desert_buttons 13 | RoxygenNote: 7.2.3 14 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020--2025, STRAND Developers and their Assignees All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(.onAttach) 4 | export(CES) 5 | export(HPDI) 6 | export(bayesian_p) 7 | export(build_multiplex_bindings_dr_longitudinal) 8 | export(build_multiplex_bindings_dr_multiplex) 9 | export(build_multiplex_bindings_sr_longitudinal) 10 | export(center) 11 | export(colMaxs) 12 | export(colMins) 13 | export(fit_NBDA_model) 14 | export(fit_block_model) 15 | export(fit_block_plus_social_relations_model) 16 | export(fit_block_plus_social_relations_model_missings) 17 | export(fit_block_plus_social_relations_model_with_measurement_bias) 18 | export(fit_block_plus_social_relations_model_with_measurement_bias_missings) 19 | export(fit_latent_network_model) 20 | export(fit_latent_network_model_missings) 21 | export(fit_latent_network_plus_flows_model) 22 | export(fit_longitudinal_model) 23 | export(fit_longitudinal_model_missings) 24 | export(fit_multiplex_model) 25 | export(fit_multiplex_model_missings) 26 | export(fit_social_relations_model) 27 | export(generate_structured_correlation_matrix) 28 | export(inv_logit) 29 | export(inv_logit_shifted) 30 | export(is_numeric_not_binary) 31 | export(logit) 32 | export(longitudinal_plot) 33 | export(longitudinal_plot_b) 34 | export(longitudinal_plot_c) 35 | export(longitudinal_plot_d) 36 | export(longitudinal_plot_g) 37 | export(make_longitudinal_data) 38 | export(make_longitudinal_data_missings) 39 | export(make_priors) 40 | export(make_strand_data) 41 | export(multiplex_plot) 42 | export(multiplex_plot_d) 43 | export(multiplex_plot_g) 44 | export(parse_longitudinal_data) 45 | export(parse_longitudinal_data_missings) 46 | export(plot_diffusion) 47 | export(process_block_parameters) 48 | export(process_missings) 49 | export(random_string) 50 | export(rbern) 51 | export(rmvnorm) 52 | export(rmvnorm2) 53 | export(run_longitudinal_checks) 54 | export(simulate_diffusion) 55 | export(simulate_longitudinal_network) 56 | export(simulate_multiplex_network) 57 | export(simulate_sbm_network) 58 | export(simulate_sbm_plus_srm_network) 59 | export(simulate_sbm_plus_srm_network_with_measurement_bias) 60 | export(simulate_selfreport_network) 61 | export(simulate_srm_network) 62 | export(standardize) 63 | export(strand_VPCs) 64 | export(strand_caterpillar_plot) 65 | export(sum_stats) 66 | export(summarize_bm_results) 67 | export(summarize_bsrm_results) 68 | export(summarize_bsrm_results_with_measurement_bias) 69 | export(summarize_lnm_results) 70 | export(summarize_lnmf_results) 71 | export(summarize_longitudinal_bsrm_results) 72 | export(summarize_multiplex_bsrm_results) 73 | export(summarize_srm_results) 74 | export(summarize_strand_results) 75 | importFrom(grDevices,terrain.colors) 76 | importFrom(graphics,pairs) 77 | importFrom(jsonlite,read_json) 78 | importFrom(stats,complete.cases) 79 | importFrom(stats,median) 80 | importFrom(stats,model.frame) 81 | importFrom(stats,model.matrix) 82 | importFrom(stats,na.omit) 83 | importFrom(stats,na.pass) 84 | importFrom(stats,pnorm) 85 | importFrom(stats,rbeta) 86 | importFrom(stats,rbinom) 87 | importFrom(stats,rnorm) 88 | importFrom(stats,rpois) 89 | importFrom(stats,sd) 90 | importFrom(utils,download.file) 91 | -------------------------------------------------------------------------------- /R/AMENDS_Data.R: -------------------------------------------------------------------------------- 1 | #' Friendship and sharing network data from a rural Colombian population 2 | #' 3 | #' Data on friendship nominations, sharing ties, relatedness, age, sex, wealth, and ethnicity. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(AMENDS_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. 10 | #' 11 | #' @keywords datasets 12 | #' 13 | #' @references Ross, CT., and Pisor, A. 14 | #' 2024. Perceived inequality and variability in the expression of parochial altruism. 15 | #' Evolutionary Human Sciences. 16 | #' 17 | #' @source \href{https://www.eva.mpg.de/ecology/fieldwork/afrocolombians}{EVA} 18 | #' 19 | #' @examples 20 | #' data(AMENDS_Data) 21 | "AMENDS_Data" 22 | -------------------------------------------------------------------------------- /R/Baboon_Data.R: -------------------------------------------------------------------------------- 1 | #' Data on Baboon grooming relationships 2 | #' 3 | #' Data on grooming paired with additional covariate data. See the reference to the original study below for full methodological information. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(Baboon_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. N individuals = 19. The list contains three matrices (of dimension 19x19) containing data on Grooming, Presenting, and Threatening behaviours, hand-coded from focal follows. 10 | #' An Exposure matrix gives the count of times in which individual i could have been observed engaging in a given behaviour towards individual j. Finally, there are covariate data on Sex and Age. 11 | #' 12 | #' @keywords datasets 13 | #' 14 | #' @references Gelardi V, Godard J, Paleressompoulle D, Claidiere N, Barrat A. 2020. 15 | #' Measuring social networks in primates: Wearable sensors versus direct observations. 16 | #' Proc. R. Soc. A 476: 20190737. 17 | #' 18 | #' @source \href{http://dx.doi.org/10.1098/rspa.2019.0737}{RSPA} 19 | #' 20 | #' @examples 21 | #' data(Baboon_Data) 22 | "Baboon_Data" 23 | -------------------------------------------------------------------------------- /R/Baboon_Longitudinal_Data.R: -------------------------------------------------------------------------------- 1 | #' Data on Baboon grooming, resting, and playing relationships 2 | #' 3 | #' Data on grooming, resting, and playing paired with additional covariate data. See the reference to the original study below for full methodological information. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(Baboon_Longitudinal_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. N individuals = 19. The list contains four tensors (of dimension 19x19X14) containing data on grooming, resting, and playing behaviours, hand-coded from focal follows for 28 days. Each time-step is a two-day period. 10 | #' An exposure tensor gives the count of times in which individual i could have been observed engaging in a given behaviour towards individual j on time-step t. Finally, there are covariate data on sex and age. 11 | #' 12 | #' @keywords datasets 13 | #' 14 | #' @references Gelardi V, Godard J, Paleressompoulle D, Claidiere N, Barrat A. 2020. 15 | #' Measuring social networks in primates: Wearable sensors versus direct observations. 16 | #' Proc. R. Soc. A 476: 20190737. 17 | #' 18 | #' @source \href{http://dx.doi.org/10.1098/rspa.2019.0737}{RSPA} 19 | #' 20 | #' @examples 21 | #' data(Baboon_Longitudinal_Data) 22 | "Baboon_Longitudinal_Data" 23 | -------------------------------------------------------------------------------- /R/Bat_Data.R: -------------------------------------------------------------------------------- 1 | #' Blood sharing data in vampire bats 2 | #' 3 | #' Data on blood sharing observations. Kinship data is based on SPAGeDi software estimates from the authors STR data. See the reference to the original study below for full methodological information. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(Bat_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. N individuals = 19. The list contains three matrices (of dimension 19x19) containing data on licking duration, relatedness, and opportunity to be observed. 10 | #' Finally, there is covariate data on Sex. 11 | #' 12 | #' @keywords datasets 13 | #' 14 | #' @references Carter GG, Wilkinson GS. 15 | #' 2013. Food sharing in vampire bats: reciprocal help predicts donations more than relatedness or harassment. 16 | #' Proc R Soc B 280: 20122573. 17 | #' 18 | #' @source \href{http://dx.doi.org/10.1098/rspb.2012.2573}{RSPB} 19 | #' 20 | #' @examples 21 | #' data(Bat_Data) 22 | "Bat_Data" 23 | -------------------------------------------------------------------------------- /R/CES.R: -------------------------------------------------------------------------------- 1 | #' A function to compute the CES function 2 | #' 3 | #' See Constant elasticity of substitution from Wikipedia 4 | #' 5 | #' @param K Value of input 1. 6 | #' @param L Value of input 2. 7 | #' @param alpha Share parameter of input 1. 8 | #' @param sigma Elasticity of substitution. 9 | #' @param eta Returns to scale. 10 | #' @param nudge If TRUE, then nudge sigma such that sigma=1 is interpetable. 11 | #' @return CES(K,L) 12 | #' @export 13 | 14 | CES = function(K, L, alpha, sigma, eta, nudge=TRUE){ 15 | if(length(K) != length(L)) stop("K and L must be of same length.") 16 | for(i in 1:length(K)){ 17 | if(K[i] < 0) stop("K must be >= 0.") 18 | if(L[i] < 0) stop("L must be >= 0.") 19 | } 20 | if(alpha < 0 | alpha > 1) stop("alpha in (0,1).") 21 | if(sigma < 0) stop("sigma must be > 0.") 22 | if(eta < 0) stop("eta must be > 0.") 23 | if(nudge == TRUE) sigma = (3.1415/3.1415926)*sigma 24 | 25 | rho = (sigma - 1)/sigma 26 | p = (alpha*K^rho + (1-alpha)*L^rho)^(eta/rho) 27 | 28 | return(p) 29 | } 30 | -------------------------------------------------------------------------------- /R/Callithrix_Data.R: -------------------------------------------------------------------------------- 1 | #' Data on Callithrix aggression 2 | #' 3 | #' Foraging networks and social tolerance in a cooperatively breeding primate (Callithrix jacchus). See the reference to the original study below for full methodological information. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(Callithrix_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. This data object contains a subset of data from the original publication. The first sub-list contains data from the C-, or low food, condition. 10 | #' The second sub-list contains data from the S++, or high food, condition. Both sub-lists contain data on dyadic aggression, normalized directed rank difference, opportunity to be observed, and sex. 11 | #' 12 | #' @keywords datasets 13 | #' 14 | #' @references De la Fuente, María Fernanda et al. (2021), Foraging networks and social tolerance in a cooperatively breeding primate (Callithrix jacchus), Dryad, Dataset. 15 | #' 16 | #' @source \href{https://doi.org/10.5061/dryad.7pvmcvdtn}{Dryad} 17 | #' 18 | #' @examples 19 | #' data(Callithrix_Data) 20 | "Callithrix_Data" 21 | -------------------------------------------------------------------------------- /R/Colombia_Data.R: -------------------------------------------------------------------------------- 1 | #' Friendship data from a rural Colombian population 2 | #' 3 | #' Data on friendship nominations paired with covariate data. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(Colombia_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. 10 | #' 11 | #' @keywords datasets 12 | #' 13 | #' @references Dalla Ragione, A., Ross, CT., and Redhead, DJ. 14 | #' 2022. Friendship and partner choice in rural Colombia. 15 | #' 16 | #' @source \href{https://www.eva.mpg.de/ecology/fieldwork/afrocolombians}{EVA} 17 | #' 18 | #' @examples 19 | #' data(Colombia_Data) 20 | "Colombia_Data" 21 | -------------------------------------------------------------------------------- /R/FoodSharing_Data.R: -------------------------------------------------------------------------------- 1 | #' Food and Money sharing data from a rural Colombian population 2 | #' 3 | #' Self-report data on transfers, double-sampled, paired with covariate data. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(FoodSharing_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. 10 | #' 11 | #' @keywords datasets 12 | #' 13 | #' @references Anne C. Pisor, Matthew M. Gervais, Benjamin G. Purzycki, and Cody T. Ross. 2020. 14 | #' Preferences and constraints: the value of economic games for studying human behaviour 15 | #' Royal Society Open Science. Volume 7, Issue 6. 16 | #' 17 | #' @source \href{https://doi.org/10.1098/rsos.192090}{RSOS} 18 | #' 19 | #' @examples 20 | #' data(FoodSharing_Data) 21 | "FoodSharing_Data" 22 | -------------------------------------------------------------------------------- /R/HPDI.R: -------------------------------------------------------------------------------- 1 | #' A function to get Highest Posterior Density Interval 2 | #' 3 | #' This is a simple helper function to get density intervals. See McElreaths Rethinking for details. 4 | #' 5 | #' @param samples A vector of samples to summarize. 6 | #' @param prob Interval range. 7 | #' @return A vector of intervals. 8 | #' @export 9 | #' 10 | 11 | HPDI = function(samples, prob = 0.89){ 12 | concat = function (...){ 13 | paste(..., collapse = "", sep = "") 14 | } 15 | 16 | coerce.list = c("numeric", "matrix", "data.frame", "integer", 17 | "array") 18 | if (inherits(samples, coerce.list)) { 19 | samples = coda::as.mcmc(samples) 20 | } 21 | x = sapply(prob, function(p) coda::HPDinterval(samples, 22 | prob = p)) 23 | n = length(prob) 24 | result = rep(0, n * 2) 25 | for (i in 1:n) { 26 | low_idx = n + 1 - i 27 | up_idx = n + i 28 | result[low_idx] = x[1, i] 29 | result[up_idx] = x[2, i] 30 | names(result)[low_idx] = concat("|", prob[i]) 31 | names(result)[up_idx] = concat(prob[i], "|") 32 | } 33 | return(result) 34 | } 35 | -------------------------------------------------------------------------------- /R/RICH_Data.R: -------------------------------------------------------------------------------- 1 | #' Data on RICH games from Colombia 2 | #' 3 | #' Data on network-structured economic games with additional covariate data. These data have been rescaled, and some missing values were imputed using the mode or median. See the reference to the original study below for full methodological information. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(RICH_Data) 8 | #' 9 | #' @format An object of class \code{"list"}. N individuals = 93. The list contains three outcome matrices (of dimension 93 x 93) containing data on giving, taking, and reducing behaviours. 10 | #' 11 | #' @keywords datasets 12 | #' 13 | #' @references Ross and Pisor, 2024. 14 | #' Perceived inequality and variability in the expression of parochial altruism 15 | #' 16 | #' @source \href{http://dx.doi.org/}{Working paper} 17 | #' 18 | #' @examples 19 | #' data(RICH_Data) 20 | "RICH_Data" 21 | -------------------------------------------------------------------------------- /R/STRAND-package.R: -------------------------------------------------------------------------------- 1 | #' STRAND: Social network analysis and simulation in R using Stan 2 | #' 3 | #' The STRAND package provides four categories of important functions: 4 | #' network simulation functions, network analysis functions, summary functions, and results visualization functions. 5 | #' 6 | #' If you use STRAND, please cite us: 7 | #' 8 | #' Ross, C. T., McElreath, R., and Redhead, D. (2024). Modelling animal network data in R using STRAND. Journal of Animal Ecology, 93(3), 254-266. 9 | #' 10 | #' Sosa, S., McElreath, M. B., Redhead, D., and Ross, C. T. (2025). Robust Bayesian analysis of animal networks subject to biases in sampling intensity and censoring. Methods in Ecology and Evolution. 11 | #' 12 | #' Redhead, D., McElreath, R., and Ross, C. T. (2023). Reliable network inference from unreliable data: A tutorial on latent network modeling using STRAND. Psychological methods. 13 | #' 14 | #' @section Network simulation functions: 15 | #'The package can be used to simulate network data under stochastic block models, social relations models, and latent network models. 16 | #'These tools allow for simulation not only of realistic human social networks, but also allow researchers to simulate the effects of 17 | #'potential biases—like respondents falsely reporting ties or failing to recall real ties—on network level properties. 18 | #' @section Network analysis functions: 19 | #'Users can specify complex Bayesian social network models using simple lm() style syntax. 20 | #'Single-sampled self report data can be modeled using stochastic block models or the social relations model, with or with-out covariates. 21 | #'Double-sampled network data can be modeled using a latent network approach that accounts for inter-respondent disagreement. 22 | #' @section Summary functions: 23 | #' Users can summarize Stan results into tables with a simple interface. 24 | #' @section Visualization functions: 25 | #' Users can visualize Stan results with a simple interface. 26 | #' 27 | #' @keywords internal 28 | "_PACKAGE" 29 | NULL 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /R/bayesian_p.R: -------------------------------------------------------------------------------- 1 | #' A function to calculate prob of sign error, or Bayesian p value 2 | #' 3 | #' @param x value 4 | #' @return bayesian_p(x) 5 | #' @export 6 | 7 | bayesian_p = function(x){ 8 | M_x = median(x) 9 | 10 | if(M_x<0){ 11 | N_x = length(x) 12 | P_x = length(which(x>0)) 13 | } else{ 14 | N_x = length(x) 15 | P_x = length(which(x<0)) 16 | } 17 | return(P_x/N_x) 18 | } 19 | -------------------------------------------------------------------------------- /R/build_multiplex_bindings_dr_longitudinal.R: -------------------------------------------------------------------------------- 1 | #' A function to add accesssory data to a STRAND data object for use in longitudinal analysis 2 | #' 3 | #' This is an internal function. 4 | #' 5 | #' @param data A STRAND data object. 6 | #' @param verbose If TRUE, then print structure of dyadic reciprocity matrix. 7 | #' @return A STRAND data object with extra information about the structure of the dyadic reciprocity matrix. 8 | #' @export 9 | #' 10 | 11 | build_multiplex_bindings_dr_longitudinal = function(data, verbose = FALSE){ 12 | # Compute banding structure 13 | fill_set = c() 14 | for(k in 1:(data$N_responses-1)){ 15 | fill_set = c(fill_set, seq(k, 1)) 16 | } 17 | 18 | # Build A matrix 19 | bindings_mat_A = diag(NA, data$N_responses) 20 | bindings_mat_A[upper.tri(bindings_mat_A)] = fill_set 21 | bindings_mat_A[lower.tri(bindings_mat_A)] = 0 22 | 23 | # Build B matrix 24 | bindings_mat_B = diag(0, data$N_responses) 25 | bindings_mat_B[upper.tri(bindings_mat_B)] = fill_set + data$N_responses - 1 26 | bindings_mat_B[lower.tri(bindings_mat_B)] = 0 27 | bindings_mat_B = bindings_mat_B + t(bindings_mat_B) 28 | diag(bindings_mat_B) = 2*data$N_responses - 1 29 | 30 | # Assemble full matrix 31 | bindings_mat = diag(NA, 2*data$N_responses) 32 | bindings_mat[upper.tri(bindings_mat)] = 0 33 | 34 | bindings_mat[1:data$N_responses, 1:data$N_responses] = t(bindings_mat_A) 35 | bindings_mat[(1:data$N_responses)+data$N_responses, (1:data$N_responses)+data$N_responses] = t(bindings_mat_A) 36 | bindings_mat[(1:data$N_responses)+data$N_responses, 1:data$N_responses] = bindings_mat_B 37 | 38 | # Compute lookup table 39 | dr_indices = which(bindings_mat > 0, arr.ind=TRUE) 40 | dr_indices = dr_indices[order(dr_indices[,1]),] 41 | dr_id = bindings_mat[dr_indices] 42 | 43 | # Compute other info 44 | data$N_dr_bindings_l = choose(2*data$N_responses,2) # Not sure about this one 45 | data$N_dr_params_l = 2*data$N_responses - 1 46 | data$N_dr_indices_l = nrow(dr_indices) 47 | data$dr_indices_l = dr_indices 48 | data$dr_id_l = bindings_mat[dr_indices] 49 | 50 | if(verbose == TRUE){ 51 | print(bindings_mat) 52 | } 53 | 54 | return(data) 55 | } 56 | -------------------------------------------------------------------------------- /R/build_multiplex_bindings_dr_multiplex.R: -------------------------------------------------------------------------------- 1 | #' A function to add accesssory data to a STRAND data object for use in multiplex analysis 2 | #' 3 | #' This is an internal function. 4 | #' 5 | #' @param data A STRAND data object. 6 | #' @param verbose If TRUE, then print structure of dyadic reciprocity matrix. 7 | #' @return A STRAND data object with extra information about the structure of the dyadic reciprocity matrix. 8 | #' @export 9 | #' 10 | 11 | build_multiplex_bindings_dr_multiplex = function(data, verbose = FALSE){ 12 | # Build A matrix 13 | bindings_mat_A = diag(NA, data$N_responses) 14 | bindings_mat_A[upper.tri(bindings_mat_A)] = seq(1,choose(data$N_responses,2)) 15 | bindings_mat_A[lower.tri(bindings_mat_A)] = 0 16 | 17 | # Build B matrix 18 | bindings_mat_B = diag(0, data$N_responses) 19 | bindings_mat_B[lower.tri(bindings_mat_B)] = seq(1,choose(data$N_responses,2)) + choose(data$N_responses,2) 20 | bindings_mat_B[upper.tri(bindings_mat_B)] = 0 21 | bindings_mat_B = bindings_mat_B + t(bindings_mat_B) 22 | 23 | # Assemble full matrix 24 | bindings_mat = diag(NA, 2*data$N_responses) 25 | bindings_mat[upper.tri(bindings_mat)] = 0 26 | 27 | bindings_mat[1:data$N_responses, 1:data$N_responses] = t(bindings_mat_A) 28 | bindings_mat[(1:data$N_responses)+data$N_responses, (1:data$N_responses)+data$N_responses] = t(bindings_mat_A) 29 | bindings_mat[(1:data$N_responses)+data$N_responses, 1:data$N_responses] = bindings_mat_B 30 | 31 | # Compute lookup table 32 | dr_indices = which(bindings_mat > 0, arr.ind=TRUE) 33 | dr_indices = dr_indices[order(dr_indices[,1]),] 34 | dr_id = bindings_mat[dr_indices] 35 | 36 | # Compute other info 37 | data$N_dr_bindings = 2*choose(data$N_responses,2) 38 | data$N_dr_params = data$N_dr_bindings + data$N_responses 39 | data$N_dr_indices = nrow(dr_indices) 40 | data$dr_indices = dr_indices 41 | data$dr_id = bindings_mat[dr_indices] 42 | 43 | if(verbose == TRUE){ 44 | print(bindings_mat) 45 | } 46 | 47 | return(data) 48 | } 49 | -------------------------------------------------------------------------------- /R/build_multiplex_bindings_sr_longitudinal.R: -------------------------------------------------------------------------------- 1 | #' A function to add accesssory data to a STRAND data object for use in longitudinal analysis 2 | #' 3 | #' This is an internal function. 4 | #' 5 | #' @param data A STRAND data object. 6 | #' @param verbose If TRUE, then print structure of generalized reciprocity matrix. 7 | #' @return A STRAND data object with extra information about the structure of the generalized reciprocity matrix. 8 | #' @export 9 | #' 10 | 11 | build_multiplex_bindings_sr_longitudinal = function(data, verbose = FALSE){ 12 | # Compute banding structure 13 | fill_set = c() 14 | for(k in 1:(data$N_responses-1)){ 15 | fill_set = c(fill_set, seq(k, 1)) 16 | } 17 | 18 | # Build A matrix 19 | bindings_mat_A = diag(NA, data$N_responses) 20 | bindings_mat_A[upper.tri(bindings_mat_A)] = fill_set 21 | bindings_mat_A[lower.tri(bindings_mat_A)] = 0 22 | 23 | # Build C matrix 24 | bindings_mat_C = diag(NA, data$N_responses) 25 | bindings_mat_C[upper.tri(bindings_mat_C)] = fill_set + (data$N_responses - 1) 26 | bindings_mat_C[lower.tri(bindings_mat_C)] = 0 27 | 28 | # Build B matrice 29 | bindings_mat_B = diag(0, data$N_responses) 30 | bindings_mat_B[upper.tri(bindings_mat_B)] = fill_set + 2*(data$N_responses - 1) 31 | bindings_mat_B[lower.tri(bindings_mat_B)] = 0 32 | 33 | bindings_mat_Bt = diag(0, data$N_responses) 34 | bindings_mat_Bt[upper.tri(bindings_mat_Bt)] = fill_set + 3*(data$N_responses - 1) 35 | bindings_mat_Bt[lower.tri(bindings_mat_Bt)] = 0 36 | 37 | bindings_mat_B = bindings_mat_B + t(bindings_mat_Bt) 38 | diag(bindings_mat_B) = 4*(data$N_responses - 1) + 1 39 | 40 | # Assemble full matrix 41 | bindings_mat = diag(NA, 2*data$N_responses) 42 | bindings_mat[upper.tri(bindings_mat)] = 0 43 | 44 | bindings_mat[1:data$N_responses, 1:data$N_responses] = t(bindings_mat_A) 45 | bindings_mat[(1:data$N_responses)+data$N_responses, (1:data$N_responses)+data$N_responses] = t(bindings_mat_C) 46 | bindings_mat[(1:data$N_responses)+data$N_responses, 1:data$N_responses] = bindings_mat_B 47 | 48 | # Compute lookup table 49 | sr_indices = which(bindings_mat > 0, arr.ind=TRUE) 50 | sr_indices = sr_indices[order(sr_indices[,1]),] 51 | sr_id = bindings_mat[sr_indices] 52 | 53 | # Compute other info 54 | data$N_sr_bindings_l = choose(2*data$N_responses,2) # Not sure about this one 55 | data$N_sr_params_l = 4*(data$N_responses - 1) + 1 56 | data$N_sr_indices_l = nrow(sr_indices) 57 | data$sr_indices_l = sr_indices 58 | data$sr_id_l = bindings_mat[sr_indices] 59 | 60 | if(verbose == TRUE){ 61 | print(bindings_mat) 62 | } 63 | 64 | return(data) 65 | } 66 | -------------------------------------------------------------------------------- /R/center.R: -------------------------------------------------------------------------------- 1 | #' A function to mean center data 2 | #' 3 | #' This is a simple helper function to mean center data. We recommmend to mean center covariates as it makes parameter interpretation easier. 4 | #' 5 | #' @param input A vector of data to center. 6 | #' @return A vector of centered data. 7 | #' @export 8 | #' @examples 9 | #' \dontrun{ 10 | #' age_centered = center(input=age) 11 | #' } 12 | #' 13 | 14 | center = function(input){ 15 | y = input - mean(input, na.rm=TRUE) 16 | return(y) 17 | } 18 | -------------------------------------------------------------------------------- /R/colMaxs.R: -------------------------------------------------------------------------------- 1 | #' A function to compute the max by col 2 | #' 3 | #' Simpler helper function. 4 | #' 5 | #' @param x Input array. 6 | #' @param margin Margin. 7 | #' @return colMaxs(x, margin) 8 | #' @export 9 | 10 | colMaxs = function(x, margin=2){ 11 | m = apply(x, MARGIN=c(margin), max, na.rm=TRUE) 12 | return(m) 13 | } 14 | -------------------------------------------------------------------------------- /R/colMins.R: -------------------------------------------------------------------------------- 1 | #' A function to compute the min by col 2 | #' 3 | #' Simpler helper function. 4 | #' 5 | #' @param x Input array. 6 | #' @param margin Margin. 7 | #' @return colMins(x, margin) 8 | #' @export 9 | 10 | colMins = function(x, margin=2){ 11 | m = apply(x, MARGIN=c(margin), min, na.rm=TRUE) 12 | return(m) 13 | } 14 | -------------------------------------------------------------------------------- /R/generate_structured_correlation_matrix.R: -------------------------------------------------------------------------------- 1 | #' A function to generate correlation matrices with special inner symmetry 2 | #' 3 | #' This is an internal function. 4 | #' 5 | #' @param data A data list. 6 | #' @param eta Prior on the LKJ Cholesky factor. 7 | #' @param mode Which method to use? "cholesky" or "l2norm". 8 | #' @param setting Which matrix to create? "multiplex_dyadic_reciprocity", "longitudinal_dyadic_reciprocity", or "longitudinal_generalized_reciprocity". 9 | #' @param stan_mcmc_parameters A list of Stan parameters that often need to be tuned. 10 | #' @return A Stan object. 11 | #' @export 12 | #' 13 | 14 | generate_structured_correlation_matrix = function(data, eta, mode, setting, stan_mcmc_parameters) { 15 | data$eta = eta 16 | 17 | if (setting == "multiplex_dyadic_reciprocity") { 18 | data$setting = 1 19 | data = build_multiplex_bindings_dr_multiplex(data) 20 | } 21 | 22 | if (setting == "longitudinal_dyadic_reciprocity") { 23 | data$setting = 2 24 | data = build_multiplex_bindings_dr_longitudinal(data) 25 | } 26 | 27 | if (setting == "longitudinal_generalized_reciprocity") { 28 | data$setting = 3 29 | data = build_multiplex_bindings_sr_longitudinal(data) 30 | 31 | # Have to do a little renaming, so that the Stan file works for both dyadic and generalized matrices 32 | data$N_dr_bindings = data$N_sr_bindings 33 | data$N_dr_params = data$N_sr_params 34 | data$N_dr_indices = data$N_sr_indices 35 | data$dr_indices = data$sr_indices 36 | data$dr_id = data$sr_id 37 | } 38 | 39 | 40 | if (mode == "cholesky") { 41 | # Correlation matrix methods contributed to STRAND by Sean Pinkney 42 | # Copyright 2025 Sean Pinkney 43 | # Subject to the BSD 3-Clause License 44 | model = cmdstanr::cmdstan_model("Code/Stan/generate_structured_correlation_matrix_cholesky.stan") 45 | } 46 | 47 | if (mode == "l2norm") { 48 | model = cmdstanr::cmdstan_model("Code/Stan/generate_structured_correlation_matrix_l2norm.stan") 49 | } 50 | 51 | fit = model$sample( 52 | data = unclass(data), 53 | seed = stan_mcmc_parameters$seed, 54 | chains = stan_mcmc_parameters$chain, 55 | parallel_chains = stan_mcmc_parameters$parallel_chains, 56 | refresh = stan_mcmc_parameters$refresh, 57 | iter_warmup = stan_mcmc_parameters$iter_warmup, 58 | iter_sampling = stan_mcmc_parameters$iter_sampling, 59 | max_treedepth = stan_mcmc_parameters$max_treedepth, 60 | adapt_delta = stan_mcmc_parameters$adapt_delta, 61 | init = stan_mcmc_parameters$init 62 | ) 63 | 64 | bob = list(data = data, fit = fit) 65 | return(bob) 66 | } 67 | -------------------------------------------------------------------------------- /R/import.R: -------------------------------------------------------------------------------- 1 | #' @importFrom stats complete.cases median model.matrix rbeta rbinom rnorm rpois sd pnorm model.frame na.omit na.pass 2 | #' @importFrom grDevices terrain.colors 3 | #' @importFrom graphics pairs 4 | #' @importFrom jsonlite read_json 5 | #' @importFrom utils download.file 6 | NULL 7 | 8 | -------------------------------------------------------------------------------- /R/inv_logit.R: -------------------------------------------------------------------------------- 1 | #' A function to take inverse logit 2 | #' 3 | #' See McElreaths Rethinking package for details 4 | #' 5 | #' @param x value 6 | #' @return inverse_logit(x) 7 | #' @export 8 | 9 | inv_logit = function(x){ 10 | p = 1/(1 + exp(-x)) 11 | p = ifelse(x == Inf, 1, p) 12 | p 13 | } 14 | -------------------------------------------------------------------------------- /R/inv_logit_shifted.R: -------------------------------------------------------------------------------- 1 | #' A function to take inverse logit shifted 2 | #' 3 | #' Map x from (0, inf) to (0, 1) 4 | #' 5 | #' @param x value 6 | #' @return inv_logit_shifted(x) 7 | #' @export 8 | 9 | inv_logit_shifted = function(x){ 10 | return((inv_logit(x) - 0.5)*2) 11 | } 12 | -------------------------------------------------------------------------------- /R/is_numeric_not_binary.R: -------------------------------------------------------------------------------- 1 | #' A function to check the data type 2 | #' 3 | #' @param x value 4 | #' @return is_numeric_not_binary(x) 5 | #' @export 6 | 7 | is_numeric_not_binary = function(x){ 8 | if(is.numeric(x)==FALSE){ 9 | return(FALSE) 10 | } else{ 11 | if(all(x %in% c(0,1,NA))==TRUE){ 12 | return(FALSE)} 13 | else{ 14 | return(TRUE) 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /R/load.R: -------------------------------------------------------------------------------- 1 | #' A function to load some data when the package opens. 2 | #' 3 | #' @param libname Library name. 4 | #' @param pkgname Package name. 5 | #' @export 6 | 7 | .onAttach = function(libname=NULL, pkgname="STRAND") { 8 | github_auth_token = function() { 9 | github_pat = Sys.getenv("GITHUB_PAT") 10 | if (nzchar(github_pat)) { 11 | auth_token = c(Authorization = paste0("token ", github_pat)) 12 | } else { 13 | auth_token = NULL 14 | } 15 | auth_token 16 | } 17 | 18 | try_download = function(download_url, destination_file, 19 | quiet = TRUE) { 20 | download_status = try( 21 | suppressWarnings( 22 | utils::download.file(url = download_url, 23 | destfile = destination_file, 24 | quiet = quiet, 25 | headers = github_auth_token()) 26 | ), 27 | silent = TRUE 28 | ) 29 | download_status 30 | } 31 | 32 | download_with_retries = function(download_url, 33 | destination_file, 34 | retries = 5, 35 | pause_sec = 5, 36 | quiet = TRUE) { 37 | download_rc = try_download(download_url, destination_file, 38 | quiet = quiet) 39 | num_retries = 0 40 | while (num_retries < retries && inherits(download_rc, "try-error")) { 41 | Sys.sleep(pause_sec) 42 | num_retries = num_retries + 1 43 | download_rc = try_download(download_url, destination_file, quiet = quiet) 44 | } 45 | download_rc 46 | } 47 | 48 | latest_released_version = function(quiet=TRUE, ...) { 49 | dest_file = tempfile(pattern = "releases-", fileext = ".json") 50 | download_url = "https://api.github.com/repos/ctross/STRAND/releases/latest" 51 | release_list_downloaded = download_with_retries(download_url, dest_file, quiet = quiet, ...) 52 | if (inherits(release_list_downloaded, "try-error")) { 53 | stop("GitHub download of release list failed with error: ", 54 | attr(release_list_downloaded, "condition")$message, 55 | call. = FALSE) 56 | } 57 | release = jsonlite::read_json(dest_file) 58 | sub("v", "", release$tag_name) 59 | } 60 | 61 | packageStartupMessage("Bei diesem Spaziergang an den STRAND scharfen wir unsere Sinne fur die Sternbilder hoch am Himmel!") 62 | 63 | latest_version = latest_released_version(retries = 0) 64 | 65 | installed_version = "phosphorescent_desert_buttons" 66 | 67 | packageStartupMessage(paste0("This version of STRAND is: ", installed_version, ".")) 68 | 69 | if(installed_version != latest_version){ 70 | packageStartupMessage(paste0("The latest release of STRAND is: ", latest_version, ".\n 71 | STRAND is under active development, so consider updating with: devtools::install_github('ctross/STRAND@", latest_version,"')")) 72 | } 73 | } 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /R/logit.R: -------------------------------------------------------------------------------- 1 | #' A function to take logit 2 | #' 3 | #' See McElreaths Rethinking package for details. 4 | #' 5 | #' @param x value 6 | #' @return logit(x) 7 | #' @export 8 | 9 | logit = function(x){ 10 | log(x) - log(1 - x) 11 | } 12 | -------------------------------------------------------------------------------- /R/longitudinal_plot.R: -------------------------------------------------------------------------------- 1 | #' Plot longitudinal random effects in time-lag form 2 | #' 3 | #' @param input A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model. 4 | #' @param type Plot dyadic reciprocity ("dyadic") or generalized reciprocity ("generalized")?. Can use "custom", if the user passes in an appropriate data frame. 5 | #' @param mode For dyadic plots, should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj". 6 | #' @param parameter_set A labeled list of paramters to plot. E.g.: parameter_set = list(focal="Age", target="Age", focal="Sex", target="Sex", dyadic = "Relatedness"). The 7 | #' names must be focal, target, or dyadic, and the quoted text must be paramters given in the regression equations. E.g., focal_regression = ~ Age + Sex. 8 | #' @param results A results data.frame or matrix with colnames: c("Variable", "Layer", "Target" , "Base" , "Median", "L", "H", "Mean","SD","LayerNumeric") 9 | #' @param normalized Should effects be normalized? Only valid for type="coefficient". 10 | #' @param HPDI Highest Posterior Density Interval. Ranges in (0,1). 11 | #' @param plot Should a plot be displayed? 12 | #' @param export_as_table Should the tabular data rather than a ggplot object be returned? 13 | #' @param save_plot Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf". 14 | #' @param height Height of exported plot. 15 | #' @param width Width of exported plot. 16 | #' @param palette Override the default palette with a vector of color codes. "dyadic" need 3 colors, "generalized" needs 5 colors, and "coefficient" needs as many colors as supplied parameters. 17 | #' @return A figure or tabluar data to make a figure. 18 | #' @export 19 | #' @examples 20 | #' \dontrun{ 21 | #' res = longitudinal_plot(input = fit) 22 | #' } 23 | #' 24 | 25 | longitudinal_plot = function(input, type="dyadic", mode="cor", parameter_set, results, normalized = FALSE, HPDI=0.9, plot = TRUE, export_as_table = FALSE, save_plot = NULL, height=6, width=6, palette=NULL){ 26 | if(!type %in% c("dyadic", "generalized", "coefficient", "dyad", "general", "coeff", "custom")) stop("type must be: 'coefficient', 'dyadic' or 'generalized'. Or, a short form: 'dyad', 'general', 'coeff'. Last option is: 'custom'. ") 27 | 28 | if(attr(input, "model_type") != "Longitudinal") stop("longitudinal_plot() can only be fit to models fit using fit_longitudinal_model().") 29 | 30 | if(type=="dyadic" | type=="dyad"){ 31 | if(attr(input, "random_effects_mode") != "fixed") stop("Dyadic longitudinal_plot() can only be fit to models fit using fit_longitudinal_model() with: random_effects_mode='fixed'.") 32 | res = longitudinal_plot_d(input=input, HPDI=HPDI, mode=mode, plot = plot, export_as_table = export_as_table, save_plot = save_plot, height=height, width=width, palette=palette) 33 | } 34 | 35 | if(type=="generalized" | type=="general"){ 36 | if(attr(input, "random_effects_mode") != "fixed") stop("Generalized longitudinal_plot() can only be fit to models fit using fit_longitudinal_model() with: random_effects_mode='fixed'.") 37 | res = longitudinal_plot_g(input=input, HPDI=HPDI, plot = plot, export_as_table = export_as_table, save_plot = save_plot, height=height, width=width, palette=palette) 38 | } 39 | 40 | if(type=="coefficient" | type=="coeff"){ 41 | if(attr(input, "coefficient_mode") != "varying") stop("Coefficient longitudinal_plot() can only be fit to models fit using fit_longitudinal_model() with: coefficient_mode='varying'.") 42 | res = longitudinal_plot_c(input=input, parameters=as.vector(unlist(parameter_set)), type=names(parameter_set), normalized=normalized, HPDI=HPDI, plot = plot, export_as_table = export_as_table, save_plot = save_plot, height=height, width=width, palette=palette) 43 | } 44 | 45 | if(type=="custom"){ 46 | if(attr(input, "coefficient_mode") != "varying") stop("Coefficient longitudinal_plot() can only be fit to models fit using fit_longitudinal_model() with: coefficient_mode='varying'.") 47 | res = longitudinal_plot_b(input=input, results=results, plot = plot, save_plot = save_plot, height=height, width=width, palette=palette) 48 | } 49 | 50 | return(res) 51 | 52 | } 53 | -------------------------------------------------------------------------------- /R/longitudinal_plot_b.R: -------------------------------------------------------------------------------- 1 | #' Plot longitudinal random effects - dyadic reciprocity 2 | #' 3 | #' @param input A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model. 4 | #' @param results A results data.frame or matrix with colnames: c("Variable", "Layer", "Target" , "Base" , "Median", "L", "H", "Mean","SD","LayerNumeric", "P") 5 | #' @param plot Should a plot be displayed? 6 | #' @param save_plot Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf". 7 | #' @param height Height of exported plot. 8 | #' @param width Width of exported plot. 9 | #' @param palette Override the default palette with a 3-vector of color codes. 10 | #' @return A figure or tabluar data to make a figure. 11 | #' @export 12 | #' 13 | 14 | longitudinal_plot_b = function(input, results, plot = TRUE, save_plot = NULL, height=6, width=6, palette=NULL){ 15 | H = L = LayerNumeric = Median = Target = NULL 16 | 17 | if(is.null(palette)){ 18 | palette = terrain.colors(nrow(results)) 19 | } 20 | 21 | colnames(results) = c("Variable", "Layer", "Target" , "Base" , "Median", "L", "H", "Mean","SD","LayerNumeric","P") 22 | 23 | p = ggplot2::ggplot(results, ggplot2::aes(x=LayerNumeric, y=as.numeric(Median), ymin=as.numeric(L), ymax=as.numeric(H), group=Target, color=Target))+ 24 | ggplot2::geom_linerange(linewidth=1, position = ggplot2::position_dodge(width = 0.3)) + 25 | ggplot2::geom_point(size=2, position = ggplot2::position_dodge(width = 0.3))+ 26 | ggplot2::geom_hline(ggplot2::aes(yintercept=0),color="black",linetype="dashed")+ 27 | ggplot2::labs(y="Effect size", x="Time step") + 28 | ggplot2::theme(strip.text.x = ggplot2::element_text(size=12,face="bold"), 29 | strip.text.y = ggplot2::element_text(size=12,face="bold"), 30 | axis.text = ggplot2::element_text(size=12), 31 | axis.title = ggplot2::element_text(size=14, face="bold"))+ 32 | ggplot2::theme(strip.text.y = ggplot2::element_text(angle = 360)) + 33 | # ggplot2::coord_flip() + 34 | ggplot2::theme(panel.spacing = grid::unit(1, "lines")) + ggplot2::scale_color_manual(values = palette) + 35 | ggplot2::theme(legend.position="bottom") + ggplot2::theme(legend.title = ggplot2::element_blank()) 36 | 37 | if(!is.null(save_plot)){ 38 | ggplot2::ggsave(save_plot, p, height=height, width=width) 39 | } 40 | 41 | if(plot == TRUE){ 42 | plot(p) 43 | return(p) 44 | } 45 | 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /R/make_priors.R: -------------------------------------------------------------------------------- 1 | #' A function to create priors for STRAND models 2 | #' 3 | #' This function allows users to change the numerical values of priors (but not their distributions). Users should only change these values if they have read and understood the source code. 4 | #' 5 | #' @param priors_to_change A named vector of priors to change. To get parameter names, run: make_priors(include_rownames=TRUE). Values must be 2-vectors. If the prior has only one parameter, inlcude 0 as the second element. 6 | #' @param include_rownames Should rownames be printed? 7 | #' @return A STRAND priors matrix. 8 | #' @export 9 | #' @examples 10 | #' \dontrun{ 11 | #' make_priors(priors_to_change=list(sr_L=5),include_rownames=TRUE) 12 | #' make_priors() 13 | #' } 14 | #' 15 | 16 | make_priors = function(priors_to_change=NULL, include_rownames=FALSE){ 17 | 18 | parameter_names = c("false_positive_rate", "recall_of_true_ties", "theta_mean", 19 | "fpr_sigma", "rtt_sigma", "theta_sigma", 20 | "fpr_effects", "rtt_effects", "theta_effects", 21 | "B_ingroup", "B_outgroup", 22 | "focal_effects", "target_effects", "dyad_effects", 23 | "sr_sigma", "dr_sigma", 24 | "sr_L", "dr_L", 25 | "penalty", 26 | "effect_max", 27 | "effect_decay", 28 | "flow_rate", 29 | "gaussian_error_priors" 30 | ) 31 | 32 | priors = matrix(0, nrow=23, ncol=2) 33 | priors[1,1] = -3 34 | priors[1,2] = 1.5 35 | 36 | priors[2,1] = 3 37 | priors[2,2] = 1.5 38 | 39 | priors[3,1] = -1.5 40 | priors[3,2] = 1 41 | 42 | priors[4,1] = 1 43 | priors[5,1] = 1 44 | priors[6,1] = 1 45 | 46 | priors[7,1] = 0 47 | priors[7,2] = 2.5 48 | 49 | priors[8,1] = 0 50 | priors[8,2] = 2.5 51 | 52 | priors[9,1] = 0 53 | priors[9,2] = 2.5 54 | 55 | priors[10,1] = 0.1 56 | priors[10,2] = 2.5 57 | 58 | priors[11,1] = 0.01 59 | priors[11,2] = 2.5 60 | 61 | priors[12,1] = 0 62 | priors[12,2] = 2.5 63 | 64 | priors[13,1] = 0 65 | priors[13,2] = 2.5 66 | 67 | priors[14,1] = 0 68 | priors[14,2] = 2.5 69 | 70 | priors[15,1] = 0 71 | priors[15,2] = 2.5 72 | 73 | priors[16,1] = 0 74 | priors[16,2] = 2.5 75 | 76 | priors[17,1] = 2.5 77 | priors[18,1] = 2.5 78 | 79 | priors[19,1] = 1.5 80 | 81 | priors[20,1] = 3 82 | priors[20,2] = 1 83 | 84 | priors[21,1] = 2 85 | 86 | priors[22,1] = 3 87 | priors[22,2] = 12 88 | 89 | priors[23,1] = 0 90 | priors[23,2] = 2.5 91 | 92 | if(!is.null(priors_to_change)){ 93 | for(i in 1:length(priors_to_change)){ 94 | if(length(priors_to_change[[i]])==1){ 95 | priors[which(parameter_names==names(priors_to_change)[i] ),1] = priors_to_change[[i]] 96 | } 97 | if(length(priors_to_change[[i]])==2){ 98 | priors[which(parameter_names==names(priors_to_change)[i] ),1:2] = priors_to_change[[i]] 99 | } 100 | }} 101 | 102 | if(include_rownames == TRUE){ 103 | rownames(priors) = parameter_names 104 | } 105 | 106 | return(priors) 107 | } 108 | -------------------------------------------------------------------------------- /R/multiplex_plot.R: -------------------------------------------------------------------------------- 1 | #' Plot multiplex random effects in matrix form 2 | #' 3 | #' @param input A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model. 4 | #' @param type Plot dyadic reciprocity ("dyadic") or generalized reciprocity ("generalized")?. 5 | #' @param mode For dyadic plots, should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj". 6 | #' @param HPDI Highest Posterior Density Interval. Ranges in (0,1). 7 | #' @param plot Should a plot be displayed? 8 | #' @param export_as_table Should the tabular data rather than a ggplot object be returned? 9 | #' @param save_plot Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf". 10 | #' @param height Height of exported plot. 11 | #' @param width Width of exported plot. 12 | #' @param palette Override the default palette with a 3-vector of color codes. 13 | #' @return A figure or tabluar data to make a figure. 14 | #' @export 15 | #' @examples 16 | #' \dontrun{ 17 | #' res = multiplex_plot(input = fit) 18 | #' } 19 | #' 20 | 21 | multiplex_plot = function(input, type="dyadic", mode="cor", HPDI=0.9, plot = TRUE, export_as_table = FALSE, save_plot = NULL, height=6, width=6, palette=NULL){ 22 | if(!type %in% c("dyadic", "generalized", "dyad", "general")) stop("type nust be 'dyadic' or 'generalized'. Or, a short form: 'dyad', or 'general'.") 23 | 24 | if(!attr(input, "model_type") %in% c("Longitudinal", "Multiplex")) stop("multiplex_plot() can only be fit to models fit using fit_multiplex_model() or fit_longitudinal_model().") 25 | 26 | if(type=="dyadic" | type=="dyad"){ 27 | multiplex_plot_d(input=input, HPDI=HPDI, mode=mode, plot = plot, export_as_table = export_as_table, save_plot = save_plot, height=height, width=width, palette=palette) 28 | } 29 | 30 | if(type=="generalized" | type=="general"){ 31 | multiplex_plot_g(input=input, HPDI=HPDI, plot = plot, export_as_table = export_as_table, save_plot = save_plot, height=height, width=width, palette=palette) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /R/multiplex_plot_g.R: -------------------------------------------------------------------------------- 1 | #' Plot multiplex random effects - generalized reciprocity 2 | #' 3 | #' @param input A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model. 4 | #' @param HPDI Highest Posterior Density Interval. Ranges in (0,1). 5 | #' @param plot Should a plot be displayed? 6 | #' @param export_as_table Should the tabular data rather than a ggplot object be returned? 7 | #' @param save_plot Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf". 8 | #' @param height Height of exported plot. 9 | #' @param width Width of exported plot. 10 | #' @param palette Override the default palette with a 3-vector of color codes. 11 | #' @return A figure or tabluar data to make a figure. 12 | #' @export 13 | #' @examples 14 | #' \dontrun{ 15 | #' res = multiplex_plot_g(input = fit) 16 | #' } 17 | #' 18 | 19 | multiplex_plot_g = function(input, HPDI=0.9, plot = TRUE, export_as_table = FALSE, save_plot = NULL, height=6, width=6, palette=NULL){ 20 | if(is.null(palette)){ 21 | palette = c("#7D370D", "#FBFEF9", "#114B47") 22 | } 23 | 24 | stanfit = posterior::as_draws_rvars(input$fit$draws()) 25 | corr = posterior::draws_of(stanfit$"G_corr") 26 | 27 | N_responses = input$data$N_responses 28 | layer_names = attr(input$data,"layer_names") 29 | 30 | rs_m = apply(corr, 2:3, median) 31 | rs_l = apply(corr, 2:3, HPDI, prob=HPDI)[1,,] 32 | rs_h = apply(corr, 2:3, HPDI, prob=HPDI)[2,,] 33 | 34 | rs_m[lower.tri(rs_m)] = NA 35 | diag(rs_m) = NA 36 | 37 | rs_l[lower.tri(rs_l)] = NA 38 | diag(rs_l) = NA 39 | 40 | rs_h[lower.tri(rs_h)] = NA 41 | diag(rs_h) = NA 42 | 43 | rs_type = rs_m 44 | rs_type[which(!is.na(rs_type))] = "Cross" 45 | 46 | for(m in 1:(N_responses-1)){ 47 | for(n in (m+1):N_responses){ 48 | rs_type[m,n] = "Sender" 49 | rs_type[N_responses+m,N_responses+n] = "Receiver" 50 | }} 51 | 52 | rs_m = c(rs_m) 53 | rs_l = c(rs_l) 54 | rs_h = c(rs_h) 55 | 56 | rs_type = c(rs_type) 57 | 58 | # Prep for CI figure 59 | substrRight = function(x, n){ 60 | x = as.character(x) 61 | substr(x, nchar(x)-n+1, nchar(x)) 62 | } 63 | 64 | substrLeft = function(x, n){ 65 | x = as.character(x) 66 | substr(x, 1, nchar(x)-n+1) 67 | } 68 | 69 | names_outcomes = c(paste0(layer_names, "\n(sender)"), paste0(layer_names, "\n(receiver)")) 70 | 71 | measure1 = factor(rep(names_outcomes, each=(N_responses*2))) 72 | measure2 = factor(rep(names_outcomes, (N_responses*2))) 73 | 74 | measure1 = factor(measure1,names_outcomes) 75 | measure2 = factor(measure2,rev(names_outcomes)) 76 | 77 | r_if_sig = ifelse(rs_l > 0 | rs_h < 0, round(rs_m, 2), NA) 78 | 79 | df = data.frame(rs_m=rs_m, l=rs_l, h=rs_h, measure1=measure1, measure2=measure2, r_if_sig=r_if_sig, rs_type=rs_type) 80 | 81 | 82 | df$Group1 = ifelse(substrRight(df$measure1,4)=="der)" & substrRight(df$measure2,4)=="der)", "Sender", 83 | ifelse(substrRight(df$measure1,4)=="ver)" & substrRight(df$measure2,4)=="ver)", "Receiver", 84 | "Cross" 85 | )) 86 | 87 | p1 = ggplot2::ggplot(df, ggplot2::aes(measure1, measure2, fill=rs_m, label=round(r_if_sig,2),color=rs_type)) + 88 | ggplot2::geom_tile(ggplot2::aes(width=0.96, height=0.96), size=1.69) + 89 | ggplot2::labs(x = NULL, y = NULL, fill = "Correlation", title="Generalized reciprocity estimates", subtitle="Only reliable correlation coefficients shown") + 90 | ggplot2::scale_fill_gradient2(mid=palette[2],low=palette[1],high=palette[3], limits=c(-1,1)) + 91 | ggplot2::geom_text(color="black",size=12*0.36) + 92 | ggplot2::theme_classic() + 93 | ggplot2::scale_x_discrete(expand=c(0,0)) + 94 | ggplot2::scale_y_discrete(expand=c(0,0)) + ggplot2::guides(color = "none") + ggplot2::theme(plot.title = ggplot2::element_text(size = 14)) + 95 | ggplot2::scale_color_manual(values=c("grey75","grey15","grey15","grey75")) + ggplot2::theme(axis.text = ggplot2::element_text(size = 14)) 96 | 97 | if(!is.null(save_plot)){ 98 | ggplot2::ggsave(save_plot, p1, height=height, width=width) 99 | } 100 | 101 | if(plot == TRUE){ 102 | plot(p1) 103 | return(p1) 104 | } 105 | 106 | if(export_as_table == TRUE){ 107 | return(df) 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /R/parse_longitudinal_data.R: -------------------------------------------------------------------------------- 1 | #' An internal function to parse a list of STRAND data objects into a longitudinal object and then apply regression models. 2 | #' 3 | #' @param data A data objects of class STRAND, prepared using the make_strand_data() function. The data object must include all covariates used in the formulas of the fit_longitudinal_model function. 4 | #' @param block_regression A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however. 5 | #' @param 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 6 | #' @param 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 7 | #' @param dyad_regression A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship 8 | #' @return A STRAND data object. 9 | #' @export 10 | #' 11 | 12 | parse_longitudinal_data = function(data, 13 | block_regression, 14 | focal_regression, 15 | target_regression, 16 | dyad_regression 17 | ){ 18 | ############################################################################# Prepare data and parse formulas 19 | ind_names = colnames(data$individual_predictors) 20 | dyad_names = names(data$dyadic_predictors) 21 | 22 | if(data$N_individual_predictors==0 & focal_regression != ~ 1){ 23 | stop("No individual covariate data has been provided. focal_regression must equal ~ 1 ") 24 | } 25 | 26 | if(data$N_individual_predictors==0 & target_regression != ~ 1){ 27 | stop("No individual covariate data has been provided. target_regression must equal ~ 1 ") 28 | } 29 | 30 | if(data$N_dyadic_predictors==0 & dyad_regression != ~ 1){ 31 | stop("No individual covariate data has been provided. dyad_regression must equal ~ 1 ") 32 | } 33 | 34 | if(data$N_block_predictors==0 & block_regression != ~ 1){ 35 | stop("No block covariate data has been provided. block_regression must equal ~ 1 ") 36 | } 37 | 38 | ################################################################ Dyad model matrix 39 | if(data$N_dyadic_predictors>0){ 40 | dyad_dims = c(data$N_id, data$N_id, length(dyad_names)) 41 | 42 | dyad_dat = list() 43 | for(i in 1:dyad_dims[3]){ 44 | dyad_dat[[i]] = c(data$dyadic_predictors[[i]]) 45 | } 46 | 47 | #dyad_dat = do.call(rbind.data.frame, dyad_dat) 48 | #dyad_dat = as.data.frame(do.call(cbind, dyad_dat)) 49 | dyad_dat = do.call(data.frame, dyad_dat) 50 | colnames(dyad_dat) = dyad_names 51 | dyad_model_matrix = model.matrix( dyad_regression , dyad_dat ) 52 | 53 | dyad_dat_out = array(NA, c(dyad_dims[1], dyad_dims[2], ncol(dyad_model_matrix))) 54 | for(i in 1:ncol(dyad_model_matrix)){ 55 | dyad_dat_out[,,i] = matrix(dyad_model_matrix[,i], nrow=dyad_dims[1], ncol=dyad_dims[2]) 56 | } 57 | 58 | dimnames(dyad_dat_out)[[3]] = colnames(dyad_model_matrix) 59 | data$dyad_set = dyad_dat_out 60 | } else{ 61 | data$dyad_set = array(1, c(data$N_id, data$N_id, 1)) 62 | } 63 | 64 | ################################################################ Individual model matrix 65 | if(data$N_individual_predictors>0){ 66 | data$focal_set = model.matrix( focal_regression , data$individual_predictors ) 67 | data$target_set = model.matrix( target_regression , data$individual_predictors ) 68 | } else{ 69 | data$focal_set = matrix(1,nrow=data$N_id, ncol=1) 70 | data$target_set = matrix(1,nrow=data$N_id, ncol=1) 71 | } 72 | 73 | data$N_params = c(ncol(data$focal_set), ncol(data$target_set), dim(data$dyad_set)[3]) 74 | 75 | ################################################################ Block model matrix 76 | if(data$N_block_predictors>0){ 77 | data$block_set = model.matrix( block_regression , data$block_predictors ) 78 | } else{ 79 | data$block_set = as.array(matrix(1, nrow=data$N_id, ncol=1)) 80 | colnames(data$block_set) = "(Intercept)" 81 | } 82 | 83 | data$N_group_vars = ncol(data$block_set) 84 | data$N_groups_per_var = rep(NA, data$N_group_vars) 85 | 86 | for(i in 1:data$N_group_vars){ 87 | data$N_groups_per_var[i] = length(unique(data$block_set[,i])) 88 | } 89 | 90 | data$N_groups_per_var = as.array(data$N_groups_per_var) 91 | 92 | data$max_N_groups = max(data$N_groups_per_var) 93 | 94 | return(data) 95 | } 96 | -------------------------------------------------------------------------------- /R/plot_diffusion.R: -------------------------------------------------------------------------------- 1 | #' A function to simulate a network-based diffusion proccess using the STRAND framework 2 | #' 3 | #' This function allows users to simulate data using a NBDA model. The user must supply a list of STRAND data objects, a set of parameters, 4 | #' and a series of formulas following standard lm() style syntax. 5 | #' 6 | #' @param long_data A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates and trait diffusion data used in the formulas listed below. 7 | #' @param palette A 2-vector of plot colors. First element is for the low value of scale, second is for the high value. 8 | #' @return A ggplot2 object. 9 | #' @export 10 | #' @examples 11 | #' \dontrun{ 12 | #' plot_diffusion(long_data) 13 | #' } 14 | #' 15 | 16 | plot_diffusion = function(long_data, palette = c("#13667B", "#35ABC0")){ 17 | X = Y = Z = NULL 18 | data = make_longitudinal_data(long_data = long_data, 19 | block_regression = ~ 1, 20 | focal_regression = ~ 1, 21 | target_regression = ~ 1, 22 | dyad_regression = ~ 1 23 | ) 24 | 25 | diffusion_outcomes = matrix(NA, nrow = data$N_id, ncol = data$N_responses) 26 | 27 | for(t in 1:data$N_responses){ 28 | diffusion_outcomes[,t] = long_data[[t]]$diffusion_outcomes 29 | } 30 | 31 | # Heatmap 32 | cols_diffusion_outcomes = rows_diffusion_outcomes = matrix(NA, nrow=data$N_id, ncol=data$N_responses) 33 | 34 | for(i in 1:data$N_id){ 35 | rows_diffusion_outcomes[i,] = c(1:data$N_responses) 36 | } 37 | 38 | for(i in 1:data$N_responses){ 39 | cols_diffusion_outcomes[,i] = c(1:data$N_id) 40 | } 41 | 42 | plot_dat = data.frame(X = c(rows_diffusion_outcomes), Y=c(cols_diffusion_outcomes), Z=c(diffusion_outcomes)) 43 | 44 | # Viz 45 | ggplot2::ggplot(plot_dat, ggplot2::aes(X, Y, fill = Z)) + 46 | ggplot2::geom_tile() + ggplot2::scale_fill_gradient(low=palette[1], high=palette[2]) + 47 | ggplot2::theme(legend.position="none") + ggplot2::xlab("Time-step") + ggplot2::ylab("Individual") 48 | 49 | } 50 | -------------------------------------------------------------------------------- /R/random_string.R: -------------------------------------------------------------------------------- 1 | #' A function to make random ID codes 2 | #' 3 | #' This is a small helper function to create random ID codes. 4 | #' 5 | #' @param N Number of ID codes to generate. 6 | #' @param length Length of ID codes. 7 | #' @return A vector of unique ID codes. 8 | #' @export 9 | #' @examples 10 | #' \dontrun{ 11 | #' IDs = random_string(N=100, length=5) 12 | #' } 13 | #' 14 | 15 | random_string = function(N=1, length=12){ 16 | randomString = rep(NA, N) 17 | for (i in 1:N){ 18 | randomString[i] = paste(sample(c(0:9, letters, LETTERS), length, replace=TRUE), collapse="") 19 | } 20 | 21 | if(sum(duplicated(randomString))>0){ 22 | stop("At least one ID code string was duplicated. Consider a larger string length.") 23 | } 24 | 25 | return(randomString) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/rbern.R: -------------------------------------------------------------------------------- 1 | #' A function to simulate Bernoulli data 2 | #' 3 | #' See McElreaths Rethinking package for details 4 | #' 5 | #' @param n Number of samples 6 | #' @param prob Probability 7 | #' @return Binary samples 8 | #' @export 9 | 10 | rbern = function (n, prob = 0.5) 11 | { 12 | rbinom(n, size = 1, prob = prob) 13 | } 14 | -------------------------------------------------------------------------------- /R/rmvnorm.R: -------------------------------------------------------------------------------- 1 | #' A function to simulate MV norm data 2 | #' 3 | #' See mvtnorm package for details 4 | #' 5 | #' @param n number of samples 6 | #' @param mean mean vector 7 | #' @param sigma vcov matrix 8 | #' @param method method to use 9 | #' @param pre0.9_9994 see mvtnorm 10 | #' @param checkSymmetry see mvtnorm 11 | #' @return MV normal samples 12 | #' @export 13 | 14 | rmvnorm = function (n, mean = rep(0, nrow(sigma)), sigma = diag(length(mean)), 15 | method = c("eigen", "svd", "chol"), pre0.9_9994 = FALSE, 16 | checkSymmetry = TRUE){ 17 | if (checkSymmetry && !isSymmetric(sigma, tol = sqrt(.Machine$double.eps), 18 | check.attributes = FALSE)) { 19 | stop("sigma must be a symmetric matrix") 20 | } 21 | if (length(mean) != nrow(sigma)) 22 | stop("mean and sigma have non-conforming size") 23 | method = match.arg(method) 24 | R = if (method == "eigen") { 25 | ev = eigen(sigma, symmetric = TRUE) 26 | if (!all(ev$values >= -sqrt(.Machine$double.eps) * abs(ev$values[1]))) { 27 | warning("sigma is numerically not positive semidefinite") 28 | } 29 | t(ev$vectors %*% (t(ev$vectors) * sqrt(pmax(ev$values, 30 | 0)))) 31 | } 32 | else if (method == "svd") { 33 | s. = svd(sigma) 34 | if (!all(s.$d >= -sqrt(.Machine$double.eps) * abs(s.$d[1]))) { 35 | warning("sigma is numerically not positive semidefinite") 36 | } 37 | t(s.$v %*% (t(s.$u) * sqrt(pmax(s.$d, 0)))) 38 | } 39 | else if (method == "chol") { 40 | R = chol(sigma, pivot = TRUE) 41 | R[, order(attr(R, "pivot"))] 42 | } 43 | retval = matrix(rnorm(n * ncol(sigma)), nrow = n, byrow = !pre0.9_9994) %*% 44 | R 45 | retval = sweep(retval, 2, mean, "+") 46 | colnames(retval) = names(mean) 47 | retval 48 | } 49 | -------------------------------------------------------------------------------- /R/rmvnorm2.R: -------------------------------------------------------------------------------- 1 | #' A function to simulate MV Normal data 2 | #' 3 | #' See McElreaths Rethinking package for details 4 | #' 5 | #' @param n Number of samples. 6 | #' @param Mu Mean vector. 7 | #' @param sigma Variance vector. 8 | #' @param Rho Correlation matrix. 9 | #' @param method See details in Rethinking. 10 | #' @return MV normal samples. 11 | #' @export 12 | 13 | rmvnorm2 = function (n, Mu = rep(0, length(sigma)), sigma = rep(1, length(Mu)), 14 | Rho = diag(length(Mu)), method = "chol"){ 15 | ldim = function(x) { 16 | z = length(dim(x)) 17 | if (z == 0) 18 | z = 1 19 | return(z) 20 | } 21 | if (ldim(Mu) > 1 || ldim(sigma) > 1 || ldim(Rho) > 2) { 22 | m = 0 23 | mR = 0 24 | K_Mu = 1 25 | if (ldim(Mu) == 2) { 26 | K_Mu = dim(Mu)[1] 27 | m = dim(Mu)[2] 28 | } 29 | else { 30 | m = length(Mu) 31 | } 32 | K_sigma = 1 33 | if (ldim(sigma) == 2) { 34 | K_sigma = dim(sigma)[1] 35 | } 36 | K_Rho = 1 37 | if (ldim(Rho) == 3) { 38 | K_Rho = dim(Rho)[1] 39 | } 40 | mR = dim(Rho)[2] 41 | K = n 42 | if (K_Mu < K) { 43 | Mu_new = matrix(NA, nrow = K, ncol = m) 44 | row_list = rep(1:K_Mu, length.out = K) 45 | if (K_Mu == 1) 46 | for (i in 1:K) Mu_new[i, ] = Mu 47 | else for (i in 1:K) Mu_new[i, ] = Mu[row_list[i], 48 | ] 49 | Mu = Mu_new 50 | } 51 | if (K_sigma < K) { 52 | sigma_new = matrix(NA, nrow = K, ncol = m) 53 | row_list = rep(1:K_sigma, length.out = K) 54 | for (i in 1:K) sigma_new[i, ] = sigma[row_list[i], 55 | ] 56 | sigma = sigma_new 57 | } 58 | if (K_Rho < K) { 59 | Rho_new = array(NA, dim = c(K, m, m)) 60 | row_list = rep(1:K_Rho, length.out = K) 61 | for (i in 1:K) Rho_new[i, , ] = Rho[row_list[i], 62 | , ] 63 | Rho = Rho_new 64 | } 65 | result = array(NA, dim = c(K, m)) 66 | for (i in 1:n) { 67 | DS = diag(sigma[i, ]) 68 | SIGMA = DS %*% Rho[i, , ] %*% DS 69 | result[i, ] = rmvnorm(n = 1, mean = Mu[i, ], sigma = SIGMA, 70 | method = method) 71 | } 72 | return(result) 73 | } 74 | else { 75 | DS = diag(sigma) 76 | SIGMA = DS %*% Rho %*% DS 77 | return(rmvnorm(n = n, mean = Mu, sigma = SIGMA, method = method)) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /R/run_longitudinal_checks.R: -------------------------------------------------------------------------------- 1 | #' An internal function to check that a list of STRAND data objects can be merged into a longitudinal object 2 | #' 3 | #' @param data A list of data objects of class STRAND prepared using the make_strand_data() function. The data object must include all covariates used in the formulas of the fit_longitudinal_model() function. 4 | #' @param pass 1 or 2. First pass checks raw data, second pass checks some computed values also. 5 | #' @return Returns an error if objects do not match. 6 | #' @export 7 | #' 8 | 9 | run_longitudinal_checks = function(data, pass){ 10 | if(pass==1){ 11 | check_set = matrix(NA, nrow=length(data),ncol=12) 12 | checks = c("N_networktypes", "N_id", "N_responses", "N_periods", "N_individual_predictors", "N_dyadic_predictors", 13 | "N_block_predictors", "individual_predictors", "block_predictors", "dyadic_predictors", 14 | "outcome_mode", "N_groups_per_block_type") 15 | } 16 | if(pass==2){ 17 | check_set = matrix(NA, nrow=length(data),ncol=18) 18 | checks = c("N_networktypes", "N_id", "N_responses", "N_periods", "N_individual_predictors", "N_dyadic_predictors", 19 | "N_block_predictors", "individual_predictors", "block_predictors", "dyadic_predictors", 20 | "outcome_mode", "N_groups_per_block_type", "N_params", "N_group_vars","N_groups_per_var", 21 | "max_N_groups", "group_ids_levels","priors" ) 22 | } 23 | 24 | for(i in 1:length(data)){ 25 | if(!"Longitudinal" %in% attr(data[[i]], "supported_models")){stop("For longitudinal models, set 'longitudinal = TRUE' in call to make_strand_data().")} 26 | 27 | check_set[i,1] = ifelse(data[[1]]$N_networktypes == data[[i]]$N_networktypes,1,0) 28 | check_set[i,2] = ifelse(data[[1]]$N_id == data[[i]]$N_id,1,0) 29 | check_set[i,3] = ifelse(data[[1]]$N_responses == data[[i]]$N_responses,1,0) 30 | check_set[i,4] = ifelse(data[[1]]$N_periods == data[[i]]$N_periods,1,0) 31 | check_set[i,5] = ifelse(data[[1]]$N_individual_predictors == data[[i]]$N_individual_predictors,1,0) 32 | check_set[i,6] = ifelse(data[[1]]$N_dyadic_predictors == data[[i]]$N_dyadic_predictors,1,0) 33 | check_set[i,7] = ifelse(data[[1]]$N_block_predictors == data[[i]]$N_block_predictors,1,0) 34 | check_set[i,8] = ifelse(all(colnames(data[[1]]$individual_predictors)==colnames(data[[i]]$individual_predictors)),1,0) 35 | check_set[i,9] = ifelse(all(colnames(data[[1]]$block_predictors)==colnames(data[[i]]$block_predictors)),1,0) 36 | check_set[i,10] = ifelse(all(names(data[[1]]$dyadic_predictors)==names(data[[i]]$dyadic_predictors)),1,0) 37 | check_set[i,11] = ifelse(data[[1]]$outcome_mode == data[[i]]$outcome_mode,1,0) 38 | check_set[i,12] = ifelse(all(data[[1]]$N_groups_per_block_type == data[[i]]$N_groups_per_block_type),1,0) 39 | } 40 | 41 | if(pass==2){ 42 | for(i in 1:length(data)){ 43 | check_set[i,13] = ifelse(all(data[[1]]$N_params == data[[i]]$N_params),1,0) 44 | check_set[i,14] = ifelse(all(data[[1]]$N_group_vars == data[[i]]$N_group_vars),1,0) 45 | check_set[i,15] = ifelse(all(data[[1]]$N_groups_per_var == data[[i]]$N_groups_per_var),1,0) 46 | check_set[i,16] = ifelse(all(data[[1]]$max_N_groups == data[[i]]$max_N_groups),1,0) 47 | 48 | temp1 = c() 49 | for(j in 1:length(attr(data[[1]], "group_ids_levels"))){ 50 | temp1[j] = all(attr(data[[1]], "group_ids_levels")[[j]]==attr(data[[i]], "group_ids_levels")[[j]]) 51 | } 52 | check_set[i,17] = all(temp1) 53 | check_set[i,18] = ifelse(all(data[[1]]$priors == data[[i]]$priors),1,0) 54 | } 55 | } 56 | 57 | cschecks = ifelse(colSums(check_set) == length(data),1,0) 58 | 59 | for(i in 1:length(cschecks)){ 60 | if(cschecks[i]==0){ 61 | stop(paste0("Error, match not possible for ", checks[i])) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /R/standardize.R: -------------------------------------------------------------------------------- 1 | #' A function to standardize data 2 | #' 3 | #' This is a simple helper function to standardize data. We recommmend to standardize covariates as it makes parameter interpretation easier. 4 | #' 5 | #' @param input A vector of data to standardize. 6 | #' @param type Divide by "max" or "sd"? 7 | #' @param center Subtract mean? 8 | #' @return A vector of standardize data. 9 | #' @export 10 | #' @examples 11 | #' \dontrun{ 12 | #' age_standardize = standardize(input=age) 13 | #' } 14 | #' 15 | 16 | standardize = function(input, center=TRUE, type="sd"){ 17 | if(center==TRUE){ 18 | y = input - mean(input, na.rm=TRUE) 19 | } 20 | 21 | if(center==FALSE){ 22 | y = input 23 | } 24 | 25 | if(type=="sd"){ 26 | z = y/sd(y, na.rm=TRUE) 27 | } 28 | 29 | if(type=="max"){ 30 | z = y/max(y, na.rm=TRUE) 31 | } 32 | 33 | if(!type %in% c("sd","max")){ 34 | stop("type must be sd or max.") 35 | } 36 | 37 | return(z) 38 | } 39 | -------------------------------------------------------------------------------- /R/sum_stats.R: -------------------------------------------------------------------------------- 1 | #' A function to summarize samples 2 | #' 3 | #' This is a simple helper function to summarize samples. 4 | #' 5 | #' @param y A string. 6 | #' @param x Samples. 7 | #' @param z HPDI level 8 | #' @return A vector of summaries. 9 | #' @export 10 | #' 11 | 12 | sum_stats = function(y, x, z){ 13 | bob = rep(NA, 7) 14 | dig = 3 15 | bob[1] = y 16 | bob[2] = round(median(x),dig) 17 | bob[3] = round(HPDI(x, z)[1],dig) 18 | bob[4] = round(HPDI(x, z)[2],dig) 19 | bob[5] = round(mean(x),dig) 20 | bob[6] = round(sd(x),dig) 21 | bob[7] = round(bayesian_p(x),dig) 22 | 23 | return(bob) 24 | } 25 | -------------------------------------------------------------------------------- /R/summarize_strand_results.R: -------------------------------------------------------------------------------- 1 | #' Organize Stan output and provide summaries of model parameters 2 | #' 3 | #' This is a function to organize Stan output and provide summaries of key model parameters. 4 | #' 5 | #' @param input A STRAND model object, obtained by fitting a model using a STRAND function. 6 | #' @param include_samples An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space. 7 | #' @param HPDI Highest Posterior Density Interval. Ranges in (0,1). 8 | #' @return A STRAND results object including summary table, a summary list, and samples. 9 | #' @export 10 | #' @examples 11 | #' \dontrun{ 12 | #' res = summarize_strand_results(input = fit) 13 | #' } 14 | #' 15 | 16 | summarize_strand_results = function(input, include_samples=TRUE, HPDI=0.9){ 17 | if(attributes(input)$class != "STRAND Model Object"){ 18 | stop("summarize_strand_results() requires a fitted object of class: STRAND Model Object.") 19 | } 20 | 21 | if(attributes(input)$fit_type != "mcmc"){ 22 | if(attributes(input)$fit_type == "vb"){ 23 | warning("Final, publication-ready model fits for STRAND models should always be produced using MCMC! Variational inference via Pathfinder can be used in Stan 24 | during experimental model runs, but final inferences should be based on MCMC sampling. In our tests, Pathfinder results are decently similar to MCMC results, 25 | but often failed to recover strong true effects. ") 26 | } else{ 27 | stop("Fitted results can only be reorganized for STRAND model objects fit using MCMC. Variational inference or optimization can be used in Stan 28 | during experimental model runs, but final inferences should be based on MCMC sampling.") 29 | } 30 | } 31 | 32 | if(attributes(input)$model_type == "SRM"){ 33 | res = summarize_srm_results(input=input, include_samples=include_samples, HPDI=HPDI) 34 | } 35 | 36 | if(attributes(input)$model_type == "SBM"){ 37 | res = summarize_bm_results(input=input, include_samples=include_samples, HPDI=HPDI) 38 | } 39 | 40 | if(attributes(input)$model_type == "SRM+SBM"){ 41 | res = summarize_bsrm_results(input=input, include_samples=include_samples, HPDI=HPDI) 42 | } 43 | 44 | if(attributes(input)$model_type == "SRM+SBM+ME"){ 45 | res = summarize_bsrm_results_with_measurement_bias(input=input, include_samples=include_samples, HPDI=HPDI) 46 | } 47 | 48 | if(attributes(input)$model_type == "LNM"){ 49 | res = summarize_lnm_results(input=input, include_samples=include_samples, HPDI=HPDI) 50 | } 51 | 52 | if(attributes(input)$model_type == "LNM+Flows"){ 53 | res = summarize_lnmf_results(input=input, include_samples=include_samples, HPDI=HPDI) 54 | } 55 | 56 | if(attributes(input)$model_type == "Multiplex"){ 57 | res = summarize_multiplex_bsrm_results(input=input, include_samples=include_samples, HPDI=HPDI) 58 | } 59 | 60 | if(attributes(input)$model_type == "Longitudinal"){ 61 | res = summarize_longitudinal_bsrm_results(input=input, include_samples=include_samples, HPDI=HPDI) 62 | } 63 | 64 | return(res) 65 | } 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /data/AMENDS_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/AMENDS_Data.RData -------------------------------------------------------------------------------- /data/Baboon_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/Baboon_Data.RData -------------------------------------------------------------------------------- /data/Baboon_Longitudinal_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/Baboon_Longitudinal_Data.RData -------------------------------------------------------------------------------- /data/Bat_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/Bat_Data.RData -------------------------------------------------------------------------------- /data/Callithrix_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/Callithrix_Data.RData -------------------------------------------------------------------------------- /data/Colombia_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/Colombia_Data.RData -------------------------------------------------------------------------------- /data/FoodSharing_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/FoodSharing_Data.RData -------------------------------------------------------------------------------- /data/RICH_Data.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/data/RICH_Data.RData -------------------------------------------------------------------------------- /inst/generate_structured_correlation_matrix_cholesky.stan: -------------------------------------------------------------------------------- 1 | functions { 2 | // Correlation matrix methods contributed to STRAND by Sean Pinkney 3 | // Copyright 2025 Sean Pinkney 4 | // Subject to the BSD 3-Clause License 5 | vector lb_ub_lp(vector y, real lb, real ub) { 6 | target += log(ub - lb) + log_inv_logit(y) + log1m_inv_logit(y); 7 | 8 | return lb + (ub - lb) * inv_logit(y); 9 | } 10 | 11 | real lb_ub_lp(real y, real lb, real ub) { 12 | target += log(ub - lb) + log_inv_logit(y) + log1m_inv_logit(y); 13 | 14 | return lb + (ub - lb) * inv_logit(y); 15 | } 16 | 17 | matrix cholesky_corr_constrain_lp(int K, vector raw, int N_blocks, 18 | array[,] int res_index, 19 | array[] int res_id, vector lb, vector ub) { 20 | matrix[K, K] L = rep_matrix(0, K, K); 21 | int cnt = 1; 22 | int N_res = num_elements(res_id); 23 | vector[N_blocks] x_cache; 24 | array[N_blocks] int res_id_cnt = ones_int_array(N_blocks); 25 | int res_row = 1; 26 | 27 | L[1, 1] = 1; 28 | L[2, 1] = lb_ub_lp(raw[cnt], lb[cnt], ub[cnt]); 29 | L[2, 2] = sqrt(1 - L[2, 1] ^ 2); 30 | cnt += 1; 31 | 32 | if (res_index[res_row, 1] == 2) { 33 | x_cache[res_id[res_row]] = L[2, 1]; 34 | res_id_cnt[res_id[res_row]] += 1; 35 | res_row += 1; 36 | } 37 | 38 | for (i in 3 : K) { 39 | if (res_index[res_row, 1] == i && res_index[res_row, 2] == 1) { 40 | if (res_id_cnt[res_id[res_row]] == 1) { 41 | L[i, 1] = lb_ub_lp(raw[cnt], lb[cnt], ub[cnt]); 42 | x_cache[res_id[res_row]] = L[i, 1]; 43 | res_id_cnt[res_id[res_row]] += 1; 44 | cnt += 1; 45 | } else { 46 | L[i, 1] = x_cache[res_id[res_row]]; 47 | } 48 | res_row += 1; 49 | } else { 50 | L[i, 1] = lb_ub_lp(raw[cnt], lb[cnt], ub[cnt]); 51 | cnt += 1; 52 | } 53 | 54 | L[i, 2] = sqrt(1 - L[i, 1] ^ 2); 55 | real l_ij_old = log1m(L[i, 1] ^ 2); 56 | for (j in 2 : i - 1) { 57 | real b1 = dot_product(L[j, 1 : (j - 1)], L[i, 1 : (j - 1)]); 58 | real stick_length = exp(0.5 * l_ij_old); 59 | real low = max({-stick_length, (lb[cnt] - b1) / L[j, j]}); 60 | real up = min({stick_length, (ub[cnt] - b1) / L[j, j]}); 61 | 62 | if (res_index[res_row, 1] == i && res_index[res_row, 2] == j) { 63 | if (res_id_cnt[res_id[res_row]] == 1) { 64 | L[i, j] = lb_ub_lp(raw[cnt], low, up); 65 | x_cache[res_id[res_row]] = L[i, j] * L[j, j] + b1; 66 | res_id_cnt[res_id[res_row]] += 1; 67 | cnt += 1; 68 | } else { 69 | L[i, j] = (x_cache[res_id[res_row]] - b1) / L[j, j]; 70 | target += -log(L[j, j]); 71 | } 72 | res_row = res_row == N_res ? N_res : res_row + 1; 73 | } else { 74 | L[i, j] = lb_ub_lp(raw[cnt], low, up); 75 | cnt += 1; 76 | } 77 | l_ij_old = log_diff_exp(l_ij_old, 2 * log(abs(L[i, j]))); 78 | } 79 | L[i, i] = exp(0.5 * l_ij_old); 80 | } 81 | return L; 82 | } 83 | } 84 | 85 | data{ 86 | //# Array dimension variables 87 | int N_responses; //# Number of outcome networks 88 | 89 | //# Dyadic reciprocity control parameters 90 | real eta; 91 | int N_dr_params; 92 | int N_dr_indices; 93 | int N_dr_bindings; 94 | array[N_dr_indices, 2] int dr_indices; 95 | array[N_dr_indices] int dr_id; 96 | } 97 | 98 | transformed data{ 99 | //# Dyadic reciprocity control parameters 100 | int N_off_diag = ((2*N_responses) * ((2*N_responses) - 1)) %/% 2; 101 | vector[N_off_diag] lb; 102 | vector[N_off_diag] ub; 103 | 104 | //# Dyadic reciprocity control parameters 105 | lb = rep_vector(-1, N_off_diag); 106 | ub = rep_vector(1, N_off_diag); 107 | } 108 | 109 | parameters{ 110 | vector[N_dr_params] dr_par_set; 111 | } 112 | 113 | transformed parameters{ 114 | matrix[2*N_responses, 2*N_responses] dr_L = cholesky_corr_constrain_lp(2*N_responses, dr_par_set, N_dr_bindings, dr_indices, dr_id, lb, ub); 115 | } 116 | 117 | model{ 118 | //# Dyadic priors for social relations model 119 | dr_L ~ lkj_corr_cholesky(eta); 120 | } 121 | 122 | generated quantities { 123 | matrix[2*N_responses, 2*N_responses] D_corr; 124 | D_corr = multiply_lower_tri_self_transpose(dr_L); 125 | } 126 | -------------------------------------------------------------------------------- /inst/generate_structured_correlation_matrix_l2norm.stan: -------------------------------------------------------------------------------- 1 | data{ 2 | int N_responses; //# number of outcome layers 3 | int setting; //# setting = 1 for multiplex dr, setting = 2 for longitudinal dr, setting = 3 for longitudinal gr 4 | real bandage_penalty; //# stitching strength 5 | real eta; //# prior 6 | } 7 | 8 | parameters{ 9 | cholesky_factor_corr[2*N_responses] dr_L; 10 | } 11 | 12 | transformed parameters{ 13 | matrix[2*N_responses, 2*N_responses] D_corr; 14 | D_corr = tcrossprod(dr_L); 15 | } 16 | 17 | model{ 18 | //# Stitch together the dyadic matrix 19 | if(setting<3){ 20 | for(m in 1:(N_responses-1)){ 21 | for(n in (m+1):N_responses){ 22 | target += normal_lpdf(D_corr[m+N_responses, n+N_responses] | D_corr[m, n], bandage_penalty); 23 | target += normal_lpdf(D_corr[m, n+N_responses] | D_corr[n, m+N_responses], bandage_penalty); 24 | }} 25 | } 26 | 27 | //# Add stitches to the dyadic matrix for longitudinal symmetries 28 | if(setting==2){ 29 | for(k in 1:(N_responses-1)){ 30 | for(m in 1:(N_responses-k)){ 31 | target += normal_lpdf(D_corr[m, m+k] | D_corr[1, k+1], bandage_penalty); 32 | target += normal_lpdf(D_corr[m, N_responses+m+k] | D_corr[1, N_responses+k+1], bandage_penalty); 33 | } 34 | } 35 | 36 | for(m in 1:N_responses){ 37 | target += normal_lpdf(D_corr[m, m+N_responses] | D_corr[1, N_responses+1], bandage_penalty); 38 | } 39 | } 40 | 41 | //# Add stitches to the generalized matrix for longitudinal symmetries 42 | if(setting==3){ 43 | for(k in 1:(N_responses-1)){ 44 | for(m in 1:(N_responses-k)){ 45 | target += normal_lpdf(D_corr[m, m+k] | D_corr[1, k+1], bandage_penalty); 46 | target += normal_lpdf(D_corr[m, N_responses+m+k] | D_corr[1, N_responses+k+1], bandage_penalty); 47 | target += normal_lpdf(D_corr[N_responses + m, N_responses + m+k] | D_corr[N_responses + 1, N_responses + k+1], bandage_penalty); 48 | target += normal_lpdf(D_corr[m + k, N_responses + m] | D_corr[k + 1, N_responses + 1], bandage_penalty); 49 | }} 50 | 51 | for(m in 1:N_responses){ 52 | target += normal_lpdf(D_corr[m, m+N_responses] | D_corr[1, N_responses+1], bandage_penalty); 53 | } 54 | } 55 | 56 | dr_L ~ lkj_corr_cholesky(eta); 57 | } 58 | -------------------------------------------------------------------------------- /logos/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo.gif -------------------------------------------------------------------------------- /logos/logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo1.png -------------------------------------------------------------------------------- /logos/logo10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo10.png -------------------------------------------------------------------------------- /logos/logo11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo11.png -------------------------------------------------------------------------------- /logos/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo2.png -------------------------------------------------------------------------------- /logos/logo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo3.png -------------------------------------------------------------------------------- /logos/logo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo4.png -------------------------------------------------------------------------------- /logos/logo5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo5.png -------------------------------------------------------------------------------- /logos/logo6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo6.png -------------------------------------------------------------------------------- /logos/logo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo7.png -------------------------------------------------------------------------------- /logos/logo8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo8.png -------------------------------------------------------------------------------- /logos/logo9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctross/STRAND/9528310209afd24d13ec346f9e5124e0574e585e/logos/logo9.png -------------------------------------------------------------------------------- /man/AMENDS_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AMENDS_Data.R 3 | \docType{data} 4 | \name{AMENDS_Data} 5 | \alias{AMENDS_Data} 6 | \title{Friendship and sharing network data from a rural Colombian population} 7 | \format{ 8 | An object of class \code{"list"}. 9 | } 10 | \source{ 11 | \href{https://www.eva.mpg.de/ecology/fieldwork/afrocolombians}{EVA} 12 | } 13 | \usage{ 14 | data(AMENDS_Data) 15 | } 16 | \description{ 17 | Data on friendship nominations, sharing ties, relatedness, age, sex, wealth, and ethnicity. 18 | } 19 | \examples{ 20 | data(AMENDS_Data) 21 | } 22 | \references{ 23 | Ross, CT., and Pisor, A. 24 | 2024. Perceived inequality and variability in the expression of parochial altruism. 25 | Evolutionary Human Sciences. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/Baboon_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Baboon_Data.R 3 | \docType{data} 4 | \name{Baboon_Data} 5 | \alias{Baboon_Data} 6 | \title{Data on Baboon grooming relationships} 7 | \format{ 8 | An object of class \code{"list"}. N individuals = 19. The list contains three matrices (of dimension 19x19) containing data on Grooming, Presenting, and Threatening behaviours, hand-coded from focal follows. 9 | An Exposure matrix gives the count of times in which individual i could have been observed engaging in a given behaviour towards individual j. Finally, there are covariate data on Sex and Age. 10 | } 11 | \source{ 12 | \href{http://dx.doi.org/10.1098/rspa.2019.0737}{RSPA} 13 | } 14 | \usage{ 15 | data(Baboon_Data) 16 | } 17 | \description{ 18 | Data on grooming paired with additional covariate data. See the reference to the original study below for full methodological information. 19 | } 20 | \examples{ 21 | data(Baboon_Data) 22 | } 23 | \references{ 24 | Gelardi V, Godard J, Paleressompoulle D, Claidiere N, Barrat A. 2020. 25 | Measuring social networks in primates: Wearable sensors versus direct observations. 26 | Proc. R. Soc. A 476: 20190737. 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/Baboon_Longitudinal_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Baboon_Longitudinal_Data.R 3 | \docType{data} 4 | \name{Baboon_Longitudinal_Data} 5 | \alias{Baboon_Longitudinal_Data} 6 | \title{Data on Baboon grooming, resting, and playing relationships} 7 | \format{ 8 | An object of class \code{"list"}. N individuals = 19. The list contains four tensors (of dimension 19x19X14) containing data on grooming, resting, and playing behaviours, hand-coded from focal follows for 28 days. Each time-step is a two-day period. 9 | An exposure tensor gives the count of times in which individual i could have been observed engaging in a given behaviour towards individual j on time-step t. Finally, there are covariate data on sex and age. 10 | } 11 | \source{ 12 | \href{http://dx.doi.org/10.1098/rspa.2019.0737}{RSPA} 13 | } 14 | \usage{ 15 | data(Baboon_Longitudinal_Data) 16 | } 17 | \description{ 18 | Data on grooming, resting, and playing paired with additional covariate data. See the reference to the original study below for full methodological information. 19 | } 20 | \examples{ 21 | data(Baboon_Longitudinal_Data) 22 | } 23 | \references{ 24 | Gelardi V, Godard J, Paleressompoulle D, Claidiere N, Barrat A. 2020. 25 | Measuring social networks in primates: Wearable sensors versus direct observations. 26 | Proc. R. Soc. A 476: 20190737. 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/Bat_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Bat_Data.R 3 | \docType{data} 4 | \name{Bat_Data} 5 | \alias{Bat_Data} 6 | \title{Blood sharing data in vampire bats} 7 | \format{ 8 | An object of class \code{"list"}. N individuals = 19. The list contains three matrices (of dimension 19x19) containing data on licking duration, relatedness, and opportunity to be observed. 9 | Finally, there is covariate data on Sex. 10 | } 11 | \source{ 12 | \href{http://dx.doi.org/10.1098/rspb.2012.2573}{RSPB} 13 | } 14 | \usage{ 15 | data(Bat_Data) 16 | } 17 | \description{ 18 | Data on blood sharing observations. Kinship data is based on SPAGeDi software estimates from the authors STR data. See the reference to the original study below for full methodological information. 19 | } 20 | \examples{ 21 | data(Bat_Data) 22 | } 23 | \references{ 24 | Carter GG, Wilkinson GS. 25 | 2013. Food sharing in vampire bats: reciprocal help predicts donations more than relatedness or harassment. 26 | Proc R Soc B 280: 20122573. 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/CES.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CES.R 3 | \name{CES} 4 | \alias{CES} 5 | \title{A function to compute the CES function} 6 | \usage{ 7 | CES(K, L, alpha, sigma, eta, nudge = TRUE) 8 | } 9 | \arguments{ 10 | \item{K}{Value of input 1.} 11 | 12 | \item{L}{Value of input 2.} 13 | 14 | \item{alpha}{Share parameter of input 1.} 15 | 16 | \item{sigma}{Elasticity of substitution.} 17 | 18 | \item{eta}{Returns to scale.} 19 | 20 | \item{nudge}{If TRUE, then nudge sigma such that sigma=1 is interpetable.} 21 | } 22 | \value{ 23 | CES(K,L) 24 | } 25 | \description{ 26 | See Constant elasticity of substitution from Wikipedia 27 | } 28 | -------------------------------------------------------------------------------- /man/Callithrix_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Callithrix_Data.R 3 | \docType{data} 4 | \name{Callithrix_Data} 5 | \alias{Callithrix_Data} 6 | \title{Data on Callithrix aggression} 7 | \format{ 8 | An object of class \code{"list"}. This data object contains a subset of data from the original publication. The first sub-list contains data from the C-, or low food, condition. 9 | The second sub-list contains data from the S++, or high food, condition. Both sub-lists contain data on dyadic aggression, normalized directed rank difference, opportunity to be observed, and sex. 10 | } 11 | \source{ 12 | \href{https://doi.org/10.5061/dryad.7pvmcvdtn}{Dryad} 13 | } 14 | \usage{ 15 | data(Callithrix_Data) 16 | } 17 | \description{ 18 | Foraging networks and social tolerance in a cooperatively breeding primate (Callithrix jacchus). See the reference to the original study below for full methodological information. 19 | } 20 | \examples{ 21 | data(Callithrix_Data) 22 | } 23 | \references{ 24 | De la Fuente, María Fernanda et al. (2021), Foraging networks and social tolerance in a cooperatively breeding primate (Callithrix jacchus), Dryad, Dataset. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/Colombia_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Colombia_Data.R 3 | \docType{data} 4 | \name{Colombia_Data} 5 | \alias{Colombia_Data} 6 | \title{Friendship data from a rural Colombian population} 7 | \format{ 8 | An object of class \code{"list"}. 9 | } 10 | \source{ 11 | \href{https://www.eva.mpg.de/ecology/fieldwork/afrocolombians}{EVA} 12 | } 13 | \usage{ 14 | data(Colombia_Data) 15 | } 16 | \description{ 17 | Data on friendship nominations paired with covariate data. 18 | } 19 | \examples{ 20 | data(Colombia_Data) 21 | } 22 | \references{ 23 | Dalla Ragione, A., Ross, CT., and Redhead, DJ. 24 | 2022. Friendship and partner choice in rural Colombia. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/FoodSharing_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FoodSharing_Data.R 3 | \docType{data} 4 | \name{FoodSharing_Data} 5 | \alias{FoodSharing_Data} 6 | \title{Food and Money sharing data from a rural Colombian population} 7 | \format{ 8 | An object of class \code{"list"}. 9 | } 10 | \source{ 11 | \href{https://doi.org/10.1098/rsos.192090}{RSOS} 12 | } 13 | \usage{ 14 | data(FoodSharing_Data) 15 | } 16 | \description{ 17 | Self-report data on transfers, double-sampled, paired with covariate data. 18 | } 19 | \examples{ 20 | data(FoodSharing_Data) 21 | } 22 | \references{ 23 | Anne C. Pisor, Matthew M. Gervais, Benjamin G. Purzycki, and Cody T. Ross. 2020. 24 | Preferences and constraints: the value of economic games for studying human behaviour 25 | Royal Society Open Science. Volume 7, Issue 6. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/HPDI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HPDI.R 3 | \name{HPDI} 4 | \alias{HPDI} 5 | \title{A function to get Highest Posterior Density Interval} 6 | \usage{ 7 | HPDI(samples, prob = 0.89) 8 | } 9 | \arguments{ 10 | \item{samples}{A vector of samples to summarize.} 11 | 12 | \item{prob}{Interval range.} 13 | } 14 | \value{ 15 | A vector of intervals. 16 | } 17 | \description{ 18 | This is a simple helper function to get density intervals. See McElreaths Rethinking for details. 19 | } 20 | -------------------------------------------------------------------------------- /man/RICH_Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RICH_Data.R 3 | \docType{data} 4 | \name{RICH_Data} 5 | \alias{RICH_Data} 6 | \title{Data on RICH games from Colombia} 7 | \format{ 8 | An object of class \code{"list"}. N individuals = 93. The list contains three outcome matrices (of dimension 93 x 93) containing data on giving, taking, and reducing behaviours. 9 | } 10 | \source{ 11 | \href{http://dx.doi.org/}{Working paper} 12 | } 13 | \usage{ 14 | data(RICH_Data) 15 | } 16 | \description{ 17 | Data on network-structured economic games with additional covariate data. These data have been rescaled, and some missing values were imputed using the mode or median. See the reference to the original study below for full methodological information. 18 | } 19 | \examples{ 20 | data(RICH_Data) 21 | } 22 | \references{ 23 | Ross and Pisor, 2024. 24 | Perceived inequality and variability in the expression of parochial altruism 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/STRAND-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/STRAND-package.R 3 | \docType{package} 4 | \name{STRAND-package} 5 | \alias{STRAND} 6 | \alias{STRAND-package} 7 | \title{STRAND: Social network analysis and simulation in R using Stan} 8 | \description{ 9 | The STRAND package provides four categories of important functions: 10 | network simulation functions, network analysis functions, summary functions, and results visualization functions. 11 | } 12 | \details{ 13 | If you use STRAND, please cite us: 14 | 15 | Ross, C. T., McElreath, R., and Redhead, D. (2024). Modelling animal network data in R using STRAND. Journal of Animal Ecology, 93(3), 254-266. 16 | 17 | Redhead, D., McElreath, R., and Ross, C. T. (2023). Reliable network inference from unreliable data: A tutorial on latent network modeling using STRAND. Psychological methods. 18 | } 19 | \section{Network simulation functions}{ 20 | 21 | The package can be used to simulate network data under stochastic block models, social relations models, and latent network models. 22 | These tools allow for simulation not only of realistic human social networks, but also allow researchers to simulate the effects of 23 | potential biases—like respondents falsely reporting ties or failing to recall real ties—on network level properties. 24 | } 25 | 26 | \section{Network analysis functions}{ 27 | 28 | Users can specify complex Bayesian social network models using simple lm() style syntax. 29 | Single-sampled self report data can be modeled using stochastic block models or the social relations model, with or with-out covariates. 30 | Double-sampled network data can be modeled using a latent network approach that accounts for inter-respondent disagreement. 31 | } 32 | 33 | \section{Summary functions}{ 34 | 35 | Users can summarize Stan results into tables with a simple interface. 36 | } 37 | 38 | \section{Visualization functions}{ 39 | 40 | Users can visualize Stan results with a simple interface. 41 | } 42 | 43 | \seealso{ 44 | Useful links: 45 | \itemize{ 46 | \item \url{https://github.com/ctross/STRAND} 47 | \item Report bugs at \url{https://github.com/ctross/STRAND/issues} 48 | } 49 | 50 | } 51 | \author{ 52 | \strong{Maintainer}: Cody Ross \email{ctross@ucdavis.edu} 53 | 54 | } 55 | \keyword{internal} 56 | -------------------------------------------------------------------------------- /man/STRAND.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/STRAND.R 3 | \docType{package} 4 | \name{STRAND} 5 | \alias{STRAND} 6 | \title{STRAND: Social network analysis and simulation in R using Stan} 7 | \description{ 8 | The STRAND package provides three categories of important functions: 9 | network simulation functions, network analysis functions, and summary functions 10 | } 11 | \section{Network simulation functions}{ 12 | 13 | The package can be used to simulate network data under stochastic block models, social relations models, and latent network models. 14 | These tools allow for simulation not only of realistic human social networks, but also allow researchers to simulate the effects of 15 | potential biases—like respondents falsely reporting ties or failing to recall real ties—on network level properties. 16 | } 17 | 18 | \section{Network analysis functions}{ 19 | 20 | Users can specify complex Bayesian social network models using simple lm() style syntax. 21 | Single-sampled self report data can be modeled using stochastic block models or the social relations model, with or with-out covariates. 22 | Double-sampled network data can be modeled using a latent network approach that accounts for inter-respondent disagreement. 23 | } 24 | 25 | \section{Summary functions}{ 26 | 27 | Users can summarize and visualize Stan results with a simple interface. 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/bayesian_p.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_p.R 3 | \name{bayesian_p} 4 | \alias{bayesian_p} 5 | \title{A function to calculate prob of sign error, or Bayesian p value} 6 | \usage{ 7 | bayesian_p(x) 8 | } 9 | \arguments{ 10 | \item{x}{value} 11 | } 12 | \value{ 13 | bayesian_p(x) 14 | } 15 | \description{ 16 | A function to calculate prob of sign error, or Bayesian p value 17 | } 18 | -------------------------------------------------------------------------------- /man/build_multiplex_bindings_dr_longitudinal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/build_multiplex_bindings_dr_longitudinal.R 3 | \name{build_multiplex_bindings_dr_longitudinal} 4 | \alias{build_multiplex_bindings_dr_longitudinal} 5 | \title{A function to add accesssory data to a STRAND data object for use in longitudinal analysis} 6 | \usage{ 7 | build_multiplex_bindings_dr_longitudinal(data, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{A STRAND data object.} 11 | 12 | \item{verbose}{If TRUE, then print structure of dyadic reciprocity matrix.} 13 | } 14 | \value{ 15 | A STRAND data object with extra information about the structure of the dyadic reciprocity matrix. 16 | } 17 | \description{ 18 | This is an internal function. 19 | } 20 | -------------------------------------------------------------------------------- /man/build_multiplex_bindings_dr_multiplex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/build_multiplex_bindings_dr_multiplex.R 3 | \name{build_multiplex_bindings_dr_multiplex} 4 | \alias{build_multiplex_bindings_dr_multiplex} 5 | \title{A function to add accesssory data to a STRAND data object for use in multiplex analysis} 6 | \usage{ 7 | build_multiplex_bindings_dr_multiplex(data, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{A STRAND data object.} 11 | 12 | \item{verbose}{If TRUE, then print structure of dyadic reciprocity matrix.} 13 | } 14 | \value{ 15 | A STRAND data object with extra information about the structure of the dyadic reciprocity matrix. 16 | } 17 | \description{ 18 | This is an internal function. 19 | } 20 | -------------------------------------------------------------------------------- /man/build_multiplex_bindings_sr_longitudinal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/build_multiplex_bindings_sr_longitudinal.R 3 | \name{build_multiplex_bindings_sr_longitudinal} 4 | \alias{build_multiplex_bindings_sr_longitudinal} 5 | \title{A function to add accesssory data to a STRAND data object for use in longitudinal analysis} 6 | \usage{ 7 | build_multiplex_bindings_sr_longitudinal(data, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{A STRAND data object.} 11 | 12 | \item{verbose}{If TRUE, then print structure of generalized reciprocity matrix.} 13 | } 14 | \value{ 15 | A STRAND data object with extra information about the structure of the generalized reciprocity matrix. 16 | } 17 | \description{ 18 | This is an internal function. 19 | } 20 | -------------------------------------------------------------------------------- /man/center.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/center.R 3 | \name{center} 4 | \alias{center} 5 | \title{A function to mean center data} 6 | \usage{ 7 | center(input) 8 | } 9 | \arguments{ 10 | \item{input}{A vector of data to center.} 11 | } 12 | \value{ 13 | A vector of centered data. 14 | } 15 | \description{ 16 | This is a simple helper function to mean center data. We recommmend to mean center covariates as it makes parameter interpretation easier. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | age_centered = center(input=age) 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/colMaxs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colMaxs.R 3 | \name{colMaxs} 4 | \alias{colMaxs} 5 | \title{A function to compute the max by col} 6 | \usage{ 7 | colMaxs(x, margin = 2) 8 | } 9 | \arguments{ 10 | \item{x}{Input array.} 11 | 12 | \item{margin}{Margin.} 13 | } 14 | \value{ 15 | colMaxs(x, margin) 16 | } 17 | \description{ 18 | Simpler helper function. 19 | } 20 | -------------------------------------------------------------------------------- /man/colMins.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colMins.R 3 | \name{colMins} 4 | \alias{colMins} 5 | \title{A function to compute the min by col} 6 | \usage{ 7 | colMins(x, margin = 2) 8 | } 9 | \arguments{ 10 | \item{x}{Input array.} 11 | 12 | \item{margin}{Margin.} 13 | } 14 | \value{ 15 | colMins(x, margin) 16 | } 17 | \description{ 18 | Simpler helper function. 19 | } 20 | -------------------------------------------------------------------------------- /man/dot-onAttach.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load.R 3 | \name{.onAttach} 4 | \alias{.onAttach} 5 | \title{A function to load some data when the package opens.} 6 | \usage{ 7 | .onAttach(libname = NULL, pkgname = "STRAND") 8 | } 9 | \arguments{ 10 | \item{libname}{Library name.} 11 | 12 | \item{pkgname}{Package name.} 13 | } 14 | \description{ 15 | A function to load some data when the package opens. 16 | } 17 | -------------------------------------------------------------------------------- /man/fit_NBDA_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_NBDA_model.R 3 | \name{fit_NBDA_model} 4 | \alias{fit_NBDA_model} 5 | \title{A function to run a network-based diffusion analysis using the STRAND framework} 6 | \usage{ 7 | fit_NBDA_model( 8 | long_data, 9 | individual_focal_regression, 10 | social_block_regression, 11 | social_focal_regression, 12 | social_target_regression, 13 | social_dyad_regression, 14 | mode = "mcmc", 15 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 16 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 17 | init = NULL), 18 | priors = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{long_data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates and trait diffusion data used in the formulas listed below.} 23 | 24 | \item{individual_focal_regression}{A formula for the effects of focal predictors on individual learning rate. This should be specified as in lm(), e.g.: ~ Age * Education.} 25 | 26 | \item{social_block_regression}{A formula for the block-level predictors of social attention weights. This should be specified as in lm(), e.g.: ~ Group + Sex. Dont use interactions, however.} 27 | 28 | \item{social_focal_regression}{A formula for the effects of focal predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 29 | 30 | \item{social_target_regression}{A formula for the effects of target predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 31 | 32 | \item{social_dyad_regression}{A formula for the predictors of dyadic relationships on social attention weights. This should be specified as in lm(), e.g.: ~ Kinship + Friendship.} 33 | 34 | \item{mode}{A string giving the mode that 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 35 | 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, 36 | 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.} 37 | 38 | \item{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) 39 | 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.} 40 | 41 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 42 | } 43 | \value{ 44 | A STRAND model object containing the data used, and the Stan results. 45 | } 46 | \description{ 47 | This function allows users to analyse empirical or simulated data using a NBDA model in Stan. The user must supply a list of STRAND data objects, 48 | and a series of formulas following standard lm() style syntax. 49 | } 50 | \examples{ 51 | \dontrun{ 52 | fit = fit_NBDA_model(long_data=model_dat, 53 | individual_focal_regression = ~ Age * NoFood, 54 | social_block_regression = ~ Ethnicity, 55 | social_focal_regression = ~ Age * NoFood, 56 | social_target_regression = ~ Age * NoFood, 57 | social_dyad_regression = ~ Relatedness + Friends * SameSex, 58 | mode="mcmc", 59 | stan_mcmc_parameters = list(seed = 1, chains = 1, 60 | parallel_chains = 1, refresh = 1, 61 | iter_warmup = 100, iter_sampling = 100, 62 | max_treedepth = NULL, adapt_delta = NULL) 63 | ) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /man/fit_block_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_block_model.R 3 | \name{fit_block_model} 4 | \alias{fit_block_model} 5 | \title{A function to run stochastic block models using the STRAND framework} 6 | \usage{ 7 | fit_block_model( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression, 13 | mode = "mcmc", 14 | return_predicted_network = FALSE, 15 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 16 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 17 | init = NULL), 18 | priors = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{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.} 23 | 24 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 25 | 26 | \item{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} 27 | 28 | \item{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} 29 | 30 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 31 | 32 | \item{mode}{A string giving the mode that 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 33 | 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, 34 | 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.} 35 | 36 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 37 | 38 | \item{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) 39 | 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.} 40 | 41 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 42 | } 43 | \value{ 44 | A STRAND model object containing the data used, and the Stan results. 45 | } 46 | \description{ 47 | This function allows users to analyse empirical or simulated data using a Bayesian stochastic block model in Stan. The user must supply a STRAND data object, 48 | and a series of formulas following standard lm() style syntax. 49 | } 50 | \details{ 51 | 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. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | fit = fit_block_model( data=model_dat, 56 | block_regression = ~ Ethnicity, 57 | focal_regression = ~ Age * NoFood, 58 | target_regression = ~ Age * NoFood, 59 | dyad_regression = ~ Relatedness + Friends * SameSex, 60 | mode="mcmc", 61 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, 62 | refresh = 1, iter_warmup = 100, iter_sampling = 100, 63 | max_treedepth = NULL, adapt_delta = NULL) 64 | ) 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/fit_block_plus_social_relations_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_block_plus_srm_model.R 3 | \name{fit_block_plus_social_relations_model} 4 | \alias{fit_block_plus_social_relations_model} 5 | \title{A function to run combined stochastic block and social relations models using the STRAND framework} 6 | \usage{ 7 | fit_block_plus_social_relations_model( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression, 13 | mode = "mcmc", 14 | return_predicted_network = FALSE, 15 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 16 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 17 | init = NULL), 18 | priors = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{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.} 23 | 24 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 25 | 26 | \item{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} 27 | 28 | \item{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} 29 | 30 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 31 | 32 | \item{mode}{A string giving the mode that 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 33 | 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, 34 | 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.} 35 | 36 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 37 | 38 | \item{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) 39 | 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.} 40 | 41 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 42 | } 43 | \value{ 44 | A STRAND model object containing the data used, and the Stan results. 45 | } 46 | \description{ 47 | This function allows users to analyse empirical or simulated data using a Bayesian stochastic block and social relations model in Stan. The user must supply a STRAND data object, 48 | and a series of formulas following standard lm() style syntax. 49 | } 50 | \details{ 51 | 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. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | fit = fit_block_plus_social_relations_model(data=model_dat, 56 | block_regression = ~ Ethnicity, 57 | focal_regression = ~ Age * NoFood, 58 | target_regression = ~ Age * NoFood, 59 | dyad_regression = ~ Relatedness + Friends * SameSex, 60 | mode="mcmc", 61 | stan_mcmc_parameters = list(seed = 1, chains = 1, 62 | parallel_chains = 1, refresh = 1, 63 | iter_warmup = 100, iter_sampling = 100, 64 | max_treedepth = NULL, adapt_delta = NULL) 65 | ) 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /man/fit_block_plus_social_relations_model_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_block_plus_srm_model_missings.R 3 | \name{fit_block_plus_social_relations_model_missings} 4 | \alias{fit_block_plus_social_relations_model_missings} 5 | \title{A function to run combined stochastic block and social relations models using the STRAND framework} 6 | \usage{ 7 | fit_block_plus_social_relations_model_missings( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression, 13 | mode = "mcmc", 14 | return_predicted_network = FALSE, 15 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 16 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 17 | init = NULL), 18 | priors = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{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.} 23 | 24 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 25 | 26 | \item{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} 27 | 28 | \item{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} 29 | 30 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 31 | 32 | \item{mode}{A string giving the mode that 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 33 | 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, 34 | 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.} 35 | 36 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 37 | 38 | \item{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) 39 | 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.} 40 | 41 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 42 | } 43 | \value{ 44 | A STRAND model object containing the data used, and the Stan results. 45 | } 46 | \description{ 47 | This function allows users to analyse empirical or simulated data using a Bayesian stochastic block and social relations model in Stan. The user must supply a STRAND data object, 48 | and a series of formulas following standard lm() style syntax. 49 | } 50 | \details{ 51 | 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. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | fit = fit_block_plus_social_relations_model_missings(data=model_dat, 56 | block_regression = ~ Ethnicity, 57 | focal_regression = ~ Age * NoFood, 58 | target_regression = ~ Age * NoFood, 59 | dyad_regression = ~ Relatedness + Friends * SameSex, 60 | mode="mcmc", 61 | stan_mcmc_parameters = list(seed = 1, chains = 1, 62 | parallel_chains = 1, refresh = 1, 63 | iter_warmup = 100, iter_sampling = 100, 64 | max_treedepth = NULL, adapt_delta = NULL) 65 | ) 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /man/fit_latent_network_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_latent_network_model.R 3 | \name{fit_latent_network_model} 4 | \alias{fit_latent_network_model} 5 | \title{A function to run latent network models using the STRAND framework} 6 | \usage{ 7 | fit_latent_network_model( 8 | data, 9 | fpr_regression, 10 | rtt_regression, 11 | theta_regression, 12 | block_regression, 13 | focal_regression, 14 | target_regression, 15 | dyad_regression, 16 | mode = "mcmc", 17 | return_predicted_network = FALSE, 18 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 19 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 20 | init = NULL), 21 | priors = NULL 22 | ) 23 | } 24 | \arguments{ 25 | \item{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.} 26 | 27 | \item{fpr_regression}{A formula for the predictors of false positive rate. Specified as in lm(), e.g.: ~ Age + Education} 28 | 29 | \item{rtt_regression}{A formula for the predictors of the recall rate of true ties. Specified as in lm(), e.g.: ~ Age + Education} 30 | 31 | \item{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} 32 | 33 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 34 | 35 | \item{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} 36 | 37 | \item{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} 38 | 39 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(),, e.g.: ~ Kinship + Friendship} 40 | 41 | \item{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 42 | 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, 43 | 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.} 44 | 45 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 46 | 47 | \item{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) 48 | 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.} 49 | 50 | \item{priors}{A labeled list of priors for the model. Only edits of the values are permitted. Distributions are fixed.} 51 | } 52 | \value{ 53 | A STRAND model object containing the data used, and the Stan results. 54 | } 55 | \description{ 56 | 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, 57 | and a series of formulas following standard lm() style syntax. 58 | } 59 | \details{ 60 | 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. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | fit = fit_latent_network_model(data=model_dat, 65 | fpr_regression = ~ Age + Education, 66 | rtt_regression = ~ Age + Education, 67 | theta_regression = ~ 1, 68 | block_regression = ~ Ethnicity, 69 | focal_regression = ~ Age * NoFood, 70 | target_regression = ~ Age * NoFood, 71 | dyad_regression = ~ Relatedness + Friends * SameSex, 72 | mode="mcmc", 73 | stan_mcmc_parameters = list(seed = 1, chains = 1, 74 | parallel_chains = 1, 75 | refresh = 1, iter_warmup = 100, iter_sampling = 100, 76 | max_treedepth = NULL, adapt_delta = NULL) 77 | ) 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /man/fit_latent_network_model_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_latent_network_model_missings.R 3 | \name{fit_latent_network_model_missings} 4 | \alias{fit_latent_network_model_missings} 5 | \title{A function to run latent network models using the STRAND framework} 6 | \usage{ 7 | fit_latent_network_model_missings( 8 | data, 9 | fpr_regression, 10 | rtt_regression, 11 | theta_regression, 12 | block_regression, 13 | focal_regression, 14 | target_regression, 15 | dyad_regression, 16 | mode = "mcmc", 17 | return_predicted_network = FALSE, 18 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 19 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 20 | init = NULL), 21 | priors = NULL 22 | ) 23 | } 24 | \arguments{ 25 | \item{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.} 26 | 27 | \item{fpr_regression}{A formula for the predictors of false positive rate. Specified as in lm(), e.g.: ~ Age + Education} 28 | 29 | \item{rtt_regression}{A formula for the predictors of the recall rate of true ties. Specified as in lm(), e.g.: ~ Age + Education} 30 | 31 | \item{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} 32 | 33 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 34 | 35 | \item{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} 36 | 37 | \item{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} 38 | 39 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(),, e.g.: ~ Kinship + Friendship} 40 | 41 | \item{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 42 | 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, 43 | 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.} 44 | 45 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 46 | 47 | \item{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) 48 | 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.} 49 | 50 | \item{priors}{A labeled list of priors for the model. Only edits of the values are permitted. Distributions are fixed.} 51 | } 52 | \value{ 53 | A STRAND model object containing the data used, and the Stan results. 54 | } 55 | \description{ 56 | 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, 57 | and a series of formulas following standard lm() style syntax. 58 | } 59 | \details{ 60 | 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. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | fit = fit_latent_network_model_missings(data=model_dat, 65 | fpr_regression = ~ Age + Education, 66 | rtt_regression = ~ Age + Education, 67 | theta_regression = ~ 1, 68 | block_regression = ~ Ethnicity, 69 | focal_regression = ~ Age * NoFood, 70 | target_regression = ~ Age * NoFood, 71 | dyad_regression = ~ Relatedness + Friends * SameSex, 72 | mode="mcmc", 73 | stan_mcmc_parameters = list(seed = 1, chains = 1, 74 | parallel_chains = 1, 75 | refresh = 1, iter_warmup = 100, iter_sampling = 100, 76 | max_treedepth = NULL, adapt_delta = NULL) 77 | ) 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /man/fit_multiplex_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_multiplex_model.R 3 | \name{fit_multiplex_model} 4 | \alias{fit_multiplex_model} 5 | \title{A function to apply combined a stochastic block and social relations model to multiplex networks using the STRAND framework} 6 | \usage{ 7 | fit_multiplex_model( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression, 13 | mode = "mcmc", 14 | bandage_penalty = 0.01, 15 | eta = 4, 16 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 17 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 18 | init = NULL), 19 | priors = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{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.} 24 | 25 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 26 | 27 | \item{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} 28 | 29 | \item{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} 30 | 31 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 32 | 33 | \item{mode}{A string giving the mode that 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 34 | 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, 35 | 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.} 36 | 37 | \item{bandage_penalty}{A parameter that controls how tightly stiched together correlation structure parameters are. Default is 0.01 for tight stiching of parameters that should be equal. Relaxing to 0.05, or 0.1 can sometimes aid model performance. Setting "bandage_penalty=-1" deploys a different Stan model, which fixes the dyadic matrix perfectly. You must set init=0 below, for this model to initialize.} 38 | 39 | \item{eta}{Prior on LKJ Cholesky factor, if bandage_penalty = -1.} 40 | 41 | \item{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) 42 | 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.} 43 | 44 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 45 | } 46 | \value{ 47 | A STRAND model object containing the data used, and the Stan results. 48 | } 49 | \description{ 50 | This function allows users to analyse empirical or simulated data using a Bayesian stochastic block and social relations model in Stan. The user must supply a STRAND data object, 51 | and a series of formulas following standard lm() style syntax. 52 | } 53 | \details{ 54 | It is important to note that all individual block (or group) assignment must be supplied as data. Latent blocks or groups will be supported in future releases of STRAND. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | fit = fit_multiplex_model(data=model_dat, 59 | block_regression = ~ Ethnicity, 60 | focal_regression = ~ Age * NoFood, 61 | target_regression = ~ Age * NoFood, 62 | dyad_regression = ~ Relatedness + Friends * SameSex, 63 | mode="mcmc", 64 | stan_mcmc_parameters = list(seed = 1, chains = 1, 65 | parallel_chains = 1, refresh = 1, 66 | iter_warmup = 100, iter_sampling = 100, 67 | max_treedepth = NULL, adapt_delta = NULL) 68 | ) 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /man/fit_multiplex_model_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_multiplex_model_missings.R 3 | \name{fit_multiplex_model_missings} 4 | \alias{fit_multiplex_model_missings} 5 | \title{A function to apply combined a stochastic block and social relations model to multiplex networks using the STRAND framework} 6 | \usage{ 7 | fit_multiplex_model_missings( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression, 13 | mode = "mcmc", 14 | bandage_penalty = 0.01, 15 | eta = 4, 16 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 17 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 18 | init = NULL), 19 | priors = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{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.} 24 | 25 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 26 | 27 | \item{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} 28 | 29 | \item{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} 30 | 31 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 32 | 33 | \item{mode}{A string giving the mode that 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 34 | 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, 35 | 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.} 36 | 37 | \item{bandage_penalty}{A parameter that controls how tightly stiched together correlation structure parameters are. Default is 0.01 for tight stiching of parameters that should be equal. Relaxing to 0.05, or 0.1 can sometimes aid model performance. Setting "bandage_penalty=-1" deploys a different Stan model, which fixes the dyadic matrix perfectly. You must set init=0 below, for this model to initialize.} 38 | 39 | \item{eta}{Prior on LKJ Cholesky factor, if bandage_penalty = -1.} 40 | 41 | \item{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) 42 | 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.} 43 | 44 | \item{priors}{A labeled list of priors for the model. User are only permitted to edit the values. Distributions are fixed.} 45 | } 46 | \value{ 47 | A STRAND model object containing the data used, and the Stan results. 48 | } 49 | \description{ 50 | This function allows users to analyse empirical or simulated data using a Bayesian stochastic block and social relations model in Stan. The user must supply a STRAND data object, 51 | and a series of formulas following standard lm() style syntax. 52 | } 53 | \details{ 54 | It is important to note that all individual block (or group) assignment must be supplied as data. Latent blocks or groups will be supported in future releases of STRAND. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | fit = fit_multiplex_model_missings(data=model_dat, 59 | block_regression = ~ Ethnicity, 60 | focal_regression = ~ Age * NoFood, 61 | target_regression = ~ Age * NoFood, 62 | dyad_regression = ~ Relatedness + Friends * SameSex, 63 | mode="mcmc", 64 | stan_mcmc_parameters = list(seed = 1, chains = 1, 65 | parallel_chains = 1, refresh = 1, 66 | iter_warmup = 100, iter_sampling = 100, 67 | max_treedepth = NULL, adapt_delta = NULL) 68 | ) 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /man/fit_social_relations_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_srm_model.R 3 | \name{fit_social_relations_model} 4 | \alias{fit_social_relations_model} 5 | \title{A function to run social relations models using the STRAND framework} 6 | \usage{ 7 | fit_social_relations_model( 8 | data, 9 | focal_regression, 10 | target_regression, 11 | dyad_regression, 12 | mode = "mcmc", 13 | return_predicted_network = FALSE, 14 | stan_mcmc_parameters = list(seed = 1, chains = 1, parallel_chains = 1, refresh = 1, 15 | iter_warmup = NULL, iter_sampling = NULL, max_treedepth = NULL, adapt_delta = NULL, 16 | init = NULL), 17 | priors = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{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.} 22 | 23 | \item{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} 24 | 25 | \item{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} 26 | 27 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(),, e.g.: ~ Kinship + Friendship} 28 | 29 | \item{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 30 | 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, 31 | 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.} 32 | 33 | \item{return_predicted_network}{Should predicted tie probabilities be returned? Requires large memory overhead, but can be used to check model fit.} 34 | 35 | \item{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) 36 | 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.} 37 | 38 | \item{priors}{A labeled list of priors for the model. Only edits of the values are permitted. Distributions are fixed.} 39 | } 40 | \value{ 41 | A STRAND model object containing the data used, and the Stan results. 42 | } 43 | \description{ 44 | This function allows users to analyse empirical or simulated data using a Bayesian social relations model in Stan. The user must supply a STRAND data object, 45 | and a series of formulas following standard lm() style syntax. 46 | } 47 | \examples{ 48 | \dontrun{ 49 | fit = fit_social_relations_model( data=model_dat, 50 | focal_regression = ~ Age * NoFood, 51 | target_regression = ~ Age * NoFood, 52 | dyad_regression = ~ Relatedness + Friends * SameSex, 53 | mode="mcmc", 54 | stan_mcmc_parameters = list(seed = 1, 55 | chains = 1, parallel_chains = 1, 56 | refresh = 1, iter_warmup = 100, iter_sampling = 100, 57 | max_treedepth = NULL, adapt_delta = NULL) 58 | ) 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /man/generate_structured_correlation_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generate_structured_correlation_matrix.R 3 | \name{generate_structured_correlation_matrix} 4 | \alias{generate_structured_correlation_matrix} 5 | \title{A function to generate correlation matrices with special inner symmetry} 6 | \usage{ 7 | generate_structured_correlation_matrix( 8 | data, 9 | eta, 10 | mode, 11 | setting, 12 | stan_mcmc_parameters 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{A data list.} 17 | 18 | \item{eta}{Prior on the LKJ Cholesky factor.} 19 | 20 | \item{mode}{Which method to use? "cholesky" or "l2norm".} 21 | 22 | \item{setting}{Which matrix to create? "multiplex_dyadic_reciprocity", "longitudinal_dyadic_reciprocity", or "longitudinal_generalized_reciprocity".} 23 | 24 | \item{stan_mcmc_parameters}{A list of Stan parameters that often need to be tuned.} 25 | } 26 | \value{ 27 | A Stan object. 28 | } 29 | \description{ 30 | This is an internal function. 31 | } 32 | -------------------------------------------------------------------------------- /man/inv_logit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inv_logit.R 3 | \name{inv_logit} 4 | \alias{inv_logit} 5 | \title{A function to take inverse logit} 6 | \usage{ 7 | inv_logit(x) 8 | } 9 | \arguments{ 10 | \item{x}{value} 11 | } 12 | \value{ 13 | inverse_logit(x) 14 | } 15 | \description{ 16 | See McElreaths Rethinking package for details 17 | } 18 | -------------------------------------------------------------------------------- /man/inv_logit_shifted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inv_logit_shifted.R 3 | \name{inv_logit_shifted} 4 | \alias{inv_logit_shifted} 5 | \title{A function to take inverse logit shifted} 6 | \usage{ 7 | inv_logit_shifted(x) 8 | } 9 | \arguments{ 10 | \item{x}{value} 11 | } 12 | \value{ 13 | inv_logit_shifted(x) 14 | } 15 | \description{ 16 | Map x from (0, inf) to (0, 1) 17 | } 18 | -------------------------------------------------------------------------------- /man/is_numeric_not_binary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_numeric_not_binary.R 3 | \name{is_numeric_not_binary} 4 | \alias{is_numeric_not_binary} 5 | \title{A function to check the data type} 6 | \usage{ 7 | is_numeric_not_binary(x) 8 | } 9 | \arguments{ 10 | \item{x}{value} 11 | } 12 | \value{ 13 | is_numeric_not_binary(x) 14 | } 15 | \description{ 16 | A function to check the data type 17 | } 18 | -------------------------------------------------------------------------------- /man/logit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/logit.R 3 | \name{logit} 4 | \alias{logit} 5 | \title{A function to take logit} 6 | \usage{ 7 | logit(x) 8 | } 9 | \arguments{ 10 | \item{x}{value} 11 | } 12 | \value{ 13 | logit(x) 14 | } 15 | \description{ 16 | See McElreaths Rethinking package for details. 17 | } 18 | -------------------------------------------------------------------------------- /man/longitudinal_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/longitudinal_plot.R 3 | \name{longitudinal_plot} 4 | \alias{longitudinal_plot} 5 | \title{Plot longitudinal random effects in time-lag form} 6 | \usage{ 7 | longitudinal_plot( 8 | input, 9 | type = "dyadic", 10 | mode = "cor", 11 | parameter_set, 12 | results, 13 | normalized = FALSE, 14 | HPDI = 0.9, 15 | plot = TRUE, 16 | export_as_table = FALSE, 17 | save_plot = NULL, 18 | height = 6, 19 | width = 6, 20 | palette = NULL 21 | ) 22 | } 23 | \arguments{ 24 | \item{input}{A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model.} 25 | 26 | \item{type}{Plot dyadic reciprocity ("dyadic") or generalized reciprocity ("generalized")?. Can use "custom", if the user passes in an appropriate data frame.} 27 | 28 | \item{mode}{For dyadic plots, should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj".} 29 | 30 | \item{parameter_set}{A labeled list of paramters to plot. E.g.: parameter_set = list(focal="Age", target="Age", focal="Sex", target="Sex", dyadic = "Relatedness"). The 31 | names must be focal, target, or dyadic, and the quoted text must be paramters given in the regression equations. E.g., focal_regression = ~ Age + Sex.} 32 | 33 | \item{results}{A results data.frame or matrix with colnames: c("Variable", "Layer", "Target" , "Base" , "Median", "L", "H", "Mean","SD","LayerNumeric")} 34 | 35 | \item{normalized}{Should effects be normalized? Only valid for type="coefficient".} 36 | 37 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 38 | 39 | \item{plot}{Should a plot be displayed?} 40 | 41 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 42 | 43 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 44 | 45 | \item{height}{Height of exported plot.} 46 | 47 | \item{width}{Width of exported plot.} 48 | 49 | \item{palette}{Override the default palette with a vector of color codes. "dyadic" need 3 colors, "generalized" needs 5 colors, and "coefficient" needs as many colors as supplied parameters.} 50 | } 51 | \value{ 52 | A figure or tabluar data to make a figure. 53 | } 54 | \description{ 55 | Plot longitudinal random effects in time-lag form 56 | } 57 | \examples{ 58 | \dontrun{ 59 | res = longitudinal_plot(input = fit) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /man/longitudinal_plot_b.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/longitudinal_plot_b.R 3 | \name{longitudinal_plot_b} 4 | \alias{longitudinal_plot_b} 5 | \title{Plot longitudinal random effects - dyadic reciprocity} 6 | \usage{ 7 | longitudinal_plot_b( 8 | input, 9 | results, 10 | plot = TRUE, 11 | save_plot = NULL, 12 | height = 6, 13 | width = 6, 14 | palette = NULL 15 | ) 16 | } 17 | \arguments{ 18 | \item{input}{A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model.} 19 | 20 | \item{results}{A results data.frame or matrix with colnames: c("Variable", "Layer", "Target" , "Base" , "Median", "L", "H", "Mean","SD","LayerNumeric", "P")} 21 | 22 | \item{plot}{Should a plot be displayed?} 23 | 24 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 25 | 26 | \item{height}{Height of exported plot.} 27 | 28 | \item{width}{Width of exported plot.} 29 | 30 | \item{palette}{Override the default palette with a 3-vector of color codes.} 31 | } 32 | \value{ 33 | A figure or tabluar data to make a figure. 34 | } 35 | \description{ 36 | Plot longitudinal random effects - dyadic reciprocity 37 | } 38 | -------------------------------------------------------------------------------- /man/longitudinal_plot_c.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/longitudinal_plot_c.R 3 | \name{longitudinal_plot_c} 4 | \alias{longitudinal_plot_c} 5 | \title{Plot longitudinal random effects - dyadic reciprocity} 6 | \usage{ 7 | longitudinal_plot_c( 8 | input, 9 | parameters, 10 | type, 11 | normalized = FALSE, 12 | HPDI = 0.9, 13 | plot = TRUE, 14 | export_as_table = FALSE, 15 | save_plot = NULL, 16 | height = 6, 17 | width = 6, 18 | palette = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{input}{A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model.} 23 | 24 | \item{parameters}{Name of the parameter as included in the function call. E.g., ~ Age + Sex... Then: parameters=c("Age", "Age", "Sex", "Sex")} 25 | 26 | \item{type}{For each parameter, indicate its type: "focal", "target", or "dyadic". And, from the above: type = =c("focal", "target", "focal", "target")} 27 | 28 | \item{normalized}{Should effects be normalized?} 29 | 30 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 31 | 32 | \item{plot}{Should a plot be displayed?} 33 | 34 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 35 | 36 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 37 | 38 | \item{height}{Height of exported plot.} 39 | 40 | \item{width}{Width of exported plot.} 41 | 42 | \item{palette}{Override the default palette with a 3-vector of color codes.} 43 | } 44 | \value{ 45 | A figure or tabluar data to make a figure. 46 | } 47 | \description{ 48 | Plot longitudinal random effects - dyadic reciprocity 49 | } 50 | \examples{ 51 | \dontrun{ 52 | res = longitudinal_plot_c(input = fit, parameters, type) 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /man/longitudinal_plot_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/longitudinal_plot_d.R 3 | \name{longitudinal_plot_d} 4 | \alias{longitudinal_plot_d} 5 | \title{Plot longitudinal random effects - dyadic reciprocity} 6 | \usage{ 7 | longitudinal_plot_d( 8 | input, 9 | HPDI = 0.9, 10 | mode = "cor", 11 | plot = TRUE, 12 | export_as_table = FALSE, 13 | save_plot = NULL, 14 | height = 6, 15 | width = 6, 16 | palette = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{input}{A STRAND model object, obtained by fitting a longitudinal combined stochastic block and social relations model.} 21 | 22 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 23 | 24 | \item{mode}{Should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj".} 25 | 26 | \item{plot}{Should a plot be displayed?} 27 | 28 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 29 | 30 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 31 | 32 | \item{height}{Height of exported plot.} 33 | 34 | \item{width}{Width of exported plot.} 35 | 36 | \item{palette}{Override the default palette with a 3-vector of color codes.} 37 | } 38 | \value{ 39 | A figure or tabluar data to make a figure. 40 | } 41 | \description{ 42 | Plot longitudinal random effects - dyadic reciprocity 43 | } 44 | \examples{ 45 | \dontrun{ 46 | res = longitudinal_plot_d(input = fit) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/longitudinal_plot_g.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/longitudinal_plot_g.R 3 | \name{longitudinal_plot_g} 4 | \alias{longitudinal_plot_g} 5 | \title{Plot multiplex random effects - generalized reciprocity} 6 | \usage{ 7 | longitudinal_plot_g( 8 | input, 9 | HPDI = 0.9, 10 | plot = TRUE, 11 | export_as_table = FALSE, 12 | save_plot = NULL, 13 | height = 6, 14 | width = 6, 15 | palette = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{input}{A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model.} 20 | 21 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 22 | 23 | \item{plot}{Should a plot be displayed?} 24 | 25 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 26 | 27 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 28 | 29 | \item{height}{Height of exported plot.} 30 | 31 | \item{width}{Width of exported plot.} 32 | 33 | \item{palette}{Override the default palette with a 3-vector of color codes.} 34 | } 35 | \value{ 36 | A figure or tabluar data to make a figure. 37 | } 38 | \description{ 39 | Plot multiplex random effects - generalized reciprocity 40 | } 41 | \examples{ 42 | \dontrun{ 43 | res = multiplex_plot_g(input = fit) 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/make_longitudinal_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_longitudinal_data.R 3 | \name{make_longitudinal_data} 4 | \alias{make_longitudinal_data} 5 | \title{An internal function to make a longitudinal data object using the STRAND framework} 6 | \usage{ 7 | make_longitudinal_data( 8 | long_data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression 13 | ) 14 | } 15 | \arguments{ 16 | \item{long_data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates used in the formulas listed below.} 17 | 18 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 19 | 20 | \item{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} 21 | 22 | \item{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} 23 | 24 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 25 | } 26 | \value{ 27 | A STRAND data object. 28 | } 29 | \description{ 30 | An internal function to make a longitudinal data object using the STRAND framework 31 | } 32 | \examples{ 33 | \dontrun{ 34 | fit = make_longitudinal_data(long_data, 35 | block_regression = ~ Ethnicity, 36 | focal_regression = ~ Age * NoFood, 37 | target_regression = ~ Age * NoFood, 38 | dyad_regression = ~ Relatedness + Friends * SameSex 39 | ) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/make_longitudinal_data_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_longitudinal_data_missings.R 3 | \name{make_longitudinal_data_missings} 4 | \alias{make_longitudinal_data_missings} 5 | \title{An internal function to make a longitudinal data object using the STRAND framework} 6 | \usage{ 7 | make_longitudinal_data_missings( 8 | long_data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression 13 | ) 14 | } 15 | \arguments{ 16 | \item{long_data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates used in the formulas listed below.} 17 | 18 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 19 | 20 | \item{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} 21 | 22 | \item{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} 23 | 24 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 25 | } 26 | \value{ 27 | A STRAND data object. 28 | } 29 | \description{ 30 | An internal function to make a longitudinal data object using the STRAND framework 31 | } 32 | \examples{ 33 | \dontrun{ 34 | fit = make_longitudinal_data_missings(long_data, 35 | block_regression = ~ Ethnicity, 36 | focal_regression = ~ Age * NoFood, 37 | target_regression = ~ Age * NoFood, 38 | dyad_regression = ~ Relatedness + Friends * SameSex 39 | ) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/make_priors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_priors.R 3 | \name{make_priors} 4 | \alias{make_priors} 5 | \title{A function to create priors for STRAND models} 6 | \usage{ 7 | make_priors(priors_to_change = NULL, include_rownames = FALSE) 8 | } 9 | \arguments{ 10 | \item{priors_to_change}{A named vector of priors to change. To get parameter names, run: make_priors(include_rownames=TRUE). Values must be 2-vectors. If the prior has only one parameter, inlcude 0 as the second element.} 11 | 12 | \item{include_rownames}{Should rownames be printed?} 13 | } 14 | \value{ 15 | A STRAND priors matrix. 16 | } 17 | \description{ 18 | This function allows users to change the numerical values of priors (but not their distributions). Users should only change these values if they have read and understood the source code. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | make_priors(priors_to_change=list(sr_L=5),include_rownames=TRUE) 23 | make_priors() 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/multiplex_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multiplex_plot.R 3 | \name{multiplex_plot} 4 | \alias{multiplex_plot} 5 | \title{Plot multiplex random effects in matrix form} 6 | \usage{ 7 | multiplex_plot( 8 | input, 9 | type = "dyadic", 10 | mode = "cor", 11 | HPDI = 0.9, 12 | plot = TRUE, 13 | export_as_table = FALSE, 14 | save_plot = NULL, 15 | height = 6, 16 | width = 6, 17 | palette = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{input}{A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model.} 22 | 23 | \item{type}{Plot dyadic reciprocity ("dyadic") or generalized reciprocity ("generalized")?.} 24 | 25 | \item{mode}{For dyadic plots, should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj".} 26 | 27 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 28 | 29 | \item{plot}{Should a plot be displayed?} 30 | 31 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 32 | 33 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 34 | 35 | \item{height}{Height of exported plot.} 36 | 37 | \item{width}{Width of exported plot.} 38 | 39 | \item{palette}{Override the default palette with a 3-vector of color codes.} 40 | } 41 | \value{ 42 | A figure or tabluar data to make a figure. 43 | } 44 | \description{ 45 | Plot multiplex random effects in matrix form 46 | } 47 | \examples{ 48 | \dontrun{ 49 | res = multiplex_plot(input = fit) 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /man/multiplex_plot_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multiplex_plot_d.R 3 | \name{multiplex_plot_d} 4 | \alias{multiplex_plot_d} 5 | \title{Plot multiplex random effects - dyadic reciprocity} 6 | \usage{ 7 | multiplex_plot_d( 8 | input, 9 | HPDI = 0.9, 10 | mode = "cor", 11 | plot = TRUE, 12 | export_as_table = FALSE, 13 | save_plot = NULL, 14 | height = 6, 15 | width = 6, 16 | palette = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{input}{A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model.} 21 | 22 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 23 | 24 | \item{mode}{Should the dyadic correlation "cor" be plotted, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj".} 25 | 26 | \item{plot}{Should a plot be displayed?} 27 | 28 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 29 | 30 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 31 | 32 | \item{height}{Height of exported plot.} 33 | 34 | \item{width}{Width of exported plot.} 35 | 36 | \item{palette}{Override the default palette with a 3-vector of color codes.} 37 | } 38 | \value{ 39 | A figure or tabluar data to make a figure. 40 | } 41 | \description{ 42 | Plot multiplex random effects - dyadic reciprocity 43 | } 44 | \examples{ 45 | \dontrun{ 46 | res = multiplex_plot_d(input = fit) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/multiplex_plot_g.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multiplex_plot_g.R 3 | \name{multiplex_plot_g} 4 | \alias{multiplex_plot_g} 5 | \title{Plot multiplex random effects - generalized reciprocity} 6 | \usage{ 7 | multiplex_plot_g( 8 | input, 9 | HPDI = 0.9, 10 | plot = TRUE, 11 | export_as_table = FALSE, 12 | save_plot = NULL, 13 | height = 6, 14 | width = 6, 15 | palette = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{input}{A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model.} 20 | 21 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 22 | 23 | \item{plot}{Should a plot be displayed?} 24 | 25 | \item{export_as_table}{Should the tabular data rather than a ggplot object be returned?} 26 | 27 | \item{save_plot}{Should a plot be exported to working directory? If so, set save_plot="desired_filename.pdf".} 28 | 29 | \item{height}{Height of exported plot.} 30 | 31 | \item{width}{Width of exported plot.} 32 | 33 | \item{palette}{Override the default palette with a 3-vector of color codes.} 34 | } 35 | \value{ 36 | A figure or tabluar data to make a figure. 37 | } 38 | \description{ 39 | Plot multiplex random effects - generalized reciprocity 40 | } 41 | \examples{ 42 | \dontrun{ 43 | res = multiplex_plot_g(input = fit) 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/parse_longitudinal_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_longitudinal_data.R 3 | \name{parse_longitudinal_data} 4 | \alias{parse_longitudinal_data} 5 | \title{An internal function to parse a list of STRAND data objects into a longitudinal object and then apply regression models.} 6 | \usage{ 7 | parse_longitudinal_data( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{A data objects of class STRAND, prepared using the make_strand_data() function. The data object must include all covariates used in the formulas of the fit_longitudinal_model function.} 17 | 18 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 19 | 20 | \item{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} 21 | 22 | \item{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} 23 | 24 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 25 | } 26 | \value{ 27 | A STRAND data object. 28 | } 29 | \description{ 30 | An internal function to parse a list of STRAND data objects into a longitudinal object and then apply regression models. 31 | } 32 | -------------------------------------------------------------------------------- /man/parse_longitudinal_data_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_longitudinal_data_missings.R 3 | \name{parse_longitudinal_data_missings} 4 | \alias{parse_longitudinal_data_missings} 5 | \title{An internal function to parse a list of STRAND data objects into a longitudinal object and then apply regression models.} 6 | \usage{ 7 | parse_longitudinal_data_missings( 8 | data, 9 | block_regression, 10 | focal_regression, 11 | target_regression, 12 | dyad_regression 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{A data objects of class STRAND, prepared using the make_strand_data() function. The data object must include all covariates used in the formulas of the fit_longitudinal_model function.} 17 | 18 | \item{block_regression}{A formula for the block-level predictors. This should be specified as in lm(), e.g.: ~ Ethnicity + Sex. Dont use interactions, however.} 19 | 20 | \item{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} 21 | 22 | \item{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} 23 | 24 | \item{dyad_regression}{A formula for the predictors of dyadic relationships. This should be specified as in lm(), e.g.: ~ Kinship + Friendship} 25 | } 26 | \value{ 27 | A STRAND data object. 28 | } 29 | \description{ 30 | An internal function to parse a list of STRAND data objects into a longitudinal object and then apply regression models. 31 | } 32 | -------------------------------------------------------------------------------- /man/plot_diffusion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_diffusion.R 3 | \name{plot_diffusion} 4 | \alias{plot_diffusion} 5 | \title{A function to simulate a network-based diffusion proccess using the STRAND framework} 6 | \usage{ 7 | plot_diffusion(long_data, palette = c("#13667B", "#35ABC0")) 8 | } 9 | \arguments{ 10 | \item{long_data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates and trait diffusion data used in the formulas listed below.} 11 | 12 | \item{palette}{A 2-vector of plot colors. First element is for the low value of scale, second is for the high value.} 13 | } 14 | \value{ 15 | A ggplot2 object. 16 | } 17 | \description{ 18 | This function allows users to simulate data using a NBDA model. The user must supply a list of STRAND data objects, a set of parameters, 19 | and a series of formulas following standard lm() style syntax. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | plot_diffusion(long_data) 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/process_block_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_block_parameters.R 3 | \name{process_block_parameters} 4 | \alias{process_block_parameters} 5 | \title{Calculate the contrast between two block estimates for each layer} 6 | \usage{ 7 | process_block_parameters(input, focal, base, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object} 11 | 12 | \item{focal}{The outcome of interest, will be of the form "X to Y", where X and Y are factor levels from the block model.} 13 | 14 | \item{base}{The base case, will be of the form "X to Y", where X and Y are factor levels from the block model.} 15 | 16 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 17 | } 18 | \value{ 19 | A matrix of output. 20 | } 21 | \description{ 22 | This is a helper function to compute contrast between samples 23 | } 24 | -------------------------------------------------------------------------------- /man/process_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_missings.R 3 | \name{process_missings} 4 | \alias{process_missings} 5 | \title{A function to compute relevant data on missings for Stan imputation} 6 | \usage{ 7 | process_missings(data) 8 | } 9 | \arguments{ 10 | \item{data}{A data object from make_strand_data after its proccessed by a model function call.} 11 | } 12 | \value{ 13 | process_missings(data) 14 | } 15 | \description{ 16 | Simpler helper function. 17 | } 18 | -------------------------------------------------------------------------------- /man/random_string.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/random_string.R 3 | \name{random_string} 4 | \alias{random_string} 5 | \title{A function to make random ID codes} 6 | \usage{ 7 | random_string(N = 1, length = 12) 8 | } 9 | \arguments{ 10 | \item{N}{Number of ID codes to generate.} 11 | 12 | \item{length}{Length of ID codes.} 13 | } 14 | \value{ 15 | A vector of unique ID codes. 16 | } 17 | \description{ 18 | This is a small helper function to create random ID codes. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | IDs = random_string(N=100, length=5) 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/rbern.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rbern.R 3 | \name{rbern} 4 | \alias{rbern} 5 | \title{A function to simulate Bernoulli data} 6 | \usage{ 7 | rbern(n, prob = 0.5) 8 | } 9 | \arguments{ 10 | \item{n}{Number of samples} 11 | 12 | \item{prob}{Probability} 13 | } 14 | \value{ 15 | Binary samples 16 | } 17 | \description{ 18 | See McElreaths Rethinking package for details 19 | } 20 | -------------------------------------------------------------------------------- /man/rmvnorm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rmvnorm.R 3 | \name{rmvnorm} 4 | \alias{rmvnorm} 5 | \title{A function to simulate MV norm data} 6 | \usage{ 7 | rmvnorm( 8 | n, 9 | mean = rep(0, nrow(sigma)), 10 | sigma = diag(length(mean)), 11 | method = c("eigen", "svd", "chol"), 12 | pre0.9_9994 = FALSE, 13 | checkSymmetry = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{n}{number of samples} 18 | 19 | \item{mean}{mean vector} 20 | 21 | \item{sigma}{vcov matrix} 22 | 23 | \item{method}{method to use} 24 | 25 | \item{pre0.9_9994}{see mvtnorm} 26 | 27 | \item{checkSymmetry}{see mvtnorm} 28 | } 29 | \value{ 30 | MV normal samples 31 | } 32 | \description{ 33 | See mvtnorm package for details 34 | } 35 | -------------------------------------------------------------------------------- /man/rmvnorm2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rmvnorm2.R 3 | \name{rmvnorm2} 4 | \alias{rmvnorm2} 5 | \title{A function to simulate MV Normal data} 6 | \usage{ 7 | rmvnorm2( 8 | n, 9 | Mu = rep(0, length(sigma)), 10 | sigma = rep(1, length(Mu)), 11 | Rho = diag(length(Mu)), 12 | method = "chol" 13 | ) 14 | } 15 | \arguments{ 16 | \item{n}{Number of samples.} 17 | 18 | \item{Mu}{Mean vector.} 19 | 20 | \item{sigma}{Variance vector.} 21 | 22 | \item{Rho}{Correlation matrix.} 23 | 24 | \item{method}{See details in Rethinking.} 25 | } 26 | \value{ 27 | MV normal samples. 28 | } 29 | \description{ 30 | See McElreaths Rethinking package for details 31 | } 32 | -------------------------------------------------------------------------------- /man/run_longitudinal_checks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_longitudinal_checks.R 3 | \name{run_longitudinal_checks} 4 | \alias{run_longitudinal_checks} 5 | \title{An internal function to check that a list of STRAND data objects can be merged into a longitudinal object} 6 | \usage{ 7 | run_longitudinal_checks(data, pass) 8 | } 9 | \arguments{ 10 | \item{data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data object must include all covariates used in the formulas of the fit_longitudinal_model() function.} 11 | 12 | \item{pass}{1 or 2. First pass checks raw data, second pass checks some computed values also.} 13 | } 14 | \value{ 15 | Returns an error if objects do not match. 16 | } 17 | \description{ 18 | An internal function to check that a list of STRAND data objects can be merged into a longitudinal object 19 | } 20 | -------------------------------------------------------------------------------- /man/simulate_diffusion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_diffusion.R 3 | \name{simulate_diffusion} 4 | \alias{simulate_diffusion} 5 | \title{A function to simulate a network-based diffusion proccess using the STRAND framework} 6 | \usage{ 7 | simulate_diffusion( 8 | long_data, 9 | individual_focal_regression, 10 | social_focal_regression, 11 | social_target_regression, 12 | social_dyad_regression, 13 | individual_focal_parameters, 14 | social_focal_parameters, 15 | social_target_parameters, 16 | social_dyad_parameters, 17 | base_rates, 18 | ces_parameters = list(alpha = 0.95, sigma = 100, eta = 1) 19 | ) 20 | } 21 | \arguments{ 22 | \item{long_data}{A list of data objects of class STRAND prepared using the make_strand_data() function. The data objects must include all covariates and trait diffusion data used in the formulas listed below.} 23 | 24 | \item{individual_focal_regression}{A formula for the effects of focal predictors on individual learning rate. This should be specified as in lm(), e.g.: ~ Age * Education.} 25 | 26 | \item{social_focal_regression}{A formula for the effects of focal predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 27 | 28 | \item{social_target_regression}{A formula for the effects of target predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 29 | 30 | \item{social_dyad_regression}{A formula for the predictors of dyadic relationships on social attention weights. This should be specified as in lm(), e.g.: ~ Kinship + Friendship.} 31 | 32 | \item{individual_focal_parameters}{A formula for the effects of focal predictors on individual learning rate. This should be specified as in lm(), e.g.: ~ Age * Education.} 33 | 34 | \item{social_focal_parameters}{A formula for the effects of focal predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 35 | 36 | \item{social_target_parameters}{A formula for the effects of target predictors on social attention weights. This should be specified as in lm(), e.g.: ~ Age * Education.} 37 | 38 | \item{social_dyad_parameters}{A formula for the predictors of dyadic relationships on social attention weights. This should be specified as in lm(), e.g.: ~ Kinship + Friendship.} 39 | 40 | \item{base_rates}{The intercept parameters for the individual and then social learing rates on logg-odds scale.} 41 | 42 | \item{ces_parameters}{A named list: alpha is the share of social influence owing to i to j ties (which implies 1-alpha is the share due to j to i ties), sigma is the elastisity of substitution, eta is returns to scale.} 43 | } 44 | \value{ 45 | A STRAND model object containing the data used, and the Stan results. 46 | } 47 | \description{ 48 | This function allows users to simulate data using a NBDA model. The user must supply a list of STRAND data objects, a set of parameters, 49 | and a series of formulas following standard lm() style syntax. 50 | } 51 | \examples{ 52 | \dontrun{ 53 | fit = fit_NBDA_model(long_data=model_dat, 54 | individual_focal_regression = ~ Age * NoFood, 55 | social_block_regression = ~ Ethnicity, 56 | social_focal_regression = ~ Age * NoFood, 57 | social_target_regression = ~ Age * NoFood, 58 | social_dyad_regression = ~ Relatedness + Friends * SameSex, 59 | mode="mcmc", 60 | stan_mcmc_parameters = list(seed = 1, chains = 1, 61 | parallel_chains = 1, refresh = 1, 62 | iter_warmup = 100, iter_sampling = 100, 63 | max_treedepth = NULL, adapt_delta = NULL) 64 | ) 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/simulate_longitudinal_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_longitudinal_network.R 3 | \name{simulate_longitudinal_network} 4 | \alias{simulate_longitudinal_network} 5 | \title{A function to simulate longitudinal directed networks using a combined stochastic block and social relations model} 6 | \usage{ 7 | simulate_longitudinal_network( 8 | N_id = 99, 9 | N_timesteps = 3, 10 | B = NULL, 11 | V = 3, 12 | groups = NULL, 13 | sr_mu = c(0, 0), 14 | sr_sigma, 15 | sr_Rho, 16 | dr_mu = 0, 17 | dr_sigma, 18 | dr_Rho, 19 | error_sigma = 0.01, 20 | outcome_mode = "bernoulli", 21 | link_mode = "logit", 22 | individual_predictors = NULL, 23 | dyadic_predictors = NULL, 24 | individual_effects = NULL, 25 | dyadic_effects = NULL 26 | ) 27 | } 28 | \arguments{ 29 | \item{N_id}{Number of individuals.} 30 | 31 | \item{N_timesteps}{Number of network layers, one per timestep.} 32 | 33 | \item{B}{List of List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term. The first list is over layers/time-steps. The second is over block variables within layers.} 34 | 35 | \item{V}{Number of blocking variables in each layer.} 36 | 37 | \item{groups}{A list of dataframes of the block IDs of each individual for each variable in B.} 38 | 39 | \item{sr_mu}{A vector for sender and receivier random effects. In most cases, this should be a vector of 0s 2*N_timesteps long.} 40 | 41 | \item{sr_sigma}{A standard deviation vector for sender and receivier random effects. The first N_timesteps elements control node-level variation in out-degree, the second N_timesteps elements control in-degree.} 42 | 43 | \item{sr_Rho}{Correlation of sender-receiver effects (i.e., generalized reciprocity). Needs to be a valid correlation matrix, 2*N_timesteps by 2*N_timesteps.} 44 | 45 | \item{dr_mu}{A vector for dyadic random effects. In most cases, this should be a vector of 0s N_timesteps long.} 46 | 47 | \item{dr_sigma}{Standard deviation for dyadic random effects. This should be a vector N_timesteps long.} 48 | 49 | \item{dr_Rho}{Correlation of dyad effects (i.e., dyadic reciprocity). Needs to be a valid correlation matrix, 2*N_timesteps by 2*N_timesteps.} 50 | 51 | \item{error_sigma}{Standard deviation for measurement error in Gaussian models.} 52 | 53 | \item{outcome_mode}{Outcome mode: can be "bernoulli", "poisson", "binomial", or "gaussian".} 54 | 55 | \item{link_mode}{Link mode: can be "logit", "probit", "log", or "identity". For poisson, you must use log. For Gaussian you must use identity.} 56 | 57 | \item{individual_predictors}{An N_timesteps list of N_id x N_individual_parameters array of covariates.} 58 | 59 | \item{dyadic_predictors}{An N_timesteps list of N_id x N_id x N_dyadic_parameters array of covariates.} 60 | 61 | \item{individual_effects}{A list of 2 by N_individual_parameters matrix of slopes. The list runs over layers/timesteps. In each element, the first row gives effects of focal characteristics (on out-degree). 62 | The second row gives effects of target characteristics (on in-degree).} 63 | 64 | \item{dyadic_effects}{A list of N_dyadic_parameters vectors of slopes.} 65 | } 66 | \value{ 67 | A list of objects including: network (an adjacency tensor of binary outcomes), tie_strength (an adjacency tensor with probability weights), 68 | group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), 69 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 70 | } 71 | \description{ 72 | This is a function to simulate multilayer longitudinal network data with a stochastic block structure, sender-receiver effects, and dyadic reciprocity. This function 73 | is essentially the union of a social relations model and a stochastic block model. 74 | } 75 | -------------------------------------------------------------------------------- /man/simulate_multiplex_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_multiplex_network.R 3 | \name{simulate_multiplex_network} 4 | \alias{simulate_multiplex_network} 5 | \title{A function to simulate multilayer directed networks using a combined stochastic block and social relations model} 6 | \usage{ 7 | simulate_multiplex_network( 8 | N_id = 99, 9 | N_layers = 3, 10 | B = NULL, 11 | V = 3, 12 | groups = NULL, 13 | sr_mu = c(0, 0), 14 | sr_sigma, 15 | sr_Rho, 16 | dr_mu, 17 | dr_sigma, 18 | dr_Rho, 19 | error_sigma = 0.01, 20 | outcome_mode = "bernoulli", 21 | link_mode = "logit", 22 | individual_predictors = NULL, 23 | dyadic_predictors = NULL, 24 | individual_effects = NULL, 25 | dyadic_effects = NULL 26 | ) 27 | } 28 | \arguments{ 29 | \item{N_id}{Number of individuals.} 30 | 31 | \item{N_layers}{Number of network layers} 32 | 33 | \item{B}{List of List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term. The first list is over layers. The second is over block variables.} 34 | 35 | \item{V}{Number of blocking variables in each B.} 36 | 37 | \item{groups}{Dataframe of the block IDs of each individual for each variable in B.} 38 | 39 | \item{sr_mu}{Mean A vector for sender and receivier random effects. In most cases, this should be a vector of 0s 2*N_layers long.} 40 | 41 | \item{sr_sigma}{A standard deviation vector for sender and receivier random effects. The first N_layers elements control node-level variation in out-degree, the second N_layers elements control in-degree.} 42 | 43 | \item{sr_Rho}{Correlation of sender-receiver effects (i.e., generalized reciprocity). Needs to be a valid correlation matrix, 2*N_layers by 2*N_layers.} 44 | 45 | \item{dr_mu}{Mean A vector for dyadic random effects. In most cases, this should be a vector of 0s N_layers long.} 46 | 47 | \item{dr_sigma}{Standard deviation for dyadic random effects. This should be a vector N_layers long.} 48 | 49 | \item{dr_Rho}{Correlation of dyad effects (i.e., dyadic reciprocity). Needs to be a valid correlation matrix, 2*N_layers by 2*N_layers.} 50 | 51 | \item{error_sigma}{Standard deviation for measurement error in Gaussian models.} 52 | 53 | \item{outcome_mode}{Outcome mode: can be "bernoulli", "poisson", "binomial", or "gaussian".} 54 | 55 | \item{link_mode}{Link mode: can be "logit", "probit", "log", or "identity". For poisson, you must use log. For Gaussian you must use identity.} 56 | 57 | \item{individual_predictors}{An N_id by N_individual_parameters matrix of covariates.} 58 | 59 | \item{dyadic_predictors}{An N_id by N_id by N_dyadic_parameters array of covariates.} 60 | 61 | \item{individual_effects}{A list of 2 by N_individual_parameters matrix of slopes. The list runs over layers. In each element, the first row gives effects of focal characteristics (on out-degree). 62 | The second row gives effects of target characteristics (on in-degree).} 63 | 64 | \item{dyadic_effects}{A list of N_dyadic_parameters vectors of slopes.} 65 | } 66 | \value{ 67 | A list of objects including: network (an adjacency tensor of binary outcomes), tie_strength (an adjacency tensor with probability weights), 68 | group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), 69 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 70 | } 71 | \description{ 72 | This is a function to simulate multilayer network data with a stochastic block structure, sender-receiver effects, and dyadic reciprocity. This function 73 | is essentially the union of a social relations model and a stochastic block model. 74 | } 75 | -------------------------------------------------------------------------------- /man/simulate_sbm_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_sbm_network.R 3 | \name{simulate_sbm_network} 4 | \alias{simulate_sbm_network} 5 | \title{A function to simulate single layer directed networks with a stochastic block structure} 6 | \usage{ 7 | simulate_sbm_network( 8 | N_id = 100, 9 | B = NULL, 10 | V = 3, 11 | groups = NULL, 12 | error_sigma = 0.01, 13 | outcome_mode = "bernoulli", 14 | link_mode = "logit", 15 | individual_predictors = NULL, 16 | dyadic_predictors = NULL, 17 | individual_effects = NULL, 18 | dyadic_effects = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{N_id}{Number of individuals.} 23 | 24 | \item{B}{List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term.} 25 | 26 | \item{V}{Number of blocking variables in B.} 27 | 28 | \item{groups}{Dataframe of the block IDs of each individual for each variable in B.} 29 | 30 | \item{error_sigma}{Standard deviation for measurement error in Gaussian models.} 31 | 32 | \item{outcome_mode}{Outcome mode: can be "bernoulli", "poisson", "binomial", or "gaussian".} 33 | 34 | \item{link_mode}{Link mode: can be "logit", "probit", "log", or "identity". For poisson, you must use log. For Gaussian you must use identity.} 35 | 36 | \item{individual_predictors}{An N_id by N_individual_parameters matrix of covariates.} 37 | 38 | \item{dyadic_predictors}{An N_id by N_id by N_dyadic_parameters array of covariates.} 39 | 40 | \item{individual_effects}{A 2 by N_individual_parameters matrix of slopes. The first row gives effects of focal characteristics (on out-degree). 41 | The second row gives effects of target characteristics (on in-degree).} 42 | 43 | \item{dyadic_effects}{An N_dyadic_parameters vector of slopes.} 44 | } 45 | \value{ 46 | A list of objects including: network (an adjacency matrix of binary outcomes), tie_strength (an adjacency matrix with probability weights), 47 | group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), 48 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 49 | } 50 | \description{ 51 | This is a function to simulate single layer network data with a stochastic block structure. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | library(igraph) 56 | V = 1 # One blocking variable 57 | G = 3 # Three categories in this variable 58 | N_id = 100 # Number of people 59 | 60 | clique = sample(1:3, N_id, replace=TRUE) 61 | B = matrix(-6, nrow=G, ncol=G) 62 | diag(B) = -1.5 # Block matrix 63 | 64 | B[1,3] = -5 65 | B[3,2] = -4 66 | 67 | A = simulate_sbm_network(N_id = N_id, B=list(B=B), V=V, groups = data.frame(clique=factor(clique)), 68 | individual_predictor=matrix(rnorm(N_id, 0, 1), nrow=N_id, ncol=1), 69 | individual_effects=matrix(c(1.7, 0.3),ncol=1, nrow=2), 70 | outcome_mode="bernoulli" 71 | ) 72 | 73 | Net = graph_from_adjacency_matrix(A$network, mode = c("directed")) 74 | V(Net)$color = c("turquoise4","gray13", "goldenrod3")[A$group_ids$clique] 75 | 76 | plot(Net, edge.arrow.size =0.1, edge.curved = 0.3, vertex.label=NA, vertex.size = 5) 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /man/simulate_sbm_plus_srm_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_sbm_plus_srm_network.R 3 | \name{simulate_sbm_plus_srm_network} 4 | \alias{simulate_sbm_plus_srm_network} 5 | \title{A function to simulate single layer directed networks using a combined stochastic block and social relations model} 6 | \usage{ 7 | simulate_sbm_plus_srm_network( 8 | N_id = 99, 9 | B = NULL, 10 | V = 3, 11 | groups = NULL, 12 | sr_mu = c(0, 0), 13 | sr_sigma = c(0.3, 1.5), 14 | sr_rho = 0.6, 15 | dr_mu = 0, 16 | dr_sigma = 1, 17 | dr_rho = 0.7, 18 | error_sigma = 0.01, 19 | outcome_mode = "bernoulli", 20 | link_mode = "logit", 21 | individual_predictors = NULL, 22 | dyadic_predictors = NULL, 23 | individual_effects = NULL, 24 | dyadic_effects = NULL 25 | ) 26 | } 27 | \arguments{ 28 | \item{N_id}{Number of individuals.} 29 | 30 | \item{B}{List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term.} 31 | 32 | \item{V}{Number of blocking variables in B.} 33 | 34 | \item{groups}{Dataframe of the block IDs of each individual for each variable in B.} 35 | 36 | \item{sr_mu}{Mean A vector for sender and receivier random effects. In most cases, this should be c(0,0).} 37 | 38 | \item{sr_sigma}{A standard deviation vector for sender and receivier random effects. The first element controls node-level variation in out-degree, the second in in-degree.} 39 | 40 | \item{sr_rho}{Correlation of sender-receiver effects (i.e., generalized reciprocity).} 41 | 42 | \item{dr_mu}{Mean A vector for dyadic random effects. In most cases, this should be c(0,0).} 43 | 44 | \item{dr_sigma}{Standard deviation for dyadic random effects.} 45 | 46 | \item{dr_rho}{Correlation of dyad effects (i.e., dyadic reciprocity).} 47 | 48 | \item{error_sigma}{Standard deviation for measurement error in Gaussian models.} 49 | 50 | \item{outcome_mode}{Outcome mode: can be "bernoulli", "poisson", "binomial", or "gaussian".} 51 | 52 | \item{link_mode}{Link mode: can be "logit", "probit", "log", or "identity". For poisson, you must use log. For Gaussian you must use identity.} 53 | 54 | \item{individual_predictors}{An N_id by N_individual_parameters matrix of covariates.} 55 | 56 | \item{dyadic_predictors}{An N_id by N_id by N_dyadic_parameters array of covariates.} 57 | 58 | \item{individual_effects}{A 2 by N_individual_parameters matrix of slopes. The first row gives effects of focal characteristics (on out-degree). 59 | The second row gives effects of target characteristics (on in-degree).} 60 | 61 | \item{dyadic_effects}{An N_dyadic_parameters vector of slopes.} 62 | } 63 | \value{ 64 | A list of objects including: network (an adjacency matrix of binary outcomes), tie_strength (an adjacency matrix with probability weights), 65 | group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), 66 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 67 | } 68 | \description{ 69 | This is a function to simulate single layer network data with a stochastic block structure, sender-receiver effects, and dyadic reciprocity. This function 70 | is essentially the union of a social relations model and a stochastic block model. 71 | } 72 | \examples{ 73 | \dontrun{ 74 | library(igraph) 75 | V = 1 # One blocking variable 76 | G = 3 # Three categories in this variable 77 | N_id = 100 # Number of people 78 | 79 | clique = sample(1:3, N_id, replace=TRUE) 80 | B = matrix(-8, nrow=G, ncol=G) 81 | diag(B) = -4.5 # Block matrix 82 | 83 | B[1,3] = -5.9 84 | B[3,2] = -6.9 85 | 86 | A = simulate_sbm_plus_srm_network(N_id = N_id, B=list(B=B), V=V, 87 | groups=data.frame(clique=factor(clique)), 88 | individual_predictor=matrix(rnorm(N_id, 0, 1), nrow=N_id, ncol=1), 89 | individual_effects=matrix(c(1.7, 0.3),ncol=1, nrow=2), 90 | sr_sigma = c(1.4, 0.8), sr_rho = 0.5, 91 | dr_sigma = 1.2, dr_rho = 0.8, 92 | outcome_mode="bernoulli" 93 | ) 94 | 95 | Net = graph_from_adjacency_matrix(A$network, mode = c("directed")) 96 | V(Net)$color = c("turquoise4","gray13", "goldenrod3")[A$group_ids$clique] 97 | 98 | plot(Net, edge.arrow.size =0.1, edge.curved = 0.3, vertex.label=NA, vertex.size = 5) 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /man/simulate_sbm_plus_srm_network_with_measurement_bias.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in 3 | % R/simulate_sbm_plus_srm_network_with_measurement_error.R 4 | \name{simulate_sbm_plus_srm_network_with_measurement_bias} 5 | \alias{simulate_sbm_plus_srm_network_with_measurement_bias} 6 | \title{A function to simulate single layer directed networks using a combined stochastic block and social relations model} 7 | \usage{ 8 | simulate_sbm_plus_srm_network_with_measurement_bias( 9 | N_id = 30, 10 | B = NULL, 11 | V = 3, 12 | groups = NULL, 13 | sr_mu = c(0, 0), 14 | sr_sigma = c(0.3, 1.5), 15 | sr_rho = 0.6, 16 | dr_mu = 0, 17 | dr_sigma = 1, 18 | dr_rho = 0.7, 19 | exposure_mu = 1.9, 20 | exposure_sigma = 0.01, 21 | exposure_max = 50, 22 | censoring_mu = 1.9, 23 | censoring_sigma = 0.01, 24 | N_trials = 20, 25 | outcome_mode = "binomial", 26 | link_mode = "logit", 27 | individual_predictors = NULL, 28 | dyadic_predictors = NULL, 29 | exposure_predictors = NULL, 30 | censoring_predictors = NULL, 31 | individual_effects = NULL, 32 | dyadic_effects = NULL, 33 | exposure_effects = NULL, 34 | censoring_effects = NULL 35 | ) 36 | } 37 | \arguments{ 38 | \item{N_id}{Number of individuals.} 39 | 40 | \item{B}{List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term.} 41 | 42 | \item{V}{Number of blocking variables in B.} 43 | 44 | \item{groups}{Dataframe of the block IDs of each individual for each variable in B.} 45 | 46 | \item{sr_mu}{Mean vector for sender and receivier random effects. In most cases, this should be c(0,0).} 47 | 48 | \item{sr_sigma}{A standard deviation vector for sender and receivier random effects. The first element controls node-level variation in out-degree, the second in in-degree.} 49 | 50 | \item{sr_rho}{Correlation of sender-receiver effects (i.e., generalized reciprocity).} 51 | 52 | \item{dr_mu}{Mean vector for dyadic random effects. In most cases, this should be c(0,0).} 53 | 54 | \item{dr_sigma}{Standard deviation for dyadic random effects.} 55 | 56 | \item{dr_rho}{Correlation of dyad effects (i.e., dyadic reciprocity).} 57 | 58 | \item{exposure_mu}{Intercept term for log-odds of encounter.} 59 | 60 | \item{exposure_sigma}{Standard deviation for exposure random effects.} 61 | 62 | \item{exposure_max}{Max sample size of observations for a given focal.} 63 | 64 | \item{censoring_mu}{Intercept term for log-odds of censoring.} 65 | 66 | \item{censoring_sigma}{Standard deviation for censoring random effects.} 67 | 68 | \item{N_trials}{Number of binomial trials in follow-up detectability experiment.} 69 | 70 | \item{outcome_mode}{Outcome mode: only "binomial" is supported.} 71 | 72 | \item{link_mode}{Link mode: can be "logit", "probit".} 73 | 74 | \item{individual_predictors}{An N_id by N_individual_parameters matrix of covariates.} 75 | 76 | \item{dyadic_predictors}{An N_id by N_id by N_dyadic_parameters array of covariates.} 77 | 78 | \item{exposure_predictors}{An N_id by N_individual_parameters matrix of covariates.} 79 | 80 | \item{censoring_predictors}{An N_id by N_individual_parameters matrix of covariates.} 81 | 82 | \item{individual_effects}{A 2 by N_individual_parameters matrix of slopes. The first row gives effects of focal characteristics (on out-degree). 83 | The second row gives effects of target characteristics (on in-degree).} 84 | 85 | \item{dyadic_effects}{An N_dyadic_parameters vector of slopes.} 86 | 87 | \item{exposure_effects}{An N_parameters vector of slopes.} 88 | 89 | \item{censoring_effects}{An N_parameters vector of slopes.} 90 | } 91 | \value{ 92 | A list of objects including: network (an adjacency matrix of binary outcomes), tie_strength (an adjacency matrix with probability weights), 93 | group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), 94 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 95 | } 96 | \description{ 97 | This is a function to simulate single layer network data with a stochastic block structure, sender-receiver effects, and dyadic reciprocity. This function 98 | is essentially the union of a social relations model and a stochastic block model. 99 | } 100 | -------------------------------------------------------------------------------- /man/simulate_srm_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate_srm_network.R 3 | \name{simulate_srm_network} 4 | \alias{simulate_srm_network} 5 | \title{A function to simulate single layer directed networks using a social relations model} 6 | \usage{ 7 | simulate_srm_network( 8 | N_id = 99, 9 | B = -4, 10 | sr_mu = c(0, 0), 11 | sr_sigma = c(0.3, 1.5), 12 | sr_rho = 0.6, 13 | dr_mu = 0, 14 | dr_sigma = 1, 15 | dr_rho = 0.7, 16 | error_sigma = 0.01, 17 | outcome_mode = "bernoulli", 18 | link_mode = "logit", 19 | individual_predictors = NULL, 20 | dyadic_predictors = NULL, 21 | individual_effects = NULL, 22 | dyadic_effects = NULL 23 | ) 24 | } 25 | \arguments{ 26 | \item{N_id}{Number of individuals.} 27 | 28 | \item{B}{Intercept tie log-odds.} 29 | 30 | \item{sr_mu}{Mean vector for sender and receivier random effects. In most cases, this should be c(0,0).} 31 | 32 | \item{sr_sigma}{Standard deviation vector for sender and receivier random effects. The first element controls node-level variation in out-degree, the second in in-degree.} 33 | 34 | \item{sr_rho}{Correlation of sender-receiver effects: aka. generalized reciprocity.} 35 | 36 | \item{dr_mu}{Mean vector for dyadic random effects. In most cases, this should be c(0,0).} 37 | 38 | \item{dr_sigma}{Standard deviation for dyadic random effects.} 39 | 40 | \item{dr_rho}{Correlation of dyad effects: aka. dyadic reciprocity.} 41 | 42 | \item{error_sigma}{Standard deviation for measurement error in Gaussian models.} 43 | 44 | \item{outcome_mode}{Outcome mode: can be "bernoulli", "poisson", "binomial", or "gaussian".} 45 | 46 | \item{link_mode}{Link mode: can be "logit", "probit", "log", or "identity". For poisson, you must use log. For Guassian you must use identity.} 47 | 48 | \item{individual_predictors}{An N_id by N_individual_parameters matrix of covariates.} 49 | 50 | \item{dyadic_predictors}{An N_id by N_id by N_dyadic_parameters array of covariates.} 51 | 52 | \item{individual_effects}{A 2 by N_individual_parameters matrix of slopes. The first row gives effects of focal characteristics (on out-degree). 53 | The second row gives effects of target characteristics (on in-degree).} 54 | 55 | \item{dyadic_effects}{An N_dyadic_parameters vector of slopes.} 56 | } 57 | \value{ 58 | A list of objects including: network (an adjacency matrix of binary outcomes), tie_strength (an adjacency matrix with probability weights), 59 | individual_predictors (the supplied covariate data is saved along with the network data), 60 | and dyadic_predictors (the supplied covariate data is saved along with the network data). 61 | } 62 | \description{ 63 | This is a function to simulate single layer network data with sender-receiver effects and dyadic reciprocity. This function 64 | is essentially a social relations model. 65 | } 66 | \examples{ 67 | \dontrun{ 68 | library(igraph) 69 | N_id = 100 70 | A = simulate_srm_network(N_id = N_id, B=-7, 71 | individual_predictor=matrix(rnorm(N_id, 0, 1), nrow=N_id, ncol=1), 72 | individual_effects=matrix(c(1.2, 1.5), ncol=1, nrow=2), 73 | sr_sigma = c(1.4, 0.8), sr_rho = 0.5, 74 | dr_sigma = 1.2, dr_rho = 0.8, 75 | outcome_mode="bernoulli" 76 | ) 77 | Net = graph_from_adjacency_matrix(A$network, mode = c("directed")) 78 | 79 | plot(Net, edge.arrow.size =0.1, edge.curved = 0.3, vertex.label=NA, vertex.size = 5) 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /man/standardize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/standardize.R 3 | \name{standardize} 4 | \alias{standardize} 5 | \title{A function to standardize data} 6 | \usage{ 7 | standardize(input, center = TRUE, type = "sd") 8 | } 9 | \arguments{ 10 | \item{input}{A vector of data to standardize.} 11 | 12 | \item{center}{Subtract mean?} 13 | 14 | \item{type}{Divide by "max" or "sd"?} 15 | } 16 | \value{ 17 | A vector of standardize data. 18 | } 19 | \description{ 20 | This is a simple helper function to standardize data. We recommmend to standardize covariates as it makes parameter interpretation easier. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | age_standardize = standardize(input=age) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/strand_VPCs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strand_VPCs.R 3 | \name{strand_VPCs} 4 | \alias{strand_VPCs} 5 | \title{Organize Stan output and provide summaries of variance parameters} 6 | \usage{ 7 | strand_VPCs( 8 | input, 9 | n_partitions = 4, 10 | HPDI = 0.9, 11 | include_reciprocity = FALSE, 12 | mode = "cor", 13 | include_samples = FALSE, 14 | plot_pairs = FALSE, 15 | plot_type = "vpcs", 16 | plot_layer = NULL, 17 | verbose = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{input}{A STRAND model object with social relations model parameters.} 22 | 23 | \item{n_partitions}{Should variance on latent scale be partioned into 3 factors (focal, target, dyadic+error) as in amen? Or 4 factors (focal, target, dyadic, error)? Or 5 factors (focal, target, dyadic reciprocal, dyadic noise, error)?} 24 | 25 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 26 | 27 | \item{include_reciprocity}{Should reciprocity estimates be returned?.} 28 | 29 | \item{mode}{Should the dyadic correlation "cor" be computed, or the dyadic covariance "cov", or the adjusted dyadic+error correlation "adj".} 30 | 31 | \item{include_samples}{An indicator for the user to specify if raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 32 | 33 | \item{plot_pairs}{A Boolean to plot pairs of the variance terms.} 34 | 35 | \item{plot_type}{Should the raw variances be plotted: "raw", or should the variance partition coefficients: "vpcs"?} 36 | 37 | \item{plot_layer}{The name of the layer to plot.} 38 | 39 | \item{verbose}{If TRUE prints the results.} 40 | } 41 | \value{ 42 | A STRAND results object. 43 | } 44 | \description{ 45 | This is a function to organize Stan output and provide summaries of key model parameters 46 | } 47 | \examples{ 48 | \dontrun{ 49 | res = strand_VPCs(input=fit) 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /man/strand_caterpillar_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strand_caterpillar_plot.R 3 | \name{strand_caterpillar_plot} 4 | \alias{strand_caterpillar_plot} 5 | \title{A function to create a STRAND data object} 6 | \usage{ 7 | strand_caterpillar_plot( 8 | results, 9 | submodels = NULL, 10 | normalized = FALSE, 11 | only_slopes = FALSE, 12 | only_technicals = FALSE, 13 | site = "BOB", 14 | export_as_table = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{results}{The results object from summarize_strand_results.} 19 | 20 | \item{submodels}{Which submodels to plot? Supported: "False positive rate", "Recall of true ties", "Theta: question-order effects", "Focal effects: Out-degree", "Target effects: In-degree", "Dyadic effects", "Other estimates"} 21 | 22 | \item{normalized}{Should effects be normalized? Do not use for correlations and variance terms.} 23 | 24 | \item{only_slopes}{If TRUE then technical parameters are omited, and only slopes and intercepts are plotted.} 25 | 26 | \item{only_technicals}{If TRUE then technical parameters are plotted, and slopes and intercepts are omited} 27 | 28 | \item{site}{A string to indicate group or feildsite.} 29 | 30 | \item{export_as_table}{If TRUE, the data are not plotted, and a data.frame is returned. This is useful for making complex ggplot objects with multiple groups/sites.} 31 | } 32 | \value{ 33 | A plot or dataframe 34 | } 35 | \description{ 36 | This function organizes network data and covariates into a form that can be used by STRAND for model fitting. All 37 | STRAND model fitting functions require their data to be supplied in the format exported here. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | vis = strand_caterpillar_plot(res, submodel=c("Focal efffects: Out-degree", 42 | "Target effects: In-degree", 43 | "Dyadic effects","Other estimates"), 44 | normalized=TRUE, 45 | site="XY", 46 | only_technicals=TRUE, 47 | export_as_table=FALSE 48 | ) 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /man/sum_stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sum_stats.R 3 | \name{sum_stats} 4 | \alias{sum_stats} 5 | \title{A function to summarize samples} 6 | \usage{ 7 | sum_stats(y, x, z) 8 | } 9 | \arguments{ 10 | \item{y}{A string.} 11 | 12 | \item{x}{Samples.} 13 | 14 | \item{z}{HPDI level} 15 | } 16 | \value{ 17 | A vector of summaries. 18 | } 19 | \description{ 20 | This is a simple helper function to summarize samples. 21 | } 22 | -------------------------------------------------------------------------------- /man/summarize_bm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_bm_results.R 3 | \name{summarize_bm_results} 4 | \alias{summarize_bm_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_bm_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a stochastic block model.} 11 | 12 | \item{include_samples}{An indicator for the user to specify whether raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_bm_results(input = fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_bsrm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_bsrm_results.R 3 | \name{summarize_bsrm_results} 4 | \alias{summarize_bsrm_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_bsrm_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a combined stochastic block and social relations model.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_bsrm_results(input = fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_bsrm_results_with_measurement_bias.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_bsrm_results_with_measurement_bias.R 3 | \name{summarize_bsrm_results_with_measurement_bias} 4 | \alias{summarize_bsrm_results_with_measurement_bias} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_bsrm_results_with_measurement_bias( 8 | input, 9 | include_samples = TRUE, 10 | HPDI = 0.9 11 | ) 12 | } 13 | \arguments{ 14 | \item{input}{A STRAND model object, obtained by fitting a combined stochastic block and social relations model.} 15 | 16 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 17 | 18 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 19 | } 20 | \value{ 21 | A STRAND results object including summary table, a summary list, and samples. 22 | } 23 | \description{ 24 | This is a function to organize Stan output and provide summaries of key model parameters. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | res = summarize_bsrm_results(input = fit) 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/summarize_lnm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_lnm_results.R 3 | \name{summarize_lnm_results} 4 | \alias{summarize_lnm_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_lnm_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a latent network model.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_lnm_results(input = fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_lnmf_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_lnmf_results.R 3 | \name{summarize_lnmf_results} 4 | \alias{summarize_lnmf_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_lnmf_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a latent network model including observed network flows.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_lnmf_results(input = fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_longitudinal_bsrm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_longitudinal_bsrm_results.R 3 | \name{summarize_longitudinal_bsrm_results} 4 | \alias{summarize_longitudinal_bsrm_results} 5 | \title{Organize Stan output and provide summaries of model parameters for longitudinal models} 6 | \usage{ 7 | summarize_longitudinal_bsrm_results( 8 | input, 9 | include_samples = TRUE, 10 | HPDI = 0.9, 11 | quiet = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{input}{A STRAND model object obtained by fitting a longitudinal combined stochastic block and social relations model.} 16 | 17 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 18 | 19 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 20 | 21 | \item{quiet}{If TRUE, then results aren't printed.} 22 | } 23 | \value{ 24 | A STRAND results object including summary table, a summary list, and samples. 25 | } 26 | \description{ 27 | This is a function to organize Stan output and provide summaries of key model parameters 28 | } 29 | \examples{ 30 | \dontrun{ 31 | res = summarize_longitudinal_bsrm_results(input = fit) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/summarize_multiplex_bsrm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_multiplex_bsrm_results.R 3 | \name{summarize_multiplex_bsrm_results} 4 | \alias{summarize_multiplex_bsrm_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_multiplex_bsrm_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a multiplex combined stochastic block and social relations model.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_multiplex_bsrm_results(input=fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_srm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_srm_results.R 3 | \name{summarize_srm_results} 4 | \alias{summarize_srm_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_srm_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a social relations model.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_srm_results(input = fit) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/summarize_strand_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarize_strand_results.R 3 | \name{summarize_strand_results} 4 | \alias{summarize_strand_results} 5 | \title{Organize Stan output and provide summaries of model parameters} 6 | \usage{ 7 | summarize_strand_results(input, include_samples = TRUE, HPDI = 0.9) 8 | } 9 | \arguments{ 10 | \item{input}{A STRAND model object, obtained by fitting a model using a STRAND function.} 11 | 12 | \item{include_samples}{An indicator for the user to specify where raw samples, or only the summary statistics should be returned. Samples can take up a lot of space.} 13 | 14 | \item{HPDI}{Highest Posterior Density Interval. Ranges in (0,1).} 15 | } 16 | \value{ 17 | A STRAND results object including summary table, a summary list, and samples. 18 | } 19 | \description{ 20 | This is a function to organize Stan output and provide summaries of key model parameters. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | res = summarize_strand_results(input = fit) 25 | } 26 | 27 | } 28 | --------------------------------------------------------------------------------