gendata: Generate data for testing sparse model selection

View source: R/gendata.R

gendataR Documentation

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)

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

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)

sparsenet documentation built on Aug. 22, 2023, 9:11 a.m.