Learn R Programming

glmnetcr (version 1.0.2)

glmnet.cr: Fit a Penalized Constrained Continuation Ratio Model Using Lasso or Elasticnet Regularization Via glmnet

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

glmnet.cr(x, y, method = "backward", weights, offset = NULL, alpha = 1, 
nlambda = 100, lambda.min.ratio = NULL, lambda = NULL, standardize = TRUE,
thresh = 1e-04,  exclude, penalty.factor = NULL, maxit = 100)

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
alpha
The elasticnet mixing parameter, with $0<\alpha\le 1$.="" the="" penalty="" is="" defined="" as="" $$(1-\alpha)="" 2||\beta||_2^2+\alpha||\beta||_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 th
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 over
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
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
maxit
Maximum number of outer-loop iterations for "binomial" or "multinomial" families. Default is 100.

Value

  • callthe call that produced this object
  • a0Intercept sequence of length length(lambda)
  • betaa nvars x length(lambda) matrix of coefficients
  • lambdaThe actual sequence of lambda values used
  • devThe 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.
  • nulldevNull deviance (per observation). This is defined to be -2*(loglike_sat -loglike(Null)); The NULL model refers to the intercept model.
  • dfThe number of nonzero coefficients for each value of lambda.
  • dfmatAppliable for "multnet" only so does not apply to the CR model. A matrix consisting of the number of nonzero coefficients per class
  • dimdimension of coefficient matrix (ices)
  • nobsnumber of observations
  • npassestotal passes over the data summed over all lambda values
  • offseta logical variable indicating whether an offset was included in the model
  • jerrerror flag, for warnings and errors (largely for internal debugging).
  • xreturns the original data matrix. Useful for predict and fitted functions
  • yreturns the original ordinal response. Useful for predict and fitted functions
  • methodreturns the continuation ratio method (forward or backward). Useful for predict and fitted functions

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.

See Also

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

Examples

Run this code
data(diabetes)

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

y <- diabetes$y

glmnet.fit <- glmnet.cr(x, y)

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

Run the code above in your browser using DataLab