# NOT RUN {
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)
# }
# NOT RUN {
## 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)
# }
# NOT RUN {
# 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
# }
Run the code above in your browser using DataLab