Return the model predictions of a ppLasso
or gr_ppLasso
object
Usage
# S3 method for class 'ppLasso'
predict(
fit,
data,
Z.char,
prov.char,
lambda,
which = 1:length(fit$lambda),
type = c("link", "response", "class", "vars", "nvars"),
...
)
# S3 method for class 'gr_ppLasso'
predict(
fit,
data,
Z.char,
prov.char,
lambda,
which = 1:length(fit$lambda),
type = c("link", "response", "class", "vars", "groups", "nvars", "ngroups",
"beta.norm"),
...
)
Arguments
- fit
a
ppLasso
orgr_ppLasso
.- data
an
dataframe
orlist
object that contains the variables for prediction.- Z.char
names of covariates in
data
as vector of character strings.- prov.char
name of provider IDs variable in
data
as a character string.- lambda
values of the regularization parameter lambda at which predictions are requested. For values of lambda not in the sequence of fitted models, linear interpolation is used.
- which
indices of the penalty parameter lambda at which predictions are required. By default, all indices are returned. If lambda is specified, this will override which.
- type
type of prediction:
link
: linear predictorsresponse
: fitted values (i.e.,exp(link)/(1 + exp(link))
)class
: the binomial outcome with the largest probabilityvars
: the indices for the non-zero coefficientsnvars
: the number of non-zero coefficientsgroups
: the indices for the non-zero groupsngroups
: the number of non-zero coefficientsbeta.norm
: L2 norm of the coefficients in each group
- ...
Examples
data(BinaryData)
data <- BinaryData$data
Y.char <- BinaryData$Y.char
prov.char <- BinaryData$prov.char
Z.char <- BinaryData$Z.char
fit <- pp.lasso(data, Y.char, Z.char, prov.char)
predict(fit, data, Z.char, prov.char, lambda = fit$lambda, type = "response")[1:10, 1:5]
#> 0.132 0.1202 0.1096 0.0998 0.091
#> [1,] 0.2874999 0.2996927 0.3106971 0.3206762 0.3297643
#> [2,] 0.2051302 0.2112109 0.2163924 0.2208163 0.2246015
#> [3,] 0.2051302 0.2191951 0.2321638 0.2441339 0.2551989
#> [4,] 0.3947391 0.4208778 0.4449423 0.4671087 0.4875485
#> [5,] 0.2345694 0.2340619 0.2330311 0.2316163 0.2299295
#> [6,] 0.3188411 0.3744516 0.4280555 0.4786478 0.5256182
#> [7,] 0.3924033 0.3836025 0.3752418 0.3673071 0.3597819
#> [8,] 0.3658512 0.3870533 0.4065558 0.4245437 0.4411742
#> [9,] 0.2298886 0.2256943 0.2215601 0.2175107 0.2135686
#> [10,] 0.3947391 0.4374814 0.4772352 0.5139266 0.5476058
predict(fit, data, Z.char, prov.char, lambda = 0.001, type = "class")[1:10]
#> [1] 1 0 0 1 0 1 0 1 0 1
predict(fit, data, Z.char, prov.char, lambda = 0.04, type = "vars")
#> Z1 Z3 Z4
#> 1 3 4
data(BinaryData)
data <- BinaryData$data
Y.char <- BinaryData$Y.char
prov.char <- BinaryData$prov.char
Z.char <- BinaryData$Z.char
group <- BinaryData$group
fit <- grp.lasso(data, Y.char, Z.char, prov.char, group = group)
predict(fit, data, Z.char, prov.char, lambda = fit$lambda, type = "response")[1:10, 1:5]
#> 0.0939 0.0856 0.078 0.071 0.0647
#> [1,] 0.2874998 0.2986935 0.3093832 0.3193357 0.3255634
#> [2,] 0.2051288 0.2100619 0.2149546 0.2191076 0.2136753
#> [3,] 0.2051288 0.2180235 0.2305894 0.2431181 0.2603558
#> [4,] 0.3947376 0.4185762 0.4419123 0.4646744 0.4888233
#> [5,] 0.2345683 0.2353836 0.2346598 0.2323132 0.2223927
#> [6,] 0.3188407 0.3711201 0.4233544 0.4745208 0.5275946
#> [7,] 0.3924044 0.3852951 0.3773617 0.3679648 0.3448889
#> [8,] 0.3658529 0.3891889 0.4090002 0.4266957 0.4552054
#> [9,] 0.2298861 0.2270617 0.2232482 0.2183580 0.2074687
#> [10,] 0.3947376 0.4344220 0.4731255 0.5103060 0.5458409
predict(fit, data, Z.char, prov.char, lambda = 0.001, type = "class")[1:10]
#> [1] 1 0 0 1 0 1 0 1 0 1
predict(fit, data, Z.char, prov.char, lambda = 0.04, type = "vars")
#> Z1 Z2 Z3 Z4
#> 1 2 3 4
predict(fit, data, Z.char, prov.char, lambda = 0.04, type = "groups")
#> [1] 1 2
#> Levels: 1 2 3