Last data update: 2014.03.03

R: Skeleton functions for simulations
SimFunctionsR Documentation

Skeleton functions for simulations

Description

This function prints skeleton versions of the required functions and work-flow required to run simulations, complete with the correct inputs, class of outputs, and option comments to help with the initial definitions. Use this at the start when defining your simulation.

Usage

SimFunctions(filename = NULL, comments = FALSE, singlefile = FALSE,
  summarise = TRUE)

Arguments

filename

a character vector indicating whether the output should be saved to two respective files containing the simulation design and the functional components, respectively. Using this option is generally the recommended approach when beginning to write a Monte Carlo simulation

comments

logical; include helpful comments? Default is FALSE

singlefile

logical; when filename is included, put output in one files? When FALSE the output is saved to two separate files containing the functions and design definitions. Default is FALSE

summarise

include summarise function? Default is TRUE

Details

The function SimDesign_functions is deprecated and will be removed in a future release.

Examples


SimFunctions()
SimFunctions(comments = TRUE) #with helpful comments

## Not run: 

# write output to two files and include helpful comments
SimFunctions('mysim', comments = TRUE)

# write output files to a single file without comments
SimFunctions('mysim', singlefile = TRUE)

## End(Not run)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SimDesign)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SimDesign/SimFunctions.Rd_%03d_medium.png", width=480, height=480)
> ### Name: SimFunctions
> ### Title: Skeleton functions for simulations
> ### Aliases: SimFunctions
> 
> ### ** Examples
> 
> 
> SimFunctions()
#-------------------------------------------------------------------

library(SimDesign)

Design <- expand.grid(condition1 = NA,
                      condition2 = NA)

#-------------------------------------------------------------------

Generate <- function(condition, fixed_objects = NULL) {
    dat <- data.frame()
    dat
}

Analyse <- function(condition, dat, fixed_objects = NULL) {
    ret <- c(stat1 = NaN, stat2 = NaN)
    ret
}

Summarise <- function(condition, results, fixed_objects = NULL) {
    ret <- c(bias = NaN, RMSE = NaN)
    ret
}

#-------------------------------------------------------------------

results <- runSimulation(design=Design, replications=1000, 
    generate=Generate, analyse=Analyse, summarise=Summarise, edit='none')

> SimFunctions(comments = TRUE) #with helpful comments
#-------------------------------------------------------------------

library(SimDesign)

### Define design conditions
Design <- expand.grid(condition1 = NA,
                      condition2 = NA)

#-------------------------------------------------------------------

### Define essential simulation functions

Generate <- function(condition, fixed_objects = NULL) {
    # Define data generation code ...

    # Return a vector, matrix, data.frame, or list
    dat <- data.frame()
    dat
}

Analyse <- function(condition, dat, fixed_objects = NULL) {
    # Run statistical analyses of interest ... 

    # Return a named vector or list
    ret <- c(stat1 = NaN, stat2 = NaN)
    ret
}

Summarise <- function(condition, results, fixed_objects = NULL) {
    # Summarise the simulation results ...

    # Return a named vector of results
    ret <- c(bias = NaN, RMSE = NaN)
    ret
}

#-------------------------------------------------------------------

### Run the simulation

results <- runSimulation(design=Design, replications=1000, 
    generate=Generate, analyse=Analyse, summarise=Summarise, edit='none')

> 
> ## Not run: 
> ##D 
> ##D # write output to two files and include helpful comments
> ##D SimFunctions('mysim', comments = TRUE)
> ##D 
> ##D # write output files to a single file without comments
> ##D SimFunctions('mysim', singlefile = TRUE)
> ## End(Not run)
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>