Create a Model object

Description

Creates a new Model object.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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
            })
}

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.