glmnetcr: Fit a Penalized Constrained Continuation Ratio Model Using...

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Fit a constrained continuation ratio model via penalized maximum likelihood. The regularization path is computed for the lasso or elasticnet penalty at a grid of values for the regularization parameter lambda. Can deal with all shapes of data, including very large sparse data matrices.

Usage

1
2
3
4
5
6
glmnetcr(x, y, method = "backward", weights = NULL, offset = NULL, alpha = 1,
nlambda = 100, lambda.min.ratio = NULL, lambda = NULL, standardize = TRUE,
thresh = 1e-04,  exclude = NULL, penalty.factor = NULL, maxit = 100,
dfmax = nvars + 1, pmax = min(dfmax * 2 + 20, nvars),
type.logistic = c("Newton","modified.Newton"),
trace.it = 0 )

Arguments

x

input data, of dimension nobs x nvars; each row is an observation vector. Can be in sparse column format (class "dgCMatrix" as in package Matrix)

y

ordinal response variable

method

select between fitting a backward (default) versus a forward continuation ratio model

weights

observation weights. Can be total counts if responses are proportion matrices. Default is 1 for each observation

offset

A vector of length nobs that is included in the linear predictor (a nobs x nc matrix for the "multinomial" family). Useful for the "poisson" family (e.g. log of exposure time), or for refining a model by starting at a current fit. Default is NULL. If supplied, then values must also be supplied to the predict.glmnet.cr function.

alpha

The elasticnet mixing parameter, with 0<α≤ 1. The penalty is defined as

(1-α)/2||β||_2^2+α||β||_1.

alpha=1 is the lasso penalty.

nlambda

The number of lambda values - default is 100.

lambda.min.ratio

Smallest value for lambda, as a fraction of lambda.max, the (data derived) entry value (i.e. the smallest value for which all coefficients are zero). The default depends on the sample size nobs relative to the number of variables nvars. If nobs > nvars, the default is 0.0001, close to zero. If nobs < nvars, the default is 0.01. A very small value of lambda.min.ratio will lead to a saturated fit in the nobs < nvars case. This is undefined for "binomial" and "multinomial" models, and glmnet will exit gracefully when the percentage deviance explained is almost 1.

lambda

A user supplied lambda sequence. Typical usage is to have the program compute its own lambda sequence based on nlambda and lambda.min.ratio. Supplying a value of lambda overrides this. WARNING: use with care. Do not supply a single value for lambda (for predictions after CV use predict() instead). Supply instead a decreasing sequence of lambda values. glmnet relies on its warms starts for speed, and its often faster to fit a whole path than compute a single fit.

standardize

Logical flag for variable standardization, prior to fitting the model sequence. The coefficients are always returned on the original scale. Default is standardize=TRUE. If variables are in the same units already, you might not wish to standardize.

thresh

Convergence threshold for coordinate descent. Each inner coordinate-descent loop continues until the maximum change in the objective after any coefficient update is less than thresh times the null deviance. Defaults value is 1E-6.

exclude

Indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor (next item).

penalty.factor

Separate penalty factors can be applied to each coefficient. This is a number that multiplies lambda to allow differential shrinkage. Can be 0 for some variables, which implies no shrinkage, and that variable is always included in the model. Default is 1 for all variables (and implicitly infinity for variables listed in exclude).

maxit

Maximum number of outer-loop iterations for "binomial" or "multinomial" families. Default is 100.

dfmax

Limit the maximum number of variables in the model. Useful for very large nvars, if a partial path is desired.

pmax

Limit the maximum number of variables ever to be nonzero.

type.logistic

If "Newton" then the exact hessian is used (default), while "modified.Newton" uses an upper-bound on the hessian, and can be faster.

trace.it

If trace.it=1, then a progress bar is displayed; useful for big models that take a long time to fit.

Details

The sequence of models implied by lambda is fit by coordinate descent. This is a lasso or elasticnet regularization path for fitting the generalized linear regression paths, by maximizing the appropriate penalized log-likelihood. Sometimes the sequence is truncated before nlambda values of lambda have been used, because of instabilities in the inverse link functions near a saturated fit. This function invokes glmnet(...,family="binomial") which fits a traditional logistic regression model for the log-odds. The penalties take care of redundancies.

Value

call

the call that produced this object

a0

