Learn R Programming

sparsenet (version 1.6)

gendata: Generate data for testing sparse model selection

Description

This function generates x/y data for testing sparsenet and glmnet

Usage

gendata(N, p, nonzero, rho, snr = 3, alternate = TRUE)

Value

A list with components x and y as well some other details about the dataset

Arguments

N

Sample size (eg 500)

p

Number of features or variables (eg 1000)

nonzero

Number if nonzero coefficients (eg 30)

rho

pairwise correlation between features

snr

Signal to noise ratio - SD signal/ SD noise - try 3

alternate

Alternate sign of coefficients

Author

Trevor Hastie and Jerome Friedman

Details

Generates Gaussian x and y data. The nonzero coefficients decrease linearly in absolute value from nonzero down to 0. If alternate=TRUE their signs alternate, else not

Examples

Run this code
train.data=gendata(100,1000,nonzero=30,rho=0.3,snr=3)
fit=sparsenet(train.data$x,train.data$y)
par(mfrow=c(3,3))
plot(fit)
par(mfrow=c(1,1))
fitcv=cv.sparsenet(train.data$x,train.data$y,trace.it=TRUE)
plot(fitcv)

Run the code above in your browser using DataLab