|
1 | 1 | # ------------------------------------------------------------------------------ |
2 | 2 |
|
3 | | -#' Helper functions to convert from formula to matrix interface |
| 3 | +#' Helper functions to convert between formula and matrix interface |
4 | 4 | #' |
5 | 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 |
| 6 | +#' objects (y, x, weights, etc) back or the other way around. The functions are |
| 7 | +#' intended for developer use. For the most part, this emulates the internals |
| 8 | +#' of `lm` (and also see the notes at |
8 | 9 | #' https://developer.r-project.org/model-fitting-functions.html). |
9 | 10 | #' |
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.). |
| 11 | +#' `convert_form_to_xy_fit()` and `convert_xy_to_form_fit()` are for when the |
| 12 | +#' data are created for modeling. |
| 13 | +#' `convert_form_to_xy_fit()` saves both the data objects as well as the objects |
| 14 | +#' needed when new data are predicted (e.g. `terms`, etc.). |
13 | 15 | #' |
14 | | -#' `convert_form_to_xy_new` is used when new samples are being predicted and |
15 | | -#' only requires the predictors to be available. |
| 16 | +#' `convert_form_to_xy_new()` and `convert_xy_to_form_new()` are used when new |
| 17 | +#' samples are being predicted and only require the predictors to be available. |
16 | 18 | #' |
17 | 19 | #' @param data A data frame containing all relevant variables (e.g. outcome(s), |
18 | 20 | #' predictors, case weights, etc). |
@@ -155,6 +157,7 @@ convert_form_to_xy_fit <- function(formula, |
155 | 157 |
|
156 | 158 |
|
157 | 159 | #' @param object An object of class `model_fit`. |
| 160 | +#' @inheritParams predict.model_fit |
158 | 161 | #' @rdname convert_helpers |
159 | 162 | #' @keywords internal |
160 | 163 | #' @export |
@@ -230,9 +233,21 @@ convert_form_to_xy_new <- function(object, |
230 | 233 | # The other direction where we make a formula from the data |
231 | 234 | # objects |
232 | 235 |
|
233 | | -#' @importFrom dplyr bind_cols |
234 | 236 | # TODO slots for other roles |
235 | | -convert_xy_to_form_fit <- function(x, y, weights = NULL, y_name = "..y", |
| 237 | +#' @param weights A numeric vector containing the weights. |
| 238 | +#' @param y_name A string specifying the name of the outcome. |
| 239 | +#' @inheritParams fit.model_spec |
| 240 | +#' @inheritParams convert_form_to_xy_fit |
| 241 | +#' |
| 242 | +#' @rdname convert_helpers |
| 243 | +#' @keywords internal |
| 244 | +#' @export |
| 245 | +#' |
| 246 | +#' @importFrom dplyr bind_cols |
| 247 | +convert_xy_to_form_fit <- function(x, |
| 248 | + y, |
| 249 | + weights = NULL, |
| 250 | + y_name = "..y", |
236 | 251 | remove_intercept = TRUE) { |
237 | 252 | if (is.vector(x)) |
238 | 253 | rlang::abort("`x` cannot be a vector.") |
@@ -279,6 +294,9 @@ convert_xy_to_form_fit <- function(x, y, weights = NULL, y_name = "..y", |
279 | 294 | res |
280 | 295 | } |
281 | 296 |
|
| 297 | +#' @rdname convert_helpers |
| 298 | +#' @keywords internal |
| 299 | +#' @export |
282 | 300 | convert_xy_to_form_new <- function(object, new_data) { |
283 | 301 | new_data <- new_data[, object$x_var, drop = FALSE] |
284 | 302 | if (!is.data.frame(new_data)) |
|
0 commit comments