| predict.wbm | R Documentation |
These methods facilitate fairly straightforward predictions
and simulations from wbm models.
## S3 method for class 'wbm'
predict(
object,
newdata = NULL,
se.fit = FALSE,
raw = FALSE,
use.re.var = FALSE,
re.form = NULL,
type = c("link", "response"),
allow.new.levels = TRUE,
na.action = na.pass,
...
)
## S3 method for class 'wbm'
simulate(
object,
nsim = 1,
seed = NULL,
use.u = FALSE,
newdata = NULL,
raw = FALSE,
newparams = NULL,
re.form = NA,
type = c("link", "response"),
allow.new.levels = FALSE,
na.action = na.pass,
...
)
object |
a fitted model object |
newdata |
data frame for which to evaluate predictions. |
se.fit |
Return a list containing predictions and fixed-effect standard
errors? With |
raw |
Is |
use.re.var |
Unsupported; must be |
re.form |
(formula, |
type |
character string - either |
allow.new.levels |
logical if new levels (or NA values) in
|
na.action |
|
... |
When |
nsim |
positive integer scalar - the number of responses to simulate. |
seed |
an optional seed to be used in |
use.u |
(logical) if |
newparams |
new parameters to use in evaluating predictions,
specified as in the |
With no newdata, predictions use the fitted model's design matrix.
re.form = NA or ~0 excludes random effects; the default includes them.
With raw = FALSE, supply panel histories containing the original predictor
variables and the entity identifier. The outcome is not required unless it
also occurs as a predictor (for example, a lagged outcome). Within-person
means and detrending are calculated from the supplied histories, using the
variable roles, factor coding, basis parameters, and scaling saved at fitting.
Predictions are returned in the input row order. Include the wave variable
for models with time effects, detrending, lags, or leads. Do not use a
hypothetical plotting grid as a panel history: its means are arbitrary.
With raw = TRUE, supply prepared model-scale rows, including imean(...)
and processed interaction columns. These columns are passed through unchanged.
This argument is distinct from interaction.style = "raw" when fitting.
For models fitted with an offset argument, prepared rows must include
.offset; panel histories may instead contain the original offset variables.
Interaction plots
interactions::interact_plot() and interactions::cat_plot() use a separate
hypothetical-grid path through jtools::make_predictions(). With an
interactions version supporting plot.scale, the default plot.scale = "within"
displays numeric within-person predictors as deviations from each person's
observed mean, in original units even for standardized fits. Zero means at
the person's mean. Default predictor ranges use estimation-sample deviations;
numeric within-person moderators default to zero and plus/minus one pooled
within-person SD (or their observed values when there are only two).
Constant predictors/moderators retain their original units or categories.
The outcome remains on its modeled response scale, not a within-person
deviation. outcome.scale = "link" instead uses the model's link scale.
Use plot.scale = "original" for raw predictor levels. Plot captions report
reference person means, and values implying deviations outside the observed
within-person range trigger warnings. These marginal range checks do not
establish joint support or rule out other forms of extrapolation. User-supplied
numeric predictor/moderator values and at use the selected display scale;
imean(...) overrides always use original units. Custom labels are preserved.
Plot data must be the original fitting data or a subset with panel
identifiers; excluded estimation rows are dropped and subsets retain fitted
person means. Use at for hypothetical values, not modified plotting data.
Person means and interaction-product means are held at their observation-weighted averages
over the estimation sample, while focal predictors vary. This describes
conditional predictions, not population-average effects or forecasts for a
particular entity. Use at = list("imean(x)" = value) (and, when needed,
"imean(x:z)") to set different reference means. Time-invariant moderators
multiply the centered within-person term; their product means are not
independently held fixed as those moderators change. For a within-varying factor,
its reference means are the means of its indicator columns.
Direct calls to jtools::make_predictions() (and older interactions versions
without plot.scale) retain original-scale inputs. plot.scale is a plotting
option, not an argument to predict() or an estimation option.
Automatic plotting grids currently support scalar numeric/factor terms,
including two- and three-way interactions. Scalar transformations such as
log(x) require plot.scale = "original"; a deviation of log(x) is not
a deviation of x. Detrended, lagged/lead, and
basis-expansion models require complete panel histories for prediction or
explicitly prepared rows via make_predictions(..., new_data = ..., raw = TRUE).
Partial residuals, custom plotting covariance estimates, and prediction
intervals are not supported. Updated interactions versions provide S3
methods for sim_slopes(), johnson_neyman(), and probe_interaction().
Numeric focal predictors use exact design-matrix contrasts, not refitting or
recentering. Slopes share the plots' units and reference settings. Tests are
fixed-effect and link-scale: residual-df t approximations for Gaussian mixed
models, normal approximations for generalized models and GEE, with an explicit
df override. They are not Satterthwaite/Kenward-Roger tests. Nonlinear/factor
focal predictors, predictor-dependent offsets, rank-deficient fits, custom
covariance estimates, response-scale derivatives for non-identity links,
and FDR-adjusted Johnson-Neyman inference are not supported. These plotting
and slope conventions do not change the fitted estimator.
Models saved by older panelr versions must be refitted to use the new
panel-history and automatic-grid paths; prepared-row predictions remain available.
Analytic se.fit values describe fixed-effect uncertainty, conditional on
the preprocessing/reference quantities; response-scale standard errors use
the delta method. Plot bands are confidence intervals, not intervals for
individual outcomes. use.re.var = TRUE is rejected because the previous
variance-addition calculation did not yield valid prediction intervals.
data("WageData")
wages <- panel_data(WageData, id = id, wave = t)
model <- wbm(lwage ~ lag(union) + wks, data = wages)
# With no newdata, predictions use the fitted design.
predict(model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.