Description Usage Arguments Examples
View source: R/simulate_hierarchically_sparse_data.R
function to generate data with hierarchical sparsity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
ncats |
number of categories to stratify on |
nvars |
number of variables |
nobs |
number of observations per strata to simulate |
nobs.test |
number of independent test observations per strata to simulate |
hier.sparsity.param |
parameter between 0 and 1 which determines how much hierarchical sparsity there is. To achieve a desired total level of sparsity among the variables with hierarchical sparsity, this parameter can be estimated using the function 'estimate.hier.sparsity.param' |
avg.hier.zeros |
desired percent of zero variables among the variables with hierarchical zero patterns. If this is specified, it will override the given hier.sparsity.param value and estimate it. This takes a while |
prop.zero.vars |
proportion of all variables that will be zero across all strata |
effect.size.max |
maximum magnitude of the true effect sizes |
misspecification.prop |
proportion of variables with hierarchical missingness misspecified |
family |
family for the response variable |
sd |
standard devation for gaussian simulations |
snr |
signal-to-noise ratio (only used for |
beta |
a matrix of true beta values. If given, then no beta will be created and data will be simulated from the given beta |
tau |
rate parameter for |
covar |
scalar, pairwise covariance term for covariates |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | set.seed(123)
dat.sim <- genHierSparseData(ncats = 3, nvars = 100, nobs = 200)
# estimate hier.sparsity.param for 0.15 total proportion of nonzero variables
# among vars with hierarchical zero patterns
## Not run:
hsp <- estimate.hier.sparsity.param(ncats = 3, nvars = 50, avg.hier.zeros = 0.15, nsims = 100)
## End(Not run)
# the above results in the following value
hsp <- 0.6270698
# check that this does indeed achieve the desired level of sparsity
mean(replicate(50, mean(genHierSparseBeta(ncats = 3,
nvars = 50, hier.sparsity.param = hsp) != 0) ))
dat.sim2 <- genHierSparseData(ncats = 3, nvars = 100, nobs = 200, hier.sparsity.param = hsp)
sparseBeta <- genHierSparseBeta(ncats = 3, nvars = 100, hier.sparsity.param = hsp)
## generate data with already generated beta
dat.sim3 <- genHierSparseData(ncats = 3, nvars = 100, nobs = 200, beta = sparseBeta)
## complete example:
## 50% sparsity:
hsp <- 0.2626451
dat.sim <- genHierSparseData(ncats = 3, nvars = 25,
nobs = 150, nobs.test = 1000,
hier.sparsity.param = hsp,
prop.zero.vars = 0.5,
effect.size.max = 0.25,
family = "gaussian")
x <- dat.sim$x
x.test <- dat.sim$x.test
y <- dat.sim$y
y.test <- dat.sim$y.test
grp <- dat.sim$group.ind
grp.test <- dat.sim$group.ind.test
fit.adapt <- cv.vennLasso(x, y,
grp,
adaptive.lasso = TRUE,
nlambda = 25,
family = "gaussian",
abs.tol = 1e-5,
rel.tol = 1e-5,
maxit = 1000,
irls.maxit = 15L,
gamma = 0.2,
standardize = FALSE,
intercept = TRUE,
nfolds = 3,
model.matrix = TRUE)
preds.a <- predict(fit.adapt$vennLasso.fit, x.test, grp.test, s = fit.adapt$lambda.min,
type = 'response')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.