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,
fixed_objects = NULL)
a summarise function to apply to the read-in files.
See runSimulation
for details
directory pointing to the .rds files to be
read-in that were saved from runSimulation(..., save_results=TRUE)
.
If NULL
, it is assumed the current working directory contains
the .rds files
(optional) names of files to read-in. If NULL
all files
located within dir
will be used
(optional) see runSimulation
for details
Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte
Carlo simulation. Journal of Statistics Education, 24
(3), 136-156.
10.1080/10691898.2016.1246953
# NOT RUN {
# }
# NOT RUN {
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
}
# 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
}
SimClean('SimDesign-results.rds')
results <- reSummarise(Summarise, dir = 'simresults/')
results
Summarise2 <- function(condition, results, fixed_objects = NULL){
mean(results)
}
results2 <- reSummarise(Summarise2, dir = 'simresults/')
results2
SimClean('simresults/')
# }
Run the code above in your browser using DataLab