Skip to contents

The method of predict() for "mid" objects obtains predictions from a fitted MID model.

Usage

# S3 method for class 'mid'
predict(
  object,
  newdata = NULL,
  na.action = "na.pass",
  type = c("response", "link", "terms"),
  terms = object$terms,
  ...
)

mid.f(object, term, x, y = NULL)

Arguments

object

a "mid" object to be used to make predictions.

newdata

a data frame of the new observations.

na.action

a function or character string specifying what should happen when the data contain NAs.

type

the type of prediction required. The default is on the scale of the response varialbe. The alternative "link" is on the scale of the linear predictors. The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale.

terms

a character vector of term labels, specifying a subset of component functions to be used to make predictions.

...

not used.

term

a character string specifying the component function of a fitted MID model.

x

a matrix, data frame or vector to be used as the input to the first argument of the component function. If a matrix or data frame is passed, inputs for both x and y are extracted from it.

y

a vector to be used as the input to the second argument of the component function.

Value

predict.mid() returns a numeric vector of MID model predictions.

Details

The S3 method of predict() for MID models returns the model predictions. mid.f() works as a component function of a MID model.

Examples

data(trees, package = "datasets")
idx <- c(5L, 10L, 15L, 20L, 25L, 30L)
mid <- interpret(Volume ~ .^2, trees[-idx,], lambda = 1)
#> 'model' not passed: response variable in 'data' is used
trees[idx, "Volume"]
#> [1] 18.8 19.9 19.1 24.9 42.6 51.0
predict(mid, trees[idx,])
#> [1] 18.55337 20.58210 22.14285 23.46519 45.01464 57.83952
predict(mid, trees[idx,], type = "terms")
#>           Girth     Height Girth:Height
#> [1,] -12.738856  1.1216360 -0.189405623
#> [2,]  -8.033129 -1.7644569  0.019681599
#> [3,]  -6.497487 -1.7644569  0.044798668
#> [4,]  -1.870473 -4.7782653 -0.246067966
#> [5,]  15.096778 -0.4426815  0.000545126
#> [6,]  27.372413  0.1252837 -0.018178806
#> attr(,"constant")
#> [1] 30.36
mid.f(mid, "Girth", trees[idx,])
#> [1] -12.738856  -8.033129  -6.497487  -1.870473  15.096778  27.372413
mid.f(mid, "Girth:Height", trees[idx,])
#> [1] -0.189405623  0.019681599  0.044798668 -0.246067966  0.000545126
#> [6] -0.018178806
predict(mid, trees[idx,], terms = c("Girth", "Height"))
#> [1] 18.74278 20.56241 22.09806 23.71126 45.01410 57.85770