#' get_simu_output
#'
#'Function takes in global settings, creates tibbles of simulated data and runs the model.
#'Taking in MCMC samples, a summary tibble is the final output, with posterior estimates (med, lower, upper) by simulation number and by parameter.
#'This is run for one run setting at a time.
#' @param runname The setting used to create the writemodel function
#' @param global_settings Fixed global params that generate fixed country-year params
#' @param simsetting runname
#' @param output.dir output directory where are simulation results are saved by iteration
#'@param nsim The number of simulation to be run.
#' @return One tibble with posterior estimates across per simulation and params. Saved to output folder.
#' @export
#'
#' @examples
#'
get_simu_output <- function(runname, global_settings, output.dir, nsim){
simsetting= runname
for(i in 1:nsim){
#Step 1: Run Simulation, nsim times and get simulated data for each run
run_simulation(runname = runname ,
global_settings = global_settings,
i=i,
simsetting = simsetting )
#Step 2: Run model and get posterior MCMC samples of global parameters.
#Inputs:Takes in run model script from write_model_to_run, number of chains, and number of iterations. Runs model without fixed parameters.
#Ouput: saved mcmc_list_?.RDS where ? is run setting, ie first run setting gives mcmc_list_1.RDS. mcmc_list has posterior mcmc samples of all global parameters.
#modelgammatruect= T if modeling Unif(0,1) for each country-year
run_mcmc(runname = runname, i=i,
Nchains = 5, Niter = 100,
simsetting = simsetting,
modelonegammatrue = T, #modelonegammatrue = T if modeling one global gammatrue
modelgammatruect = F #modelgammatruect= T if modeling Unif(0,1) for each country-year
)
#Summarizes estimates and bias for each simulation
summarize_simulation(simsetting = simsetting,
runname = runname,
simnum = i,
globalvars = gobalvars,
output.dir = output.dir)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.