Description Usage Arguments Details Value Author(s) References Examples
View source: R/reference.datasets.R
Generate a random design matrix X and coefficient vector β
useful for simulations of (high dimensional) linear models.
In particular, the function rXb()
can be used to exactly
recreate the reference linear model datasets of the hdi paper.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | rXb(n, p, s0,
xtype = c("toeplitz", "exp.decay", "equi.corr"),
btype = "U[-2,2]",
permuted = FALSE, iteration = NA, do2S = TRUE,
x.par = switch(xtype,
"toeplitz" = 0.9,
"equi.corr" = 0.8,
"exp.decay" = c(0.4, 5)),
verbose = TRUE)
rX(n, p, xtype, permuted, do2S = TRUE,
par = switch(xtype,
"toeplitz" = 0.9,
"equi.corr" = 0.8,
"exp.decay" = c(0.4, 5)))
|
n |
integer; the sample size n (paper had always |
p |
integer; the number of coefficients in the linear
model. (paper had always |
s0 |
integer number of nonzero coefficients desired in the
model; hence at most |
xtype |
a |
btype |
a |
permuted |
logical specifying if the columns of the design matrix should be permuted. |
iteration |
integer or |
do2S |
logical indicating if in the case of |
x.par,par |
the parameters to be used for the design matrix. Must be a numeric vector of length one or two. The default uses the parameters also used in the hdi paper. |
verbose |
should the function give a message if seeds are being set? (logical). |
Generation of the design matrix X:
For all xtype
's, the X matrix will be multivariate
normal, with mean zero and (co)variance matrix Σ = C
determined from xtype
, x.par
and p as follows:
xtype = "toeplitz"
:C <- par ^ abs(toeplitz(0:(p-1)))
xtype = "equi.corr"
:Σ_{i,j} = \code{par} for i != j, and = 1 for i = j, i.e., on the diagonal.
xtype = "exp.decay"
:C <- solve(par[1] ^
abs(toeplitz(0:(p-1)) / par[2]))
rXb()
:A list
with components
the generated n * p design matrix X.
the generated coefficient vector β (‘beta’).
rX()
:the generated n * p design matrix X.
Ruben Dezeure dezeure@stat.math.ethz.ch
Dezeure, R., Bühlmann, P., Meier, L. and Meinshausen, N. (2015) High-dimensional inference: confidence intervals, p-values and R-software hdi. Statistical Science 30, 533–558.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Generate the first realization of the linear model with design matrix
## type Toeplitz and coefficients type uniform between -2 and 2
dset <- rXb(n = 80, p = 20, s0 = 3,
xtype = "toeplitz", btype = "U[-2,2]")
x <- dset$x
beta <- dset$beta
## generate 100 response vectors of this linear model
y <- as.vector( x %*% beta ) + replicate(100, rnorm(nrow(x)))
## Use 'beta_min' fulfilling beta's (non standard 'btype'):
str(ds2 <- rXb(n = 50, p = 12, s0 = 3,
xtype = "exp.decay", btype = "U[0.1, 5]"))
## Generate a design matrix of type "toeplitz"
set.seed(3) # making it reproducible
X3 <- rX(n = 800, p = 500, xtype = "toeplitz", permuted = FALSE)
## permute the columns
set.seed(3)
Xp <- rX(n = 800, p = 500, xtype = "toeplitz", permuted = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.