Predictions or log posterior predictive densities from a reference model
Source:R/refmodel.R
predict.refmodel.RdThis is the predict() method for refmodel objects (returned by
get_refmodel() or init_refmodel()). It offers three types of output which
are all based on the reference model and new (or old) observations: Either
the linear predictor on link scale, the linear predictor transformed to
response scale, or the log posterior predictive density.
Usage
# S3 method for class 'refmodel'
predict(
object,
newdata = NULL,
ynew = NULL,
offsetnew = NULL,
weightsnew = NULL,
type = "response",
...
)Arguments
- object
An object of class
refmodel(returned byget_refmodel()orinit_refmodel()).- newdata
Passed to argument
newdataof the reference model'sextract_model_datafunction (seeinit_refmodel()). Provides the predictor (and possibly also the response) data for the new (or old) observations. May also beNULLfor using the original dataset. If notNULL, anyNAs will trigger an error.- ynew
If not
NULL, then this needs to be a vector of new (or old) response values. See also section "Value" below. In case of (i) the augmented-data projection or (ii) the latent projection withtype = "response"andobject$family$catsbeing notNULL,ynewis internally coerced to afactor(usingas.factor()). The levels of thisfactorhave to be a subset ofobject$family$cats(seeextend_family()'s argumentsaugdat_y_unqsandlatent_y_unqs, respectively).- offsetnew
Passed to argument
orhsof the reference model'sextract_model_datafunction (seeinit_refmodel()). Used to get the offsets for the new (or old) observations.- weightsnew
Passed to argument
wrhsof the reference model'sextract_model_datafunction (seeinit_refmodel()). Used to get the weights for the new (or old) observations.- type
Usually only relevant if
is.null(ynew), but for the latent projection, this also affects the!is.null(ynew)case (see below). The scale on which the predictions are returned, either"link"or"response"(seepredict.glm()but note thatpredict.refmodel()does not adhere to the typical R convention of a default prediction on link scale). For both scales, the predictions are averaged across the posterior draws. In case of the latent projection, argumenttypeis similar in spirit to argumentresp_oscalefrom other functions: If (i)is.null(ynew), then argumenttypeaffects the predictions as described above. In that case, note thattype = "link"yields the linear predictors without any modifications that may be due to the original response distribution (e.g., for abrms::cumulative()model, the ordered thresholds are not taken into account). If (ii)!is.null(ynew), then argumenttypealso affects the scale of the log posterior predictive densities (type = "response"for the original response scale,type = "link"for the latent Gaussian scale).- ...
Currently ignored.
Value
In the following, \(N\), \(C_{\mathrm{cat}}\), and
\(C_{\mathrm{lat}}\) from help topic refmodel-init-get are used.
Furthermore, let \(C\) denote either \(C_{\mathrm{cat}}\) (if
type = "response") or \(C_{\mathrm{lat}}\) (if type = "link").
Then, if is.null(ynew), the returned object contains the reference
model's predictions (with the scale depending on argument type) as:
a length-\(N\) vector in case of (i) the traditional projection, (ii) the latent projection with
type = "link", or (iii) the latent projection withtype = "response"andobject$family$catsbeingNULL;an \(N \times C\) matrix in case of (i) the augmented-data projection or (ii) the latent projection with
type = "response"andobject$family$catsbeing notNULL.
If !is.null(ynew), the returned object is a length-\(N\) vector of log
posterior predictive densities evaluated at ynew.
Details
Argument weightsnew is only relevant if !is.null(ynew).
In case of a multilevel reference model, group-level effects for new group
levels are drawn randomly from a (multivariate) Gaussian distribution. When
setting projpred.mlvl_pred_new to TRUE, all group levels from newdata
(even those that already exist in the original dataset) are treated as new
group levels (if is.null(newdata), all group levels from the original
dataset are considered as new group levels in that case).