SimulatedIncidenceMatrix: SimulatedIncidenceMatrix

Description Fields Methods

Description

A class for storing lists of IncidenceMatrices

Fields

mat

A matrix containing a single sample. By default, it is the first sample. See self$sample for how to change it.

sample

Return a random sample from the simulations. Alternatively, select a sample to use with self$mat by assigning a value.

simulations

The simulations this structure is responsible for. This is another name for self$arr.

Methods

addColumns(columns)

This function adds columns to self$simulations

Arguments
columns - The number of columns to add.

addError(type,rows,cols,mutate = TRUE)

Add error to the simulations according to a distribution.

Arguments
type - The type of distribution as a string. Currently 'Poisson' is allowed.
rows - Which rows to affect.
cols - Which columns to affect.
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

addRows(rows)

This function adds rows to self$simulations

Arguments
rows - The number of rows to add.

diff(lag = 1,mutate=TRUE)

This function replaces the matrix value at column i with the differences between the values at column i and i-lag.

Arguments
lag - How far back to diff.
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

head(k,direction=2,mutate=FALSE)

Take the first k slices of self$simulations

Arguments
k - How many slices to keep
direction - Which dimension to take a subset of. 1 is rows, 2 is columns, 3 is simulations
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

initialize(data=MatrixData$new(),nsim=1)

Create a new SimulatedIncidenceMatrix.

Arguments
data - The data to use for the simulation. Can be a list of IncidenceMatrices, or a single IncidenceMatrix.
nsim - The number of simulations. If data is a list, this should be the length of the list. If data is an IncidenceMatrix, this is the number of times the IncidenceMatrix is replicated.

lag(indices,mutate = TRUE,na.rm=FALSE)

This function replaces the current matrix with a new matrix with one column for every column, and a row for every row/index combination. The column corresponding to the row and index will have the value of the original matrix in the same row, but index columns previous.

Arguments
indices - A sequence of lags to use as part of the data. Note that unless this list contains 0, the data will all be shifted back by one year.
mutate - Whether to modify this object, or create and return a modified object.
na.rm - Whether to remove the NA columns that result where the lag goes off the edge of self$simulations.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

lead(indices,mutate = TRUE,na.rm=FALSE)

This function replaces the current array with a new array with one column for every column, and a row for every row/index combination. The column corresponding to the row and index will have the value of the original array in the same row, but index columns ahead.

Arguments
indices - A sequence of leads to use as part of the data. Note that unless this list contains 0, the data will all be shifted back by at least one year.
mutate - Whether to modify this object, or create and return a modified object.
na.rm - Whether to remove the NA columns that result where the lead goes off the edge of self$simulations.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

mean()

Compute the mean over all simulations.

Arguments
Value

An IncidenceMatrix where return$mat is the elementwise mean of self$arr

median()

Compute the median over all simulations.

Arguments
Value

An IncidenceMatrix where return$mat is the elementwise median of self$arr

mutate(rows,cols,sims,data)

This function changes the information stored in self$simulations

Arguments
rows - The rows to change.
cols - The columns to change.
sims - Which simulations to affect.
data - The data to change to. Can be either array-like or matrix-like. If its matrix-like it will overwrite all of the dimensions.

scale(f,mutate=TRUE)

This function rescales each element of our object according to a function.

Arguments
f - The function we rescale by. This function takes in a number and outputs a rescaled version of that number.
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

subsample(simulations,mutate=TRUE)

Choose only some of the simulations.

Arguments
simulations - Which simulations to keep
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

subset(rows,cols,mutate=TRUE)

Take a subset of the object as though it were a matrix.

Arguments
rows - Numeric, named, or logical denoting which rows to select
cols - Numeric, named, or logical denoting which columns to select
mutate - Whether to modify this object, or create and return a modified object.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

summarize(FUNC,...)

Apply a function to every simulation.

Arguments
FUNC - The function to apply.
... - Any arguments to FUNC other than the matrix.
Value

An IncidenceMatrix where return$mat[i,j] is the same as FUNC(self$arr[i,j,])

tail(k,direction=2)

Take the last k slices of self$simulations

Arguments
k - How many slices to keep
direction - Which dimension to take a subset of. 1 is rows, 2 is columns, 3 is simulations
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.


ForecastFramework documentation built on April 14, 2020, 7:39 p.m.