| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/joinerml.R |
| 3 |
\name{augment.mjoint} |
| 4 |
\alias{augment.mjoint} |
| 5 |
\title{Augment data with information from a(n) mjoint object} |
| 6 |
\usage{ |
| 7 |
\method{augment}{mjoint}(x, data = x$data, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{An \code{mjoint} object returned from \code{\link[joineRML:mjoint]{joineRML::mjoint()}}.} |
| 11 |
|
| 12 |
\item{data}{A \link[base:data.frame]{base::data.frame} or \code{\link[tibble:tibble]{tibble::tibble()}} containing the original |
| 13 |
data that was used to produce the object \code{x}. Defaults to |
| 14 |
\code{stats::model.frame(x)} so that \code{augment(my_fit)} returns the augmented |
| 15 |
original data. \strong{Do not} pass new data to the \code{data} argument. |
| 16 |
Augment will report information such as influence and cooks distance for |
| 17 |
data passed to the \code{data} argument. These measures are only defined for |
| 18 |
the original training data.} |
| 19 |
|
| 20 |
\item{...}{Additional arguments. Not used. Needed to match generic |
| 21 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 22 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 23 |
argument has a default value, the default value will be used. |
| 24 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 25 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 26 |
\itemize{ |
| 27 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 28 |
it will be ignored. |
| 29 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 30 |
will be ignored. |
| 31 |
}} |
| 32 |
} |
| 33 |
\value{ |
| 34 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with one row for each original observation |
| 35 |
with addition columns: |
| 36 |
\item{.fitted_j_0}{population-level fitted values for the |
| 37 |
j-th longitudinal process} |
| 38 |
\item{.fitted_j_1}{individuals-level fitted values for the j-th |
| 39 |
longitudinal process} |
| 40 |
\item{.resid_j_0}{population-level residuals for the j-th |
| 41 |
longitudinal process} |
| 42 |
\item{.resid_j_1}{individual-level residuals for the j-th |
| 43 |
longitudinal process} |
| 44 |
} |
| 45 |
\description{ |
| 46 |
Augment accepts a model object and a dataset and adds |
| 47 |
information about each observation in the dataset. Most commonly, this |
| 48 |
includes predicted values in the \code{.fitted} column, residuals in the |
| 49 |
\code{.resid} column, and standard errors for the fitted values in a \code{.se.fit} |
| 50 |
column. New columns always begin with a \code{.} prefix to avoid overwriting |
| 51 |
columns in the original dataset. |
| 52 |
|
| 53 |
Users may pass data to augment via either the \code{data} argument or the |
| 54 |
\code{newdata} argument. If the user passes data to the \code{data} argument, |
| 55 |
it \strong{must} be exactly the data that was used to fit the model |
| 56 |
object. Pass datasets to \code{newdata} to augment data that was not used |
| 57 |
during model fitting. This still requires that at least all predictor |
| 58 |
variable columns used to fit the model are present. If the original outcome |
| 59 |
variable used to fit the model is not included in \code{newdata}, then no |
| 60 |
\code{.resid} column will be included in the output. |
| 61 |
|
| 62 |
Augment will often behave differently depending on whether \code{data} or |
| 63 |
\code{newdata} is given. This is because there is often information |
| 64 |
associated with training observations (such as influences or related) |
| 65 |
measures that is not meaningfully defined for new observations. |
| 66 |
|
| 67 |
For convenience, many augment methods provide default \code{data} arguments, |
| 68 |
so that \code{augment(fit)} will return the augmented training data. In these |
| 69 |
cases, augment tries to reconstruct the original data based on the model |
| 70 |
object with varying degrees of success. |
| 71 |
|
| 72 |
The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the |
| 73 |
\strong{same number of rows} as the passed dataset. This means that the passed |
| 74 |
data must be coercible to a tibble. If a predictor enters the model as part |
| 75 |
of a matrix of covariates, such as when the model formula uses |
| 76 |
\code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented |
| 77 |
as a matrix column. |
| 78 |
|
| 79 |
We are in the process of defining behaviors for models fit with various |
| 80 |
\code{na.action} arguments, but make no guarantees about behavior when data is |
| 81 |
missing at this time. |
| 82 |
} |
| 83 |
\details{ |
| 84 |
See \code{\link[joineRML:fitted.mjoint]{joineRML::fitted.mjoint()}} and \code{\link[joineRML:residuals.mjoint]{joineRML::residuals.mjoint()}} for |
| 85 |
more information on the difference between population-level and |
| 86 |
individual-level fitted values and residuals. |
| 87 |
|
| 88 |
If fitting a joint model with a single longitudinal process, |
| 89 |
make sure you are using a named \code{list} to define the formula |
| 90 |
for the fixed and random effects of the longitudinal submodel. |
| 91 |
} |
| 92 |
\examples{ |
| 93 |
\dontshow{if (rlang::is_installed("joineRML")) withAutoprint(\{ # examplesIf} |
| 94 |
|
| 95 |
# broom only skips running these examples because the example models take a |
| 96 |
# while to generate—they should run just fine, though! |
| 97 |
\dontrun{ |
| 98 |
|
| 99 |
|
| 100 |
# load libraries for models and data |
| 101 |
library(joineRML) |
| 102 |
|
| 103 |
# fit a joint model with bivariate longitudinal outcomes |
| 104 |
data(heart.valve) |
| 105 |
|
| 106 |
hvd <- heart.valve[!is.na(heart.valve$log.grad) & |
| 107 |
!is.na(heart.valve$log.lvmi) & |
| 108 |
heart.valve$num <= 50, ] |
| 109 |
|
| 110 |
fit <- mjoint( |
| 111 |
formLongFixed = list( |
| 112 |
"grad" = log.grad ~ time + sex + hs, |
| 113 |
"lvmi" = log.lvmi ~ time + sex |
| 114 |
), |
| 115 |
formLongRandom = list( |
| 116 |
"grad" = ~ 1 | num, |
| 117 |
"lvmi" = ~ time | num |
| 118 |
), |
| 119 |
formSurv = Surv(fuyrs, status) ~ age, |
| 120 |
data = hvd, |
| 121 |
inits = list("gamma" = c(0.11, 1.51, 0.80)), |
| 122 |
timeVar = "time" |
| 123 |
) |
| 124 |
|
| 125 |
# extract the survival fixed effects |
| 126 |
tidy(fit) |
| 127 |
|
| 128 |
# extract the longitudinal fixed effects |
| 129 |
tidy(fit, component = "longitudinal") |
| 130 |
|
| 131 |
# extract the survival fixed effects with confidence intervals |
| 132 |
tidy(fit, ci = TRUE) |
| 133 |
|
| 134 |
# extract the survival fixed effects with confidence intervals based |
| 135 |
# on bootstrapped standard errors |
| 136 |
bSE <- bootSE(fit, nboot = 5, safe.boot = TRUE) |
| 137 |
tidy(fit, boot_se = bSE, ci = TRUE) |
| 138 |
|
| 139 |
# augment original data with fitted longitudinal values and residuals |
| 140 |
hvd2 <- augment(fit) |
| 141 |
|
| 142 |
# extract model statistics |
| 143 |
glance(fit) |
| 144 |
} |
| 145 |
\dontshow{\}) # examplesIf} |
| 146 |
} |