predict.gamlasso: Prediction from a fitted gamlasso model

Description Usage Arguments Details Value See Also Examples

View source: R/output.R

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

1
2
3
4
5
6
7
8
9
## 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 gamlasso as produced by gamlasso

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 object is returned. If provided then the variable names (column names) should match with the variable names used to fit object: the code throws an error if not.

type

When this has the value "link" (default) then the linear predictor (with offset added if needed) is returned. When type = "response" predictions on the response scale is returned, depending on the family used while fitting object.

s

Value of the lasso penalty parameter lambda at which predictions are required. Default is "lambda.min" but alternatively "lambda.1se" can be used.

new.event.times

A vector of new event times to be used for predicting survival times when type = "response" for a gamlasso object fitted with family = "cox"

...

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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

plsmselect documentation built on Dec. 1, 2019, 1:11 a.m.