Learn R Programming

SimDesign (version 0.3)

analyse: Compute estimates and statistics

Description

Compute all relevant test statistics and parameter estimates here. This is the computational heavy lifting section. In some cases, it may be easier to change the output to a named list containing different parameter configurations (i.e., when determining RMSE values for a large set of population parameters).

Usage

analyse(condition, dat, parameters = NULL)

Arguments

condition
a single row from the design input (as a data.frame), indicating the simulation conditions
dat
the 'dat' object returned from the generate function (usually a data.frame, matrix, or vector) if a list was returned, otherwise just the raw object defined from gene
parameters
the (optional) list object named 'parameters' returned from the generate function when a list is returned. Otherwise, this will be an empty list

Value

  • returns a named numeric vector with the values of interest (e.g., p-values, effects sizes, etc), or a list containing values of interest (e.g., separate matrix and vector of parameter estimates corresponding to elements in parameters)

Details

Be sure to make heavy use of try combinations and throw a stop if an iterative function fails to converge. This will cause the function to stop, and generate will be called again to obtain a different dataset.

Examples

Run this code
myanalyse <- function(condition, dat, parameters = NULL){

    # require packages/define functions if needed, or better yet index with the :: operator
    require(stats)
    mygreatfunction <- function(x) print('Do some stuff')

    #wrap computational statistics in try() statements to control estimation problems
    welch <- try(t.test(DV ~ group, dat), silent=TRUE)
    ind <- try(stats::t.test(DV ~ group, dat, var.equal=TRUE), silent=TRUE)

    # check if error, and if so stop and return an 'error'. This will re-draw the data
    if(is(welch, 'try-error')) stop('Welch error message')
    if(is(ind, 'try-error')) stop('Independent t-test error message')

    # In this function the p values for the t-tests are returned,
    #  and make sure to name each element, for future reference
    ret <- c(welch = welch$p.value,
             independent = ind$p.value)

    return(ret)
}

Run the code above in your browser using DataLab