rm(list=ls())
### DEFINE DIRECTORIES
# folder with the data
datadir <- '<<ADD YOUR FOLDER>>'
# folder with the scripts
workdir <- '<<ADD YOUR FOLDER>>'
setwd(workdir)
##################################
### PART I: PREPARATION ####
##################################
### 01. PREPARE DATA FOR ANALYSES
# should processed data files be saved (in data folder)?
save.data <- F
# run preparation script
source('01_prepare_data.R')
# save data
save.image('01_data_all.RData')
# alternatively, load existing data file from this step
#load('01_data_all.RData')
### 02. DESCRIPTIVES
# this creates files in the scripts folder but leaves the R workspace unchanged
source('02_descriptives.R')
#########################################################
### PART II: STOCHASTIC ACTOR-ORIENTED MODELS ####
#########################################################
### 03. FIT MULTILEVEL STATIONARY SAOMS IN ALL VILLAGES
# clear workspace and load just the necessary data
rm(list=ls())
load('01_data_all.RData')
# define model specification labels (will be used in object names)
saom.models <- c('1baseline', '2individual', '3oplead', '4netsize',
'5netexp', '6hhexp', '7full')
# fit full model:
# specify that none of the effect sets below should be fixed
# (this will be useful for the GoF comparisons below)
fix.netexp <- F
fix.hhexp <- F
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
# set fixed rate parameters (applies to both networks)
rates <- 3
# print estimation and score test results to files? (for debugging)
print.results <- F
# fit village-level models
source('03_saom_village_models.R')
# carry out score tests for constrained parameters
# (some needed to achieve convergence and precise estimates)
source('04_saom_scoretests.R')
# save results
save.image('02_saom_all_results.RData')
# or load existing results from this step
#load('02_saom_all_results.RData')
### 04. META-ANALYSIS OF VILLAGE-LEVEL SAOMS
# select model specification to meta-analyse
# at this stage, only the full model is fitted
saom.model <- saom.models[7]
# print results to file? (for debugging)
print.results <- T
# perform meta-analysis
source('05_saom_meta-analysis.R')
# save results
save.image('02_saom_all_results.RData')
# or load existing results from this step
#load('02_saom_all_results.RData')
### 05. COMPARISON OF THE FIT OF VARIOUS VILLAGE-LEVEL SAOM SPECIFICATIONS
# first, fit models with subsets of effects fixed:
# 1. baseline model
fix.netexp <- T
fix.hhexp <- T
fix.netsize <- T
fix.oplead <- T
fix.individual <- T
source('03_saom_village_models.R')
source('04_saom_scoretests.R') # warnings suggests there aren't any constrained effects
# 2. individual model
fix.netexp <- T
fix.hhexp <- T
fix.netsize <- T
fix.oplead <- T
fix.individual <- F
source('03_saom_village_models.R') # fix village 4 and 10
source('04_saom_scoretests.R')
# 3. opinion leader model
fix.netexp <- T
fix.hhexp <- T
fix.netsize <- T
fix.oplead <- F
fix.individual <- F
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# 4. network size model
fix.netexp <- T
fix.hhexp <- T
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# 5. network exposure model
fix.netexp <- F
fix.hhexp <- T
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# 6. household exposure model
fix.netexp <- T
fix.hhexp <- F
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# second, assess goodness of fit of given village-level models
# print results to file? (for debugging)
print.results <- F
# 1. baseline model
saom.model <- saom.models[1]
source('06_saom_model_fit.R')
# 2. individual model
saom.model <- saom.models[2]
source('06_saom_model_fit.R')
# 3. opinion leader model
saom.model <- saom.models[3]
source('06_saom_model_fit.R')
# 4. network size model
saom.model <- saom.models[4]
source('06_saom_model_fit.R')
# 5. network exposure model
saom.model <- saom.models[5]
source('06_saom_model_fit.R')
# 6. household exposure model
saom.model <- saom.models[6]
source('06_saom_model_fit.R')
# 7. full model
saom.model <- saom.models[7]
source('06_saom_model_fit.R')
# perform goodness of fit comparisons of the different specifications
source('07_saom_model_fit_comparison.R')
# save results
save.image('02_saom_all_results.RData')
# or load existing results from this step
#load('02_saom_all_results.RData')
### 06. EXPLORE FULL SAOM SPECIFICATIONS WITH DIFFERENT RATE PARAMETERS
# 1. rate 5 for both networks
# set rate parameter
rates <- 5
# fit village models
fix.netexp <- F
fix.hhexp <- F
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
print.results <- T
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# perform meta-analyses
saom.model <- saom.models[7]
print.results <- T
source('05_saom_meta-analysis.R')
# 2. rate 8 for both networks
# set rate parameter
rates <- 8
# fit village models
fix.netexp <- F
fix.hhexp <- F
fix.netsize <- F
fix.oplead <- F
fix.individual <- F
print.results <- T
source('03_saom_village_models.R')
source('04_saom_scoretests.R')
# perform meta-analyses
saom.model <- saom.models[7]
print.results <- T
source('05_saom_meta-analysis.R')
# save results
save.image('02_saom_all_results.RData')
# or load existing results from this step
#load('02_saom_all_results.RData')
##########################################
### PART IV: TABLES AND FIGURES ####
##########################################
# generate tables and figures presented in the main text
source('08_tables_and_figures_main_text.R')
# generate tables and figures presented in the SI
source('09_tables_and_figures_SI.R')