predict.gamlasso {plsmselect} | R Documentation |
Prediction from a fitted gamlasso model
Description
Takes a fitted gamlasso
object produced by gamlasso
and
returns predictions given a new set of values of the linear and smooth
variables.
Usage
## S3 method for class 'gamlasso'
predict(
object,
newdata = NULL,
type = "link",
s = "lambda.min",
new.event.times = NULL,
...
)
Arguments
object |
fitted model object of the class |
newdata |
A data frame with the values of the linear and smooth
variables for which predictions are to be made. If not provided then
predictions corresponding to the original data used to fit |
type |
When this has the value |
s |
Value of the lasso penalty parameter |
new.event.times |
A vector of new event times to be used for predicting
survival times when |
... |
Other arguments |
Details
Lasso models do not have standard errors so predict.gamlasso
does not provide them either. The standard errors for the gam part of the
model can be accesed by using mgcv::predict.gam
with suitable options.
Offsets are always included in the prediction if present in the original call
to gamlasso
. Also if type
is anything other than "link"
or "response"
then the function throws an error.
Value
Returns a vector of the same length as nrow(newdata)
with
the values of the linear predictor or on the response scale depending
on type
. For type = "link"
the value is simply the elementwise
sum of the predictions from the gam and lasso models in object
.
For type = "response"
the values are on the response scale, for
example exponential of the linear response is returned if
object$inherit$family = "poisson"
See Also
gamlasso
, predict.gam
,
predict.glmnet
.
Examples
library(plsmselect)
data(simData)
## Fit poisson gamlasso model using the term specification approach:
## (L2-penalty on linear terms & L2-penalty on smooth terms)
pfit = gamlasso(response="Yp",
linear.terms=paste0("x",1:10),
smooth.terms=paste0("z",1:4),
data=simData,
linear.penalty = "l2",
smooth.penalty = "l2",
family="poisson",
num.knots = 5,
seed=1)
## fitted values (of linear predictor):
fitted.values <- predict(pfit)
## predicted values on response scale:
pred.response <- predict(pfit, type="response", newdata=simData)
## For same model as above, but with L1-penalty on linear terms
## i.e. L1-penalty on the model matrix (X) we can use formula approach:
simData$X = model.matrix(~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10, data=simData)[,-1]
pfit = gamlasso(Yp ~ X +
s(z1, k=5) + # L2-penalty (bs="tp") is default (see ?mgcv::s)
s(z2, k=5) +
s(z3, k=5) +
s(z4, k=5),
family="poisson",
data = simData,
seed=1)
# See ?gamlasso for an example fitting a gaussian response model
# See ?summary.gamlasso for an example fitting a binomial response model
# See ?cumbasehaz for an example fitting a survival response model