Intercept sequence of length length(lambda)

beta

a nvars x length(lambda) matrix of coefficients

lambda

The actual sequence of lambda values used

dev

The fraction of (null) deviance explained (for "elnet", this is the R-square). The deviance calculations incorporate weights if present in the model. The deviance is defined to be -2*(loglike_sat - loglike), where loglike_sat is the log-likelihood for the saturated model (a model with a free parameter per observation). Hence dev.fraction=1-dev/nulldev.

nulldev

Null deviance (per observation). This is defined to be -2*(loglike_sat -loglike(Null)); The NULL model refers to the intercept model.

df

The number of nonzero coefficients for each value of lambda.

dfmat

Appliable for "multnet" only so does not apply to the CR model. A matrix consisting of the number of nonzero coefficients per class

dim

dimension of coefficient matrix (ices)

nobs

number of observations

npasses

total passes over the data summed over all lambda values

offset

a logical variable indicating whether an offset was included in the model

jerr

error flag, for warnings and errors (largely for internal debugging).

x

returns the original data matrix. Useful for predict and fitted functions

y

returns the original ordinal response. Useful for predict and fitted functions

method

returns the continuation ratio method (forward or backward). Useful for predict and fitted functions

Note

This function depends heavily upon the glmnet function in the glmnet package written by Jerome Friedman, Trevor Hastie and Rob Tibshirani

Author(s)

Kellie J. Archer, archer.43@osu.edu

See Also

See Also as glmnet, select.glmnetcr, fitted.glmnetcr

Examples

1
2
3
4
5
6
7
8
9
data(diabetes)

x <- diabetes[, 2:dim(diabetes)[2]]

y <- diabetes$y

glmnet.fit <- glmnetcr(x, y)

fitted(glmnet.fit, s = select.glmnetcr(glmnet.fit))

Example output

Loading required package: glmnet
Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-16

Warning message:
from glmnet Fortran code (error code -26); Convergence for 26th lambda value not reached after maxit=100 iterations; solutions for larger lambdas returned 
$BIC
     s23 
33.76674 

$AIC
     s23 
29.05452 

$class
 [1] "control"                  "control"                 
 [3] "control"                  "control"                 
 [5] "control"                  "control"                 
 [7] "control"                  "control"                 
 [9] "impaired fasting glucose" "control"                 
[11] "impaired fasting glucose" "impaired fasting glucose"
[13] "impaired fasting glucose" "impaired fasting glucose"
[15] "impaired fasting glucose" "type 2 diabetes"         
[17] "type 2 diabetes"          "type 2 diabetes"         
[19] "type 2 diabetes"          "type 2 diabetes"         
[21] "type 2 diabetes"          "type 2 diabetes"         
[23] "type 2 diabetes"          "type 2 diabetes"         

$probs
          control impaired fasting glucose type 2 diabetes
 [1,] 0.637759660                0.2968232      0.06541710
 [2,] 0.742789960                0.2154169      0.04179319
 [3,] 0.684967374                0.2608598      0.05417284
 [4,] 0.823974148                0.1494688      0.02655706
 [5,] 0.678639532                0.2657438      0.05561666
 [6,] 0.724791677                0.2297116      0.04549669
 [7,] 0.711520081                0.2401679      0.04831200
 [8,] 0.721282138                0.2324838      0.04623405
 [9,] 0.184716536                0.5184572      0.29682629
[10,] 0.484526771                0.4040373      0.11143589
[11,] 0.133808976                0.5043899      0.36180108
[12,] 0.162057619                0.5146922      0.32325022
[13,] 0.106676146                0.4864906      0.40683329
[14,] 0.188845436                0.5187891      0.29236544
[15,] 0.208919007                0.5190637      0.27201725
[16,] 0.022632656                0.3065999      0.67076742
[17,] 0.024619264                0.3163697      0.65901106
[18,] 0.010433956                0.2251335      0.76443251
[19,] 0.008090478                0.2021177      0.78979178
[20,] 0.024136568                0.3140570      0.66180641
[21,] 0.007500334                0.1956351      0.79686456
[22,] 0.024556421                0.3160707      0.65937286
[23,] 0.012003293                0.2386296      0.74936710
[24,] 0.007139356                0.1915041      0.80135657

glmnetcr documentation built on July 8, 2020, 6:21 p.m.