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()).
Value
A list representing the sparse matrix, containing:
nw: Count of non-zero elements inmat.w: Vector of non-zero elements inmat. Equivalent to the numeric values frommatexcluding zeros.nv: Length of v.v: Vector of row indices corresponding to each non-zero element inw. Indicates the row location inmatfor each non-zero value.nu: Length of u.u: Vector indicating the starting indices inwfor non-zero elements of each row inmat. Helps identify the partition ofwinto different rows ofmat.
See also
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()
Examples
mat <- matrix(1:12, nrow = 4)
mat[2, 2] <- 0
mat[3, 1] <- 0
extract_sparse_matrix(mat)
#> Warning: `extract_sparse_matrix()` was deprecated in epinowcast 0.5.0.
#> $nw
#> [1] 10
#>
#> $w
#> [1] 1 5 9 2 10 7 11 4 8 12
#>
#> $nv
#> [1] 10
#>
#> $v
#> [1] 1 2 3 1 3 2 3 1 2 3
#>
#> $nu
#> [1] 5
#>
#> $u
#> [1] 1 4 6 8 11
#>
