|
1 | 1 | # ------------------------------------------------------------------------------ |
2 | 2 |
|
3 | | -# Functions to take a formula interface and get the resulting |
4 | | -# objects (y, x, weights, etc) back. For the most part, this |
5 | | -# emulates the internals of `lm` (and also see the notes at |
6 | | -# https://developer.r-project.org/model-fitting-functions.html). |
7 | | - |
8 | | -# `convert_form_to_xy_fit` is for when the data are created for modeling. |
9 | | -# It saves both the data objects as well as the objects needed |
10 | | -# when new data are predicted (e.g. `terms`, etc.). |
11 | | - |
12 | | -# `convert_form_to_xy_new` is used when new samples are being predicted |
13 | | -# and only requires the predictors to be available. |
14 | | - |
| 3 | +#' Helper functions to convert between formula and matrix interface |
| 4 | +#' |
| 5 | +#' Functions to take a formula interface and get the resulting |
| 6 | +#' objects (y, x, weights, etc) back. For the most part, this |
| 7 | +#' emulates the internals of `lm` (and also see the notes at |
| 8 | +#' https://developer.r-project.org/model-fitting-functions.html). |
| 9 | +#' |
| 10 | +#' `convert_form_to_xy_fit` is for when the data are created for modeling. |
| 11 | +#' It saves both the data objects as well as the objects needed when new data |
| 12 | +#' are predicted (e.g. `terms`, etc.). |
| 13 | +#' |
| 14 | +#' `convert_form_to_xy_new` is used when new samples are being predicted and |
| 15 | +#' only requires the predictors to be available. |
| 16 | +#' |
| 17 | +#' @param data A data frame containing all relevant variables (e.g. outcome(s), |
| 18 | +#' predictors, case weights, etc). |
| 19 | +#' @param ... Additional arguments passed to [stats::model.frame()] and |
| 20 | +#' specification of `offset` and `contrasts`. |
| 21 | +#' @param na.action A function which indicates what should happen when the data |
| 22 | +#' contain NAs. |
| 23 | +#' @param indicators A string describing whether and how to create |
| 24 | +#' indicator/dummy variables from factor predictors. |
| 25 | +#' @param composition A string describing whether the resulting `x` and `y` |
| 26 | +#' should be returned as a `"matrix"` or a `"data.frame"`. |
| 27 | +#' @param remove_intercept A logical indicating whether to remove the intercept |
| 28 | +#' column after model.matrix() is finished. |
| 29 | +#' @inheritParams fit.model_spec |
| 30 | +#' @rdname convert_helpers |
| 31 | +#' @keywords internal |
| 32 | +#' @export |
| 33 | +#' |
15 | 34 | #' @importFrom stats .checkMFClasses .getXlevels delete.response |
16 | 35 | #' @importFrom stats model.offset model.weights na.omit na.pass |
| 36 | +convert_form_to_xy_fit <- function(formula, |
| 37 | + data, |
| 38 | + ..., |
| 39 | + na.action = na.omit, |
| 40 | + indicators = "traditional", |
| 41 | + composition = "data.frame", |
| 42 | + remove_intercept = TRUE) { |
17 | 43 |
|
18 | | -convert_form_to_xy_fit <- function( |
19 | | - formula, |
20 | | - data, |
21 | | - ..., |
22 | | - na.action = na.omit, |
23 | | - indicators = "traditional", |
24 | | - composition = "data.frame", |
25 | | - remove_intercept = TRUE |
26 | | -) { |
27 | 44 | if (!(composition %in% c("data.frame", "matrix"))) |
28 | 45 | rlang::abort("`composition` should be either 'data.frame' or 'matrix'.") |
29 | 46 |
|
@@ -136,8 +153,16 @@ convert_form_to_xy_fit <- function( |
136 | 153 | res |
137 | 154 | } |
138 | 155 |
|
139 | | -convert_form_to_xy_new <- function(object, new_data, na.action = na.pass, |
140 | | - composition = "data.frame") { |
| 156 | + |
| 157 | +#' @param object An object of class `model_fit`. |
| 158 | +#' @rdname convert_helpers |
| 159 | +#' @keywords internal |
| 160 | +#' @export |
| 161 | +convert_form_to_xy_new <- function(object, |
| 162 | + new_data, |
| 163 | + na.action = na.pass, |
| 164 | + composition = "data.frame") { |
| 165 | + |
141 | 166 | if (!(composition %in% c("data.frame", "matrix"))) |
142 | 167 | rlang::abort("`composition` should be either 'data.frame' or 'matrix'.") |
143 | 168 |
|
|
0 commit comments