new_dist: Creates New Distribution Object

View source: R/utilities.R

new_distR Documentation

Creates New Distribution Object

Description

The function creates distribution objects that satisfy the naming convention used in package mistr.

Usage

new_dist(
  name,
  from,
  to,
  by = NULL,
  parameters = mget(names(eval(quote(match.call()), parent)[-1]), parent),
  class = deparse(sys.calls()[[sys.nframe() - 1]][[1]]),
  parent = parent.frame()
)

Arguments

name

string containing the name of the distribution.

from

numeric representing where the support of distribution starts.

to

numeric representing where the support of distribution ends.

by

numeric representing the deterministic step between support values. If NULL: continuous distribution is assumed. If the value is specified: discrete distribution with specified step is assumed, default: NULL.

parameters

named list of parameters of the distribution, default: mget(names(eval(quote(match.call()),parent)[-1]),parent).

class

class of the distribution, this should be set in [name]dist convention (e.g. normdist, tdist), default: deparse(sys.calls()[[sys.nframe() - 1]][[1]]).

parent

parent environment, default: parent.frame().

Details

The function can be used in two ways. Either it can be called from the creator functions as for example normdist or unifdist, or directly from any function or enviroment. In the former, only arguments "name", "from" and "to" must be set. Other arguments will be filled according to the parent calls. If this function is called directly, the arguments "parameters" and "class" have to be specified also.

Value

distribution object.

Examples

## Not run: 
# using creator function
unifdist <- function(min = 0, max = 1) { 
   if (!is.numeric(min) || !is.numeric(max))   stop("Parameters must be a numeric")
   if (min >= max)   stop("min must be smaller than max.")
   new_dist(name = "Uniform", from = min, to = max)
}

#directly
U <- new_dist(name = "Uniform", from = 1, to = 6, 
              parameters =  list(min = 1, max = 6), class = "unifdist")

## End(Not run)

mistr documentation built on March 7, 2023, 7:42 p.m.