extract_sparse_matrix: Extract sparse matrix elements

extract_sparse_matrixR Documentation

Extract sparse matrix elements

Description

This helper function allows the extraction of a sparse matrix from a matrix using a similar approach to that implemented in rstan::extract_sparse_parts() and returns these elements in a named list for use in stan. This function is used in the construction of the expectation model (see enw_expectation()).

Usage

extract_sparse_matrix(mat, prefix = "")

Arguments

mat

A matrix to extract the sparse matrix from.

prefix

A character string to prefix the names of the returned list.

Value

A list representing the sparse matrix, containing:

  • nw: Count of non-zero elements in mat.

  • w: Vector of non-zero elements in mat. Equivalent to the numeric values from mat excluding zeros.

  • nv: Length of v.

  • v: Vector of row indices corresponding to each non-zero element in w. Indicates the row location in mat for each non-zero value.

  • nu: Length of u.

  • u: Vector indicating the starting indices in w for non-zero elements of each row in mat. Helps identify the partition of w into different rows of mat.

See Also

enw_expectation()

Helper functions for model modules add_max_observed_delay(), add_pmfs(), convolution_matrix(), enw_reference_by_report(), enw_reps_with_complete_refs(), extract_obs_metadata(), latest_obs_as_matrix(), simulate_double_censored_pmf()

Examples

mat <- matrix(1:12, nrow = 4)
mat[2, 2] <- 0
mat[3, 1] <- 0
extract_sparse_matrix(mat)

seabbs/epinowcast documentation built on Aug. 28, 2024, 12:31 p.m.