new_model: Create a Model object

View source: R/model-class.R

new_modelR Documentation

Create a Model object

Description

Creates a new Model object.

Usage

new_model(name, label, params = list(), simulate)

Arguments

name

a short name identifier. Must be alphanumeric (though -, _, and / are allowed as long as they are not at the start or end of name.

label

a longer, human readable label that can have other characters such as spaces, hyphens, etc.

params

a list that contains the Model object's parameters

simulate

a function that has arguments nsim and names matching elements within names(params). It returns a list of length nsim, where each element of the list represents a random draw from the Model object.

Examples

make_my_example_model <- function(n) {
  new_model(name = "normal-data",
            label = sprintf("Normal (n = %s)", n),
            params = list(n = n, mu = 2),
            simulate = function(n, mu, nsim) {
              # this function must return a list of length nsim
              x <- matrix(rnorm(n * nsim), n, nsim)
              x <- mu + x # true mean is mu
              return(split(x, col(x))) # make each col its own list element
            })
}

simulator documentation built on Feb. 16, 2023, 9:34 p.m.