Learn R Programming

SimDesign (version 0.9)

Generate: Generate data

Description

Generate data from a single row in the design input (see runSimulation).

Usage

Generate(condition, fixed_objects = NULL)

Arguments

condition
a single row from the design input (as a data.frame), indicating the simulation conditions
fixed_objects
object passed down from runSimulation

Value

  • returns a single object containing the data to be analyzed (usually a vector, matrix, or data.frame), or a list with the elements 'dat' and 'parameters'.

    If a list is returned the 'dat' element should be the observed data object while the 'parameters' element should be a named list containing the simulated parameters (if there are any. Otherwise, this could just be an empty list), or any other objects that would be useful in the Analyse and Summarise functions. If, on the other hand, the objects are only useful in the Analyse function and NOT Summarise then simply adding attributes to the returned object is sufficent (and requires less RAM)

See Also

add_missing

Examples

Run this code
mygenerate <- function(condition, fixed_objects = NULL){

    #require packages/define functions if needed, or better yet index with the :: operator

    N1 <- condition$sample_sizes_group1
    N2 <- condition$sample_sizes_group2
    sd <- condition$standard_deviations

    group1 <- rnorm(N1)
    group2 <- rnorm(N2, sd=sd)
    dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)), DV = c(group1, group2))
    pars <- list(random_number = rnorm(1)) # just a silly example of a simulated parameter

    #could just use return(dat) if no parameters should be tracked for Summerise
    return(list(dat=dat, parameters=pars))
}

mygenerate2 <- function(condition, fixed_objects = NULL){
    mu <- sample(c(-1,0,1), 1)
    dat <- rnorm(100, mu)
    dat        #return simple vector (discard mu information)
}

mygenerate3 <- function(condition, fixed_objects = NULL){
    mu <- sample(c(-1,0,1), 1)
    dat <- rnorm(100, mu)
    attr(dat, 'mu') <- mu    # store mu as an attribute 'mu'
    dat
}

# in the Analyse function, use attr(dat, 'mu') to pull out the mu object for further use

Run the code above in your browser using DataLab