|
4 | 4 | #' `brokenstick`. This object collects the fitted broken stick model.
|
5 | 5 | #'
|
6 | 6 | #' The package exports S3 methods for the `brokenstick` class for the following
|
7 |
| -#' generic functions: [fitted()], [model.frame()], [model.matrix()], [plot()], |
8 |
| -#' [predict()], [print()], [residuals()]. |
| 7 | +#' generic functions: [coef()], [fitted()], [model.frame()], [model.matrix()], |
| 8 | +#' [plot()], [predict()], [print()], [residuals()] and [summary()]. |
9 | 9 | #'
|
10 |
| -#' The package documents methods [fitted.brokenstick()], [plot.brokenstick()], |
11 |
| -#' [predict.brokenstick()] and [residuals.brokenstick()]. The package exports |
12 |
| -#' two helper functions for `brokenstick` objects: [get_knots()] and [get_r2()]. |
| 10 | +#' The package exports the following helper functions for `brokenstick` objects: |
| 11 | +#' [get_knots()], [get_omega()] and [get_r2()]. |
13 | 12 | #'
|
14 | 13 | #' A `brokenstick` object is a list with the following named elements:
|
15 | 14 | #'
|
16 | 15 | #' @section Elements:
|
17 | 16 | #' \describe{
|
18 |
| -#' \item{`names`}{A list with elements named `x`, `y` and `g` providing the |
19 |
| -#' variables names for the time, outcome and subject columns, respectively.} |
20 |
| -#' \item{`knots`}{Numeric vector of with the internal knots. Use [get_knots()] |
21 |
| -#' to extract knots.} |
22 |
| -#' \item{`boundary`}{Numeric vector of length 2 with the boundary knots. Use |
23 |
| -#' [get_knots()] to extract knots.} |
24 |
| -#' \item{`degree`}{The `degree` of the B-spline. See [splines::bs()]. Either |
25 |
| -#' 0 (constant model) or 1 (broken stick model).} |
26 |
| -#' \item{`model`}{Not used.} |
27 |
| -#' \item{`method`}{Either `lmer` or `kr`, identifying the fitting model.} |
28 |
| -#' \item{`control`}{List of control option returned by [control_brokenstick()].} |
| 17 | +#' \item{`call`}{Call that created the object} |
| 18 | +#' \item{`formula`}{A formula with the model specification, |
| 19 | +#' e.g. `formula(y ~ x | group)`} |
| 20 | +#' \item{`names`}{A named list with three elements (`"x"`, `"y"`, `"g"`) |
| 21 | +#' providing the variable name for time, outcome and subject, respectively.} |
| 22 | +#' \item{`internal`}{Numeric vector of with internal knots.} |
| 23 | +#' \item{`boundary`}{Numeric vector of length 2 with the boundary knots.} |
| 24 | +#' \item{`degree`}{The `degree` of the B-spline. See [splines::bs()]. Support |
| 25 | +#' only the values of 0 (step model) or 1 (broken stick model).} |
| 26 | +#' \item{`method`}{String, either `"kr"` or `"lmer"`, identifying the fitting model.} |
| 27 | +#' \item{`control`}{List of control options returned by [set_control()] used |
| 28 | +#' to set algorithmic details.} |
29 | 29 | #' \item{`beta`}{Numeric vector with fixed effect estimates.}
|
30 | 30 | #' \item{`omega`}{Numeric matrix with variance-covariance estimates of the
|
31 |
| -#' random effect.} |
| 31 | +#' broken stick estimates.} |
32 | 32 | #' \item{`sigma2j`}{Numeric vector with estimates of the residual variance per
|
33 |
| -#' group. Only used by method `kr`.} |
| 33 | +#' group. Only used by method `"kr"`.} |
34 | 34 | #' \item{`sigma2`}{Numeric scalar with the mean residual variance.}
|
35 |
| -#' \item{`draws`}{Numeric matrix with multiple imputations. The number of |
36 |
| -#' rows is equal to the number of missing values in `y`. The number of columns |
37 |
| -#' depends on `imp_skip`. Only used by `kr` if `imp_skip` is set.} |
| 35 | +#' \item{`sample`}{A numeric vector with descriptives of the training data.} |
| 36 | +#' \item{`light`}{Should the returned object be lighter? If `light = TRUE` |
| 37 | +#' the returned object will contain only the model settings and parameter |
| 38 | +#' estimates and not store the `sample`, `data`, `imp` and `mod` elements. |
| 39 | +#' The light object can be used to predict broken stick estimates for |
| 40 | +#' new data, but does not disclose the training data and is small.} |
| 41 | +#' \item{`data`}{The training data used to fit the model.} |
| 42 | +#' \item{`imp`}{The imputations generated for the missing outcome data. Only |
| 43 | +#' for `method = "kr"`.} |
| 44 | +#' \item{`mod`}{For `method = "kr"`: A named list with four components, each of |
| 45 | +#' class [coda::mcmc]. For `method = "lmer"`: An object of class |
| 46 | +#' [lme4::merMod-class].} |
38 | 47 | #' }
|
39 | 48 | #'
|
40 | 49 | #' @name brokenstick-class
|
41 | 50 | #' @rdname brokenstick-class
|
42 |
| -#' @author Stef van Buuren, 2020 |
43 |
| -#' @references van Buuren S (2020). |
| 51 | +#' @author Stef van Buuren, 2021 |
| 52 | +#' @references van Buuren S (2021). |
44 | 53 | #' Broken Stick Model for Irregular Longitudinal Data. \emph{In preparation}.
|
45 | 54 | NULL
|
| 55 | + |
| 56 | +new_brokenstick <- function(call = match.call(), |
| 57 | + formula = formula(), |
| 58 | + names = list(x = character(), |
| 59 | + y = character(), |
| 60 | + g = character()), |
| 61 | + internal = numeric(0), |
| 62 | + boundary = numeric(0), |
| 63 | + degree = 1L, |
| 64 | + method = NA_character_, |
| 65 | + control = list(), |
| 66 | + beta = numeric(0), |
| 67 | + omega = numeric(0), |
| 68 | + sigma2j = numeric(0), |
| 69 | + sigma2 = numeric(0), |
| 70 | + light = FALSE, |
| 71 | + sample = numeric(0), |
| 72 | + data = numeric(0), |
| 73 | + imp = numeric(0), |
| 74 | + mod = list()) { |
| 75 | + result <- list(call = call, |
| 76 | + formula = formula, |
| 77 | + names = names, |
| 78 | + internal = internal, |
| 79 | + boundary = boundary, |
| 80 | + degree = degree, |
| 81 | + method = method, |
| 82 | + control = control, |
| 83 | + beta = beta, |
| 84 | + omega = omega, |
| 85 | + sigma2j = sigma2j, |
| 86 | + sigma2 = sigma2, |
| 87 | + sample = sample, |
| 88 | + light = light) |
| 89 | + if (!light) { |
| 90 | + result$data <- data |
| 91 | + result$imp <- imp |
| 92 | + result$mod <- mod |
| 93 | + } |
| 94 | + class(result) <- "brokenstick" |
| 95 | + return(result) |
| 96 | +} |
0 commit comments