Skip to contents

predict() returns fitted or predicted values for one distributional parameter of a drmTMB fit.

Usage

# S3 method for class 'drmTMB'
predict(object, newdata = NULL, dpar = NULL, type = c("response", "link"), ...)

Arguments

object

A drmTMB fit.

newdata

Optional data frame for prediction. If omitted, fitted rows are used. When supplied, newdata must include the predictors used by the requested dpar; required predictor values must be complete, required numeric predictors must be finite, and factor predictors must use fitted levels. Transformed predictor terms, such as log(size), must also evaluate to finite design-matrix values.

dpar

Distributional parameter to predict. If NULL, the first fitted distributional parameter is used.

type

Prediction scale: "response" or "link".

...

Reserved for future prediction options.

Value

A numeric vector.

Details

By default, predictions are returned on the distributional parameter's response scale. For positive scale parameters such as sigma, this means the exponentiated value. For bivariate residual correlation rho12 or a fitted corpair() model, this means the correlation scale. Use type = "link" to return the linear predictor instead.

When newdata = NULL, predictions are for the fitted rows and include currently implemented conditional random-effect contributions for mu, including registry-backed q > 2 ordinary covariance blocks, bivariate mu1/mu2, phylogenetic mu, and residual-scale sigma including bivariate sigma1/sigma2 blocks. When newdata is supplied, predictions are fixed-effect, population-level predictions for the supplied rows.

Examples

dat <- data.frame(
  y = c(0.2, 0.5, 1.1, 1.4, 1.8, 2.2),
  x = c(-1, -0.5, 0, 0.5, 1, 1.5)
)
fit <- drmTMB(bf(y ~ x, sigma ~ x), data = dat)
predict(fit, dpar = "mu")
#> [1] 0.1999935 0.5999948 0.9999961 1.3999974 1.7999987 2.2000000
predict(fit, dpar = "sigma")
#> [1] 2.515311e+03 1.515900e+01 9.135855e-02 5.505895e-04 3.318231e-06
#> [6] 1.999794e-08
predict(fit, dpar = "sigma", type = "link")
#> [1]   7.830152   2.718594  -2.392963  -7.504521 -12.616079 -17.727636
predict(fit, newdata = data.frame(x = c(0, 1)), dpar = "mu")
#> [1] 0.9999961 1.7999987