predict.mfp2 | R Documentation |
mfp2
FitsObtains predictions from an mfp2
object.
## S3 method for class 'mfp2'
predict(
object,
newdata = NULL,
type = NULL,
terms = NULL,
terms_seq = c("equidistant", "data"),
alpha = 0.05,
ref = NULL,
strata = NULL,
newoffset = NULL,
...
)
object |
a fitted object of class |
newdata |
optionally, a matrix with column names in which to look for
variables with which to predict. See |
type |
the type of prediction required. The default is on the
scale of the linear predictors. See |
terms |
a character vector of variable names specifying for which
variables term or contrast predictions are desired.
Only used in case |
terms_seq |
a character string specifying how the range of variable
values for term predictions are handled. The default |
alpha |
significance level used for computing confidence intervals in terms prediction. |
ref |
a named list of reference values used when |
strata |
stratum levels used for predictions. |
newoffset |
A vector of offsets used for predictions. This parameter is important when newdata is supplied. The offsets will be directly added to the linear predictor without any transformations. |
... |
further arguments passed to |
To prepare the newdata
for prediction, this function applies any
necessary shifting and scaling based on the factors obtained from the
training data.
It is important to note that if the shifting factors are not sufficiently
large as estimated from the training data, variables in newdata
may end up
with negative values, which can cause prediction errors if non-linear
functional forms are used. A warning is given in this case by the function.
The next step involves transforming the data using the selected
fractional polynomial (FP) powers. If necessary, centering of variables is
conducted. Once the transformation (and centering) is complete, the
transformed data is passed to either predict.glm()
or predict.coxph()
,
depending on the chosen family of models and when type is not
terms
and contrasts
.
For any type
other than "terms"
the output conforms to the output
of predict.glm()
or predict.coxph()
.
If type = "terms"
or type = "contrasts"
, then a named list with entries
for each variable requested in terms
(excluding those not present in the
final model).
Each entry is a data.frame
with the following columns:
variable
: variable values on original scale.
variable_pre
: variable with pre-transformation applied, i.e. shifted,
scaled and centered as required.
value
: partial linear predictor or contrast (depending on type
).
se
: standard error of partial linear predictor or contrast.
lower
: lower limit of confidence interval.
upper
: upper limit of confidence interval.
This function allows to compute the partial linear predictors
for each variable selected into the final model if type = "terms"
. Note
that the results returned from this function are different from those of
predict.glm()
and predict.coxph()
since these functions do not take
into account that a single variable can be represented by multiple terms.
This functionality is useful to assess model fit, since it also allows to
draw data points based on residuals.
This functions allows to compute contrasts with reference to a specified
variable value if type = "contrasts"
. In this case, the fitted partial
predictors will be centered at the reference value (i.e. 0), and also
confidence intervals will have width 0 at that point.
mfp2()
, stats::predict.glm()
, survival::predict.coxph()
# Gaussian model
data("prostate")
x = as.matrix(prostate[,2:8])
y = as.numeric(prostate$lpsa)
# default interface
fit1 = mfp2(x, y, verbose = FALSE)
predict(fit1) # make predictions
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.