hsstan {hsstan} | R Documentation |
Hierarchical shrinkage models
Description
Run the No-U-Turn Sampler (NUTS) as implemented in Stan to fit a hierarchical shrinkage model.
Usage
hsstan(
x,
covs.model,
penalized = NULL,
family = gaussian,
iter = 2000,
warmup = floor(iter/2),
scale.u = 2,
regularized = TRUE,
nu = ifelse(regularized, 1, 3),
par.ratio = 0.05,
global.df = 1,
slab.scale = 2,
slab.df = 4,
qr = TRUE,
seed = 123,
adapt.delta = NULL,
keep.hs.pars = FALSE,
...
)
Arguments
x |
Data frame containing outcome, covariates and penalized predictors. Continuous predictors and outcome variable should be standardized before fitting the models as priors assume them to have mean zero and unit variance. |
covs.model |
Formula containing the unpenalized covariates. |
penalized |
Names of the variables to be used as penalized predictors.
Any variable that is already part of the |
family |
Type of model fitted: either |
iter |
Total number of iterations in each chain, including warmup (2000 by default). |
warmup |
Number of warmup iterations per chain (by default, half the total number of iterations). |
scale.u |
Prior scale (standard deviation) for the unpenalized covariates. |
regularized |
If |
nu |
Number of degrees of freedom of the half-Student-t prior on the
local shrinkage parameters (by default, 1 if |
par.ratio |
Expected ratio of non-zero to zero coefficients (ignored
if |
global.df |
Number of degrees of freedom for the global shrinkage
parameter (ignored if |
slab.scale |
Scale of the regularization parameter (ignored if
|
slab.df |
Number of degrees of freedom of the regularization parameter
(ignored if |
qr |
Whether the thin QR decomposition should be used to decorrelate the
predictors ( |
seed |
Optional integer defining the seed for the pseudo-random number generator. |
adapt.delta |
Target average proposal acceptance probability for adaptation, a value between 0.8 and 1 (excluded). If unspecified, it's set to 0.99 for hierarchical shrinkage models and to 0.95 for base models. |
keep.hs.pars |
Whether the parameters for the horseshoe prior should be
kept in the |
... |
Further arguments passed to |
Value
An object of class hsstan
containing the following fields:
stanfit |
an object of class |
betas |
posterior means of the unpenalized and penalized regression parameters. |
call |
the matched call. |
data |
the dataset used in fitting the model. |
model.terms |
a list of names for the outcome variable, the unpenalized covariates and the penalized predictors. |
family |
the |
hsstan.settings |
the optional settings used in the model. |
See Also
kfold()
for cross-validating a fitted object.
Examples
data(diabetes)
# non-default settings for speed of the example
df <- diabetes[1:50, ]
hs.biom <- hsstan(df, Y ~ age + sex, penalized=colnames(df)[5:10],
chains=2, iter=250)