newdata_to_X: Convert data frame of covariate values to a design matrix

View source: R/model_utils.R

newdata_to_XR Documentation

Convert data frame of covariate values to a design matrix

Description

Convert data frame of covariate values to a design matrix

Usage

newdata_to_X(newdata, wide, intercept = TRUE)

Arguments

newdata

Data frame where each row is a vector of covariate values defining an alternative focus quantity.

wide

Wide model which includes these covariates.

intercept

Include an intercept as the first column.

Details

Numeric values can be supplied for factor levels that are character strings denoting numbers (like "1" or "2").

Value

"Design" matrix of covariate values defining alternative focuses, with factors expanded to their contrasts. This is in the form required by the X argument of fic, with one row per alternative focus. The columns correspond to coefficients in a linear-type model. For the built-in focus functions such as mean_normal and prob_logistic, these coefficients include an intercept, but user-written focuses may be written in such a way as not to require an intercept (as in the example in the "skew normal" vignette).

Examples

bwt.glm <- glm(low ~ lwtkg + age + smoke + ftv, data=birthwt, family="binomial")
newdata <- data.frame(lwtkg=1, age=60, smoke=0, ftv="2+")
newdata_to_X(newdata, bwt.glm)

## See the Cox regression section of the main package vignette for another example.


chjackson/fic documentation built on Aug. 30, 2023, 6:48 p.m.