|
19 | 19 | #'
|
20 | 20 | #' @param data A data frame containing all relevant variables (e.g. outcome(s),
|
21 | 21 | #' predictors, case weights, etc).
|
22 |
| -#' @param ... Additional arguments passed to [stats::model.frame()] and |
23 |
| -#' specification of `offset`. |
| 22 | +#' @param ... Additional arguments passed to [stats::model.frame()]. |
24 | 23 | #' @param na.action A function which indicates what should happen when the data
|
25 | 24 | #' contain NAs.
|
26 | 25 | #' @param indicators A string describing whether and how to create
|
|
55 | 54 | mf_call[[names(dots)[i]]] <- get_expr(dots[[i]])
|
56 | 55 | }
|
57 | 56 |
|
58 |
| - # For new data, save the expression to create offsets (if any) |
59 |
| - if (any(names(dots) == "offset")) { |
60 |
| - offset_expr <- get_expr(dots[["offset"]]) |
61 |
| - } else { |
62 |
| - offset_expr <- NULL |
63 |
| - } |
64 |
| - |
65 | 57 | mod_frame <- eval_tidy(mf_call)
|
66 | 58 | mod_terms <- attr(mod_frame, "terms")
|
67 | 59 |
|
|
81 | 73 | rlang::abort("`weights` must be a numeric vector")
|
82 | 74 | }
|
83 | 75 |
|
84 |
| - offset <- as.vector(model.offset(mod_frame)) |
85 |
| - if (!is.null(offset)) { |
86 |
| - if (length(offset) != nrow(mod_frame)) { |
87 |
| - rlang::abort( |
88 |
| - glue::glue("The offset data should have {nrow(mod_frame)} elements.") |
89 |
| - ) |
90 |
| - } |
91 |
| - } |
| 76 | + # TODO: Do we actually use the offset when fitting? |
| 77 | + # Extract any inline offsets specified in the formula from the model frame |
| 78 | + offset <- model.offset(mod_frame) |
92 | 79 |
|
93 | 80 | if (indicators != "none") {
|
94 | 81 | if (indicators == "one_hot") {
|
|
127 | 114 | offset = offset,
|
128 | 115 | terms = mod_terms,
|
129 | 116 | xlevels = .getXlevels(mod_terms, mod_frame),
|
130 |
| - offset_expr = offset_expr, |
131 | 117 | options = options
|
132 | 118 | )
|
133 | 119 | } else {
|
|
144 | 130 | offset = offset,
|
145 | 131 | terms = mod_terms,
|
146 | 132 | xlevels = .getXlevels(mod_terms, mod_frame),
|
147 |
| - offset_expr = offset_expr, |
148 | 133 | options = options
|
149 | 134 | )
|
150 | 135 | }
|
|
168 | 153 | mod_terms <- object$terms
|
169 | 154 | mod_terms <- delete.response(mod_terms)
|
170 | 155 |
|
171 |
| - # Calculate offset(s). These can show up in-line in the formula |
172 |
| - # (in multiple places) and might also be as its own argument. If |
173 |
| - # there is more than one offset, we add them together. |
174 |
| - |
175 |
| - offset_cols <- attr(mod_terms, "offset") |
176 |
| - |
177 |
| - # If offset was done at least once in-line |
178 |
| - if (!is.null(offset_cols)) { |
179 |
| - offset <- rep(0, nrow(new_data)) |
180 |
| - for (i in offset_cols) { |
181 |
| - offset <- offset + |
182 |
| - eval_tidy( |
183 |
| - attr(mod_terms, "variables")[[i + 1]], |
184 |
| - new_data |
185 |
| - ) # use na.action here and below? |
186 |
| - } |
187 |
| - } else { |
188 |
| - offset <- NULL |
189 |
| - } |
190 |
| - |
191 |
| - if (!is.null(object$offset_expr)) { |
192 |
| - if (is.null(offset)) { |
193 |
| - offset <- rep(0, nrow(new_data)) |
194 |
| - } |
195 |
| - offset <- offset + eval_tidy(object$offset_expr, new_data) |
196 |
| - } |
197 |
| - |
198 | 156 | new_data <-
|
199 | 157 | model.frame(
|
200 | 158 | mod_terms,
|
|
208 | 166 | .checkMFClasses(cl, new_data)
|
209 | 167 | }
|
210 | 168 |
|
| 169 | + # TODO: Do we actually use the returned offsets anywhere for prediction? |
| 170 | + # Extract offset from model frame. Multiple offsets will be added together. |
| 171 | + # Offsets might have been supplied through the formula. |
| 172 | + offset <- model.offset(new_data) |
| 173 | + |
211 | 174 | if (object$options$indicators != "none") {
|
212 | 175 | if (object$options$indicators == "one_hot") {
|
213 | 176 | local_one_hot_contrasts()
|
@@ -322,7 +285,7 @@ local_one_hot_contrasts <- function(frame = rlang::caller_env()) {
|
322 | 285 | }
|
323 | 286 |
|
324 | 287 | check_form_dots <- function(x) {
|
325 |
| - good_args <- c("subset", "weights", "offset") |
| 288 | + good_args <- c("subset", "weights") |
326 | 289 | good_names <- names(x) %in% good_args
|
327 | 290 | if (any(!good_names)) {
|
328 | 291 | rlang::abort(
|
|
0 commit comments