|
a |
|
b/man/hsstan.Rd |
|
|
1 |
% Generated by roxygen2: do not edit by hand |
|
|
2 |
% Please edit documentation in R/stan.R |
|
|
3 |
\name{hsstan} |
|
|
4 |
\alias{hsstan} |
|
|
5 |
\title{Hierarchical shrinkage models} |
|
|
6 |
\usage{ |
|
|
7 |
hsstan( |
|
|
8 |
x, |
|
|
9 |
covs.model, |
|
|
10 |
penalized = NULL, |
|
|
11 |
family = gaussian, |
|
|
12 |
iter = 2000, |
|
|
13 |
warmup = floor(iter/2), |
|
|
14 |
scale.u = 2, |
|
|
15 |
regularized = TRUE, |
|
|
16 |
nu = ifelse(regularized, 1, 3), |
|
|
17 |
par.ratio = 0.05, |
|
|
18 |
global.df = 1, |
|
|
19 |
slab.scale = 2, |
|
|
20 |
slab.df = 4, |
|
|
21 |
qr = TRUE, |
|
|
22 |
seed = 123, |
|
|
23 |
adapt.delta = NULL, |
|
|
24 |
keep.hs.pars = FALSE, |
|
|
25 |
... |
|
|
26 |
) |
|
|
27 |
} |
|
|
28 |
\arguments{ |
|
|
29 |
\item{x}{Data frame containing outcome, covariates and penalized predictors. |
|
|
30 |
Continuous predictors and outcome variable should be standardized |
|
|
31 |
before fitting the models as priors assume them to have mean zero and |
|
|
32 |
unit variance.} |
|
|
33 |
|
|
|
34 |
\item{covs.model}{Formula containing the unpenalized covariates.} |
|
|
35 |
|
|
|
36 |
\item{penalized}{Names of the variables to be used as penalized predictors. |
|
|
37 |
Any variable that is already part of the \code{covs.model} formula will be |
|
|
38 |
penalized. If \code{NULL} or an empty vector, a model with only unpenalized |
|
|
39 |
covariates is fitted.} |
|
|
40 |
|
|
|
41 |
\item{family}{Type of model fitted: either \code{gaussian()} for linear regression |
|
|
42 |
(default) or \code{binomial()} for logistic regression.} |
|
|
43 |
|
|
|
44 |
\item{iter}{Total number of iterations in each chain, including warmup |
|
|
45 |
(2000 by default).} |
|
|
46 |
|
|
|
47 |
\item{warmup}{Number of warmup iterations per chain (by default, half the |
|
|
48 |
total number of iterations).} |
|
|
49 |
|
|
|
50 |
\item{scale.u}{Prior scale (standard deviation) for the unpenalized |
|
|
51 |
covariates.} |
|
|
52 |
|
|
|
53 |
\item{regularized}{If \code{TRUE} (default), the regularized horseshoe prior |
|
|
54 |
is used as opposed to the original horseshoe prior.} |
|
|
55 |
|
|
|
56 |
\item{nu}{Number of degrees of freedom of the half-Student-t prior on the |
|
|
57 |
local shrinkage parameters (by default, 1 if \code{regularized=TRUE} |
|
|
58 |
and 3 otherwise).} |
|
|
59 |
|
|
|
60 |
\item{par.ratio}{Expected ratio of non-zero to zero coefficients (ignored |
|
|
61 |
if \code{regularized=FALSE}). The scale of the global shrinkage parameter |
|
|
62 |
corresponds to \code{par.ratio} divided by the square root of the number of |
|
|
63 |
observations; for linear regression only, it's further multiplied by |
|
|
64 |
the residual standard deviation \code{sigma}.} |
|
|
65 |
|
|
|
66 |
\item{global.df}{Number of degrees of freedom for the global shrinkage |
|
|
67 |
parameter (ignored if \code{regularized=FALSE}). Larger values induce more |
|
|
68 |
shrinkage.} |
|
|
69 |
|
|
|
70 |
\item{slab.scale}{Scale of the regularization parameter (ignored if |
|
|
71 |
\code{regularized=FALSE}).} |
|
|
72 |
|
|
|
73 |
\item{slab.df}{Number of degrees of freedom of the regularization parameter |
|
|
74 |
(ignored if \code{regularized=FALSE}).} |
|
|
75 |
|
|
|
76 |
\item{qr}{Whether the thin QR decomposition should be used to decorrelate the |
|
|
77 |
predictors (\code{TRUE} by default). This is silently set to \code{FALSE} if |
|
|
78 |
there are more predictors than observations.} |
|
|
79 |
|
|
|
80 |
\item{seed}{Optional integer defining the seed for the pseudo-random number |
|
|
81 |
generator.} |
|
|
82 |
|
|
|
83 |
\item{adapt.delta}{Target average proposal acceptance probability for |
|
|
84 |
adaptation, a value between 0.8 and 1 (excluded). If unspecified, |
|
|
85 |
it's set to 0.99 for hierarchical shrinkage models and to 0.95 for |
|
|
86 |
base models.} |
|
|
87 |
|
|
|
88 |
\item{keep.hs.pars}{Whether the parameters for the horseshoe prior should be |
|
|
89 |
kept in the \code{stanfit} object returned (\code{FALSE} by default).} |
|
|
90 |
|
|
|
91 |
\item{...}{Further arguments passed to \code{\link[rstan:stanmodel-method-sampling]{rstan::sampling()}}, |
|
|
92 |
such as \code{chains} (4 by default), \code{cores} (the value of |
|
|
93 |
\code{options("mc.cores")} by default), \code{refresh} (\code{iter / 10} by default).} |
|
|
94 |
} |
|
|
95 |
\value{ |
|
|
96 |
An object of class \code{hsstan} containing the following fields: |
|
|
97 |
\item{stanfit}{an object of class \code{stanfit} containing the output |
|
|
98 |
produced by Stan, including posterior samples and diagnostic summaries. |
|
|
99 |
It can be manipulated using methods from the \strong{rstan} package.} |
|
|
100 |
\item{betas}{posterior means of the unpenalized and penalized regression |
|
|
101 |
parameters.} |
|
|
102 |
\item{call}{the matched call.} |
|
|
103 |
\item{data}{the dataset used in fitting the model.} |
|
|
104 |
\item{model.terms}{a list of names for the outcome variable, the unpenalized |
|
|
105 |
covariates and the penalized predictors.} |
|
|
106 |
\item{family}{the \code{family} object used.} |
|
|
107 |
\item{hsstan.settings}{the optional settings used in the model.} |
|
|
108 |
} |
|
|
109 |
\description{ |
|
|
110 |
Run the No-U-Turn Sampler (NUTS) as implemented in Stan to fit a hierarchical |
|
|
111 |
shrinkage model. |
|
|
112 |
} |
|
|
113 |
\examples{ |
|
|
114 |
\dontshow{oldopts <- options(mc.cores=2)} |
|
|
115 |
data(diabetes) |
|
|
116 |
|
|
|
117 |
# non-default settings for speed of the example |
|
|
118 |
df <- diabetes[1:50, ] |
|
|
119 |
hs.biom <- hsstan(df, Y ~ age + sex, penalized=colnames(df)[5:10], |
|
|
120 |
chains=2, iter=250) |
|
|
121 |
\dontshow{options(oldopts)} |
|
|
122 |
|
|
|
123 |
} |
|
|
124 |
\seealso{ |
|
|
125 |
\code{\link[=kfold]{kfold()}} for cross-validating a fitted object. |
|
|
126 |
} |