Learn R Programming

uniLasso (version 2.11)

uniInfo: Create the univariate info for use in uniLasso

Description

Fit p separate univariate fits, and if requested computes the loo fit matrix F. It is called internally by uniLasso, or can be called externally on separate data and passed as input to uniLasso. Currently this function can accommodate "gaussian", "binomial", and "Cox" families.

Usage

uniInfo(
  X,
  y,
  family = c("gaussian", "binomial", "cox"),
  weights = NULL,
  nit = 2,
  loo = FALSE,
  ridge = 0,
  eps = 1e-06
)

Value

a list with components $beta and $beta0, and if loo=TRUE, a n x p matrix F with the loo fits.

Arguments

X

An n x p feature matrix

y

A response object, depending on the family. For "gaussian" it is just a response vector. For "binomial" either a binary vector, a two level factor, or a two column non-negative matrix with rows summing to 1. For "cox" it is a Surv object (currently for right censored data).

family

one of "gaussian","binomial" or "cox". Currently only these families are implemented. In the future others will be added.

weights

Vector of non-negative weights. Default is NULL, which results in all weights equal to 1.

nit

Number of iterations if Newton steps are required (in "binomial" and "cox"). Default is 2. In principal more is better, but in some cases can run into convergence issues.

loo

A logical, default=FALSE. If TRUE it computes the matrix of loo fits F.

ridge

A positive number that penalizes the square of the slope parameters. This is useful if some of the variables are nearly constant, or have very small variances. Default is 0.0.

eps

A small number to regularize the hessian for "cox"; default is 1e-6.

Examples

Run this code
# Gaussian model
set.seed(1)
sigma=3
n <- 100; p <- 20
x <- matrix(rnorm(n * p), n, p)
beta <- matrix(c(rep(2, 5), rep(0, 15)), ncol = 1)
y <- x %*% beta + rnorm(n)*sigma


info = uniInfo(x,y)
names(info)

yb = as.numeric(y>0)
info = uniInfo(x,yb, family = "binomial", loo = TRUE)
names(info)

Run the code above in your browser using DataLab