Create a list containing the parameters of a fitted linear regression model.
params_lm(coefs, sigma = 1)
Samples of the coefficients under sampling uncertainty.
Must be a matrix or any object coercible to a matrix such as data.frame
or data.table
.
A vector of samples of the standard error of the regression model. Default value is 1 for all samples. Only used if the model is used to randomly simulate values (rather than to predict means).
An object of class params_lm
, which is a list containing coefs
,
sigma
, and n_samples
. n_samples
is equal to the
number of rows in coefs
. The coefs
element is always converted into a
matrix.
Fitted linear models are used to predict values, \(y\), as a function of covariates, \(x\), $$y = x^T\beta + \epsilon.$$ Predicted means are given by \(x^T\hat{\beta}\) where \(\hat{\beta}\) is the vector of estimated regression coefficients. Random samples are obtained by sampling the error term from a normal distribution, \(\epsilon \sim N(0, \hat{\sigma}^2)\).
This parameter object is useful for modeling health state values
when values can vary across patients and/or health states as a function of
covariates. In many cases it will, however, be simpler, and more flexible to
use a stateval_tbl
. For an example use case see the documentation for
create_StateVals.lm()
.
library("MASS")
n <- 2
params <- params_lm(
coefs = mvrnorm(n, mu = c(.5,.6),
Sigma = matrix(c(.05, .01, .01, .05), nrow = 2)),
sigma <- rgamma(n, shape = .5, rate = 4)
)
summary(params)
#> parameter term mean sd 2.5% 97.5%
#> <char> <char> <num> <num> <num> <num>
#> 1: mean x1 0.70418903 0.30632380 0.4984155713 0.90996248
#> 2: mean x2 0.69168764 0.34385077 0.4607053849 0.92266989
#> 3: sd sigma 0.01540914 0.02178463 0.0007752786 0.03004299
params
#> A "params_lm" object
#>
#> Summary of coefficients:
#> parameter term mean sd 2.5% 97.5%
#> <char> <char> <num> <num> <num> <num>
#> 1: mean x1 0.7041890 0.3063238 0.4984156 0.9099625
#> 2: mean x2 0.6916876 0.3438508 0.4607054 0.9226699
#>
#> Summary of sigma:
#> parameter term mean sd 2.5% 97.5%
#> <char> <char> <num> <num> <num> <num>
#> 1: sd sigma 0.01540914 0.02178463 0.0007752786 0.03004299