gendata: Generate data for testing sparse model selection

Description Usage Arguments Details Value Author(s) Examples

View source: R/gendata.R

Description

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

Usage

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

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

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

Value

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

Author(s)

Trevor Hastie and Jerome Friedman

Examples

1
2
3
4
5
6
7
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)

Example output

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

Loading required package: shape
Loaded sparsenet 1.2

12345678910

sparsenet documentation built on May 29, 2017, 2:19 p.m.