IncidenceMatrix: IncidenceMatrix

Description Fields Methods See Also Examples

Description

A class for storing a matrix and relevant metaData.

Fields

cellData

A list of metadata associated with the cells of the data.

cnames

The names of columns in the data.

colData

A list of metadata associated with the columns of the data.

frame

A data.frame representation of the IncidenceMatrix. The frame contains all rows/columns as rows of the data frame, and the rows, columns, values and all metadata types as columns. This is similar to the melt function.

mat

This is the matrix. For extensibility, it cannot be written to directly and must be modified through methods.

metaData

Any data not part of the main data structure.

ncol

The number of columns in the data.

nrow

The number of rows in the data

rnames

The names of rows in the data.

rowData

A list of metadata associated with the columns of the data.

Methods

addColumns(columns)

This function adds empty columns to the right side of the data.

Arguments
columns - The number of columns to add.

addRows(rows)

This function adds empty rows to the data.

Arguments
rows - The number of rows to add.

as_sts(pop_name = 'pop',freq_name = 'freq',start_name = 'start',epoch_name = 'epoch',map_name = 'map',neighbourhood_name = 'neighbourhood')

Convert this object to an sts object with as much information as possible

Arguments
pop_name - string with the name of rowData to use as the population of the sts object.
freq_name - string with the name of metaData to use as the frequency of the sts object.
start_name - string with the name of metaData to use as the start of the sts object.
epoch_name - string with the name of the colData to use as the epoch of the sts object.
map_name - string with the name of the rowData to use as the map of the sts object.
neighbourhood_name - string with the name of the rowData to use as the neighbourhood of th ests object.

debug(string)

A function for debugging the methods of this class. It calls the browser command. In order for methods to opt into to debugging, they need to implement the following code at the beginning: if(<method_name> %in% private$.debug){browser()}. This method exists, because the debugger is not always intuitive when it comes to debugging R6 methods.

Arguments
string - The name(s) of methods to debug as a character vector

diff(lag = 1,mutate=TRUE)

This function replaces the matrix value at column i with the difference. between the values at columns i and (i-lag).

Arguments
lag - How far back to diff. Defaults to 1.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
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=TRUE)

Select the last k slices of the data in dimension direction.

Arguments
k - The number of slices to keep.
direction - The dimension to take a subset of. 1 for row, 2 for column.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
Value

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

initialize(data=matrix(),metaData=list(),rowData=list(),colData=list(),cellData = list())

Create a new IncidenceMatrix object from its components.

Arguments
data - Either a matrix, or an object of class MatrixData. If data is a matrix, it will form the mat field. If data is a MatrixData, then the new object will inherit all of its fields.

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. This shift will introduce NAs where it passes off the end of the matrix.

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 at least one year.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
na.rm - Whether to remove NA values generated by walking off the edge of the matrix.
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 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 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 foreward 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 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.

mutate(rows,cols,data)

This function is a way to modify the data as though it were a matrix.

Arguments
rows - Which rows to modify. These can be numeric or names.
cols - Which cols to modify. These can be numeric or names.
data - The data to change the chosen values to. It needs to be the right shape.

scale(f,mutate=TRUE)

This function rescales each element of our object according to f

Arguments
f - a function which takes in a number and outputs a rescaled version of that number
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
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)

Select the data corresponding to the rows rows and the columns columns. rows and columns can be either numeric or named indices.

Arguments
rows - An row index or list of row indices which can be either numeric or named.
cols - An column index or list of column indices which can be either numeric or named.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
Value

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

tail(k,direction=2,mutate=TRUE)

Select the last k slices of the data in dimension direction.

Arguments
k - The number of slices to keep.
direction - The dimension to take a subset of. 1 for row, 2 for column.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
Value

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

undebug(string)

A function for ceasing to debug methods. Normally a method will call the browser command every time it is run. This command will stop it from doing so.

Arguments
string - The name(s) of the methods to stop debugging.

See Also

Inherits from : AbstractIncidenceMatrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
data = IncidenceMatrix$new(matrix(1:9,3,3))
data$mat
data$nrow
data$ncol
data$colData = list(1:3,letters[1:3])
data$colData
data$addColumns(2)
data$colData
data$mat
data$diff(1)
data$mat
data$lag(1)
data$mat
data$head(1,1)
data$mat
data$tail(2,2)
data$mat
data$mutate(data=3)
data$mat
data = IncidenceMatrix$new(matrix(1:9,3,3))
data$scale(function(x){x^2},mutate=FALSE)$mat
data$mat
data$subset(rows=1,cols=2)
data$mat

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