More info here: https://community.rstudio.com/t/browsevignettes-mypackage-saying-no-vignettes-found/68656/7
-->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# Introduction
This vignette demonstrates how to use simulate situations in which different utility functions apply to diffferent subsets of respondents. We will use a sample dataset and utility functions to generate simulated data and analyze the results. First off it is good practice remove all objects (variables, functions, etc.) from the current workspace and load all R files in the package directory into the current R session.
```{r setup}
library(simulateDCE)
rm(list=ls())
devtools::load_all()
library(rlang)
```
# Inititalize Variables
sim_all is the highest level function in the package and will run simulations for all designs contained in the specified design folder. Accordingly, this is generally the function the user will want to call. To prepare for using this function, a hypothesized utility function with corresponding beta coefficients representing the weight of each term must be declared in R.
The manipulation variable allows the user to assign different terms based on the values of columns in the experimental design file
Besides these arguments the user must also specify the number of respondents in the simulated survey and the number of times to run the model. The number of respondents (resps) should be selected based on experimental design parameters, while the number of simulations (nosim) should be large enough to glean statistically significant data. It is best to use a small number for this while learning to use the package and a large number (at least 500) once the other parameters have been settled.
The simulation can be ran using spdesign or NGENE design files which will be contained in the design path. The design path and design type, must also be specified as strings:
## can also be specified using relative path eg. designpath<- "Projects/CSA/Designs/"
#notes <- "This design consists of different heuristics. One group did not attend the methan attribute, another group only decided based on the payment"
notes <- "No Heuristics"
resps =240 # number of respondents
nosim=2 # number of simulations to run (about 500 is minimum)
## design type must be either 'spdesign' or 'ngene'
destype <- "spdesign"
```
# Randomness
As several part of the simulation rely on random values within experimentally defined bounds, the output of a given simulation call using sim_all will vary each time it is called. Unless the seed for R's randome number generator is set like so:
```{r random}
set.seed(3393)
```
# Output
The sim_all function returns a multidimensional R list containing graphs, simulated observations and a dataframe containing sumaries of estimated b coefficients. In general these will be printed to the console, but the entire results can also be assigned to an r list object.
The beta cofficients for each simulation are contained in a dataframe called coeffs located within {result}->olddesign->coefs. and a summary table, which displays
statistics of these b coefficients across all simulations is contained in ->olddesign->summary.
You can also save the results to disk using saveRDS(csa,file = "tests/manual-tests/csa.RDS")
```{r accessOutput}
## nested results are hard coded, if the design changes this must aswell