RiskElement: RiskElement Class

RiskElementR Documentation

RiskElement Class

Description

This is the parent class defining the structure for the other elements.

Public fields

name

A character giving a name to this constant

inputs

A tibble with the inputs of the element and its units

depends_on

List describing the dependencies for each input

depends_index

List with the indexes for each independency

depended_by

A list of elements that use this instance as input

input_types

A list with the preferred data type for each input (discrete/continuous/any)

output

Name of the output variable

output_unit

Unit of the output variable

output_type

Type of output variable (discrete/continuous)

simulations

A tibble with the results of the simulations

type

A character describing the type of the element

level

Description of the level for X-D Monte Carlo

simulations_multi

For multidimensional MC

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
RiskElement$new(
  name,
  input_names = NA,
  units = NA,
  element_type = "",
  input_types = list(),
  output_var = "",
  output_unit = "",
  output_type = "",
  level = 0
)
Arguments
name

A character defining the name for the element

input_names

A character vector with the names of the inputs

units

A character vector of units for each input

element_type

A character with the type of element

input_types

A list with the type of output for each input

output_var

A character with the name of the output variable

output_unit

A character with the unit of the output

output_type

A character with the type of the output ('continuous' or 'discrete')

level

Level of the variance for 2D Monte Carlo

Returns

A new instance of the element


Method map_input()

Map an input to a element

Usage
RiskElement$map_input(input, element, check_units = FALSE, index = 1)
Arguments
input

A character identifying the input variable

element

An instance of a element to use as input

check_units

Ignored

index

Index of element (for elements with multiple outputs). By default, 1

Returns

self (invisible)


Method simulate()

Make simulation. Returns a vector of length niter with self.value.

Usage
RiskElement$simulate(niter, seed = NULL)
Arguments
niter

Number of iterations (length of the vector).

seed

Seed for the pRNG. By default, NULL (no setting the seed)

Returns

A vector with the output variable


Method simulate_2D()

2D Monte Carlo simulation

Usage
RiskElement$simulate_2D(niter0, niter1, seed = NULL)
Arguments
niter0

number of iterations on the lower level

niter1

number of iterations on the upper level

seed

Seed for the pRNG. By default, NULL (no setting the seed)


Method simulate_level()

Simulation of one level for the 2D Monte Carlo

Usage
RiskElement$simulate_level(niter0, iter1 = 1, level = 0)
Arguments
niter0

number of iterations on the lower level

iter1

index representing the iteration (where to write). By default, 1

level

level to simulate (0 by default)


Method point_estimate()

Gets a discrete (fast and simple) prediction

Usage
RiskElement$point_estimate()

Method get_output()

Get the output

Usage
RiskElement$get_output(iter1 = NULL, index = 1)
Arguments
iter1

Number of iterations (length of the vector).

index

Index fo the output (for multioutput modules). By default, 1

Returns

A vector with the output variable


Method get_output_2D()

Get the output of a 2D simulation

Usage
RiskElement$get_output_2D(index = 1)
Arguments
index

Index fo the output (for multioutput modules). By default, 1


Method save_as_vector()

Saves the output of the simulation as a vector element

Usage
RiskElement$save_as_vector(name = NULL)
Arguments
name

Name of the new element (vctr_from_+self_name by default)

Returns

An instance of Vector


Method save_as_distribution()

Saves the output of the simulation as an empirical distribution.

Usage
RiskElement$save_as_distribution(name = NULL)
Arguments
name

Name of the new element (distr_from_+self_name by default)

Returns

An instance of EmpiricalDistr


Method density_plot_2D()

Makes density plot of a 2D Monte Carlo simulation

Usage
RiskElement$density_plot_2D()

Method cummulative_plot_2D()

Plots the empirical density function for 2D simulations

Usage
RiskElement$cummulative_plot_2D()

Method cummulative_plot()

Plots the empirical density function

Usage
RiskElement$cummulative_plot(add_discrete = FALSE)
Arguments
add_discrete

whether to add an horizontal line with the discrete estimate. By default, FALSE


Method density_plot()

Makes a density plot of the model output

Usage
RiskElement$density_plot(add_discrete = FALSE)
Arguments
add_discrete

whether to add an horizontal line with the discrete estimate. By default, FALSE


Method histogram()

Makes a histogram of the model output

Usage
RiskElement$histogram(add_discrete = FALSE)
Arguments
add_discrete

whether to add a vertical line with the discrete estimate. By default, FALSE


Method boxplot()

Makes a boxplot of the model output

Usage
RiskElement$boxplot(add_discrete = FALSE)
Arguments
add_discrete

whether to add an horizontal line with the discrete estimate. By default, FALSE


Method quantiles()

Quantiles of the output variable

Usage
RiskElement$quantiles(probs = c(0.01, 0.1, 0.5, 0.9, 0.99))
Arguments
probs

values of the quantiles. By default, c(.01, .1, .5, .9, .99)


Method quantiles_2D()

Quantiles of a 2D Monte Carlo simulation

Usage
RiskElement$quantiles_2D(probs = c(0.01, 0.1, 0.5, 0.9, 0.99))
Arguments
probs

values of the quantiles. By default, c(.01, .1, .5, .9, .99)


Method get_output_type()

Get the data type of the output. This is a default implementation (just return the output type). For other elements, (e.g., sum) the type depends on the type of the inputs. So, they have their own implementation.

Usage
RiskElement$get_output_type()

Method check_input_types()

Checks that the type of the inputs is consistent

Usage
RiskElement$check_input_types(recursive = FALSE)
Arguments
recursive

whether to also check the types of the dependencies. By default, FALSE


Method clone()

The objects of this class are cloneable with this method.

Usage
RiskElement$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


albgarre/biorisk documentation built on Feb. 23, 2025, 5:19 a.m.