Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

matrix_converters

Coerce R objects to block or diagonal matrices


Description

These are simple functions that may be helpful to create the matrix objects that mrgsolve expects. Functions are named based on whether they create a diagonal matrix (d), a block matrix (b), or a a correlation matrix (c).

Usage

as_bmat(x, ...)

## S4 method for signature 'list'
as_bmat(x, ...)

## S4 method for signature 'numeric'
as_bmat(x, pat = "*", ...)

## S4 method for signature 'data.frame'
as_bmat(x, pat = "*", cols = NULL, ...)

## S4 method for signature 'ANY'
as_bmat(x, ...)

as_dmat(x, ...)

## S4 method for signature 'list'
as_dmat(x, ...)

## S4 method for signature 'ANY'
as_dmat(x, ...)

## S4 method for signature 'numeric'
as_dmat(x, pat = "*", ...)

## S4 method for signature 'data.frame'
as_dmat(x, pat = "*", cols = NULL, ...)

as_cmat(x, ...)

Arguments

x

data frame or list

...

arguments passed to dmat or bmat

pat

regular expression, character

cols

column names to use instead of pat

Details

Use as_dmat to create a diagonal matrix, as_bmat to create a block matrix, and as_cmat to create a block matrix where diagonal elements are understood to be correlations rather than covariances. as_cmat uses as_bmat to form the matrix and then converts off-diagonal elements to covariances before returning.

The methods for data.frame will work down the rows of the data frame and make the appropriate matrix from the data in each row. The result is a list of matrices.

Value

A numeric matrix for list and numeric methods. For data.frames, a list of matrices are returned.

See Also

Examples

df <- data.frame(
  OMEGA1.1 = c(1,2),
  OMEGA2.1 = c(11,22),
  OMEGA2.2 = c(3,4),
  SIGMA1.1 = 1,
  FOO=-1
)

as_bmat(df, "OMEGA")
as_dmat(df,"SIGMA")
as_dmat(df[1,],"OMEGA")

mrgsolve

Simulate from ODE-Based Models

v0.11.1
GPL (>= 2)
Authors
Kyle T Baron [aut, cre] (<https://orcid.org/0000-0001-7252-5656>), Bill Gillespie [ctb], Charles Margossian [ctb], Devin Pastoor [ctb], Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>), Dilawar Singh [ctb], Felicien Le Louedec [ctb] (<https://orcid.org/0000-0003-3699-2729>), Timothy Waterhouse [ctb] (<https://orcid.org/0000-0002-0954-9660>), Metrum Research Group [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.