Run a summarise step for results that have been saved to the hard drive
When runSimulation() uses the option save_results = TRUE
the R replication results from the Generate-Analyse functions are
stored to the hard drive. As such, additional summarise components
may be required at a later time, whereby the respective .rds files
must be read back into R to be summarised. This function performs
the reading of these files, application of a provided summarise function,
and final collection of the respective results.
reSummarise( summarise, dir = NULL, files = NULL, results = NULL, Design = NULL, fixed_objects = NULL, boot_method = "none", boot_draws = 1000L, CI = 0.95 )
| summarise | a summarise function to apply to the read-in files.
See  | 
| dir | directory pointing to the .rds files to be
read-in that were saved from  | 
| files | (optional) names of files to read-in. If  | 
| results | (optional) the results of  Alternatively, if  | 
| Design | (optional) if  | 
| fixed_objects | (optional) see  | 
| boot_method | method for performing non-parametric bootstrap confidence intervals
for the respective meta-statistics computed by the  | 
| boot_draws | number of non-parametric bootstrap draws to sample for the  | 
| CI | bootstrap confidence interval level (default is 95%) | 
Phil Chalmers rphilip.chalmers@gmail.com
Chalmers, R. P., & Adkins, M. C.  (2020). Writing Effective and Reliable Monte Carlo Simulations
with the SimDesign Package. The Quantitative Methods for Psychology, 16(4), 248-280.
doi: 10.20982/tqmp.16.4.p248
Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte
Carlo simulation. Journal of Statistics Education, 24(3), 136-156.
doi: 10.1080/10691898.2016.1246953
Design <- data.frame(N = c(10, 20, 30))
Generate <- function(condition, fixed_objects = NULL) {
    dat <- with(condition, rnorm(N, 10, 5)) # distributed N(10, 5)
    dat
}
Analyse <- function(condition, dat, fixed_objects = NULL) {
    ret <- mean(dat) # mean of the sample data vector
    ret
}
## Not run: 
# run the simulation
runSimulation(design=Design, replications=50,
              generate=Generate, analyse=Analyse,
              summarise=NA, save_results=TRUE,
              save_details = list(save_results_dirname='simresults'))
Summarise <- function(condition, results, fixed_objects = NULL){
    ret <- c(mu=mean(results), SE=sd(results))
    ret
}
res <- reSummarise(Summarise, dir = 'simresults/')
res
Summarise2 <- function(condition, results, fixed_objects = NULL) {
    mean(results)
}
res2 <- reSummarise(Summarise2, dir = 'simresults/')
res2
SimClean('simresults/')
## End(Not run)
###
# similar to above, but using objects defined in workspace
results <- runSimulation(design=Design, replications=50,
                         generate=Generate, analyse=Analyse)
str(results)
Summarise <- function(condition, results, fixed_objects = NULL){
    ret <- c(mu=mean(results), SE=sd(results))
    ret
}
res <- reSummarise(Summarise, results=results, Design=Design)
res
res <- reSummarise(Summarise, results=results, boot_method = 'basic')
res
###
# Also similar, but storing the results within the summarised simulation
Summarise <- function(condition, results, fixed_objects = NULL){
    ret <- c(mu=mean(results), SE=sd(results))
    ret
}
res <- runSimulation(design=Design, replications=50, store_results = TRUE,
                     generate=Generate, analyse=Analyse, summarise=Summarise)
res
# internal results stored
results <- SimExtract(res, what = 'results')
str(results)
# pass SimDesign object to results
res <- reSummarise(Summarise, results=res, boot_method = 'basic')
resPlease choose more modern alternatives, such as Google Chrome or Mozilla Firefox.