shrinkem {shrinkem} | R Documentation |
The shrinkem
function can be used for regularizing a vector
of estimates using Bayesian shrinkage methods where the uncertainty of the estimates
are assumed to follow a Gaussian distribution.
shrinkem(
x,
Sigma,
type,
group,
iterations,
burnin,
store,
cred.level,
df1,
df2,
scale2,
lambda2.fixed,
lambda2,
...
)
x |
A vector of estimates. |
Sigma |
A covariance matrix capturing the uncertainty of the estimates (e.g., error covariance matrix). |
type |
A character string which specifies the type of regularization method is used. Currently, the types "ridge", "lasso", and "horseshoe", are supported. |
group |
A vector of integers denoting the group membership of the estimates, where each group receives a different global shrinkage parameter which is adapted to the observed data. |
iterations |
Number of posterior draws after burnin. Default = 5e4. |
burnin |
Number of posterior draws in burnin. Default = 1e3. |
store |
Store every store-th draw from posterior. Default = 1 (implying that every draw is stored). |
cred.level |
The significance level that is used to check whether a parameter is nonzero depending on whether
0 is contained in the credible interval. The default is |
df1 |
First hyperparameter (degrees of freedom) of the prior for a shrinkage parameter lambda^2, which follows a F(df1,df2,scale2)
distribution. The default is |
df2 |
Second hyperparameter (degrees of freedom) of the prior for a shrinkage parameter lambda^2, which follows a F(df1,df2,scale2)
distribution. The default is |
scale2 |
Second hyperparameter (scale parameter) of the prior for a shrinkage parameter lambda^2, which follows a F(df1,df2,scale2)
distribution. The default is |
lambda2.fixed |
Logical indicating whether the penalty parameters(s) is/are fixed. Default is FALSE. |
lambda2 |
Positive scalars of length equal to the number of groups in 'group'. The argument is only used if the argument 'lambda2.fixed' is 'TRUE'. |
... |
Parameters passed to and from other functions. |
The output is an object of class shrinkem
. The object has elements:
estimates
: A data frame with the input estimates, the shrunken posterior mean, median, and mode,
the lower and upperbound of the credbility interval based on the shrunken posterior, and a logical which indicates if
zero is contained in the credibility interval.
draws
: List containing the posterior draws of the effects (beta
), the prior parameters (tau2
, gamma2
),
and the penalty parameters (psi2
and lambda2
).
dim.est
: The dimension of the input estimates of beta
.
input.est
: The input vector of the unshrunken estimates of beta
.
call
: Input call.
Karimovo, van Erp, Leenders, and Mulder (2024). Honey, I Shrunk the Irrelevant Effects! Simple and Fast Approximate Bayesian Regularization. <https://doi.org/10.31234/osf.io/2g8qm>
# EXAMPLE
estimates <- -5:5
covmatrix <- diag(11)
# Bayesian horseshoe where all beta's have the same global shrinkage
# (using default 'group' argument)
shrink1 <- shrinkem(estimates, covmatrix, type="horseshoe")
# posterior modes of middle three estimates are practically zero
# plot posterior densities
old.par.mfrow <- par(mfrow = c(1,1))
old.par.mar <- par(mar = c(0, 0, 0, 0))
par(mfrow = c(11,1))
par(mar = c(1,2,1,2))
for(p in 1:ncol(shrink1$draws$beta)){plot(density(shrink1$draws$beta[,p]),
xlim=c(-10,10),main=colnames(shrink1$draws$beta)[p])}
par(mfrow = old.par.mfrow)
par(mar = old.par.mar)
# Bayesian horseshoe where first three and last three beta's have different
# global shrinkage parameter than other beta's
shrink2 <- shrinkem(estimates, covmatrix, type="horseshoe",
group=c(rep(1,3),rep(2,5),rep(1,3)))
# posterior modes of middle five estimates are virtually zero
# plot posterior densities
par(mfrow = c(11,1))
par(mar = c(1,2,1,2))
for(p in 1:ncol(shrink2$draws$beta)){plot(density(shrink2$draws$beta[,p]),xlim=c(-10,10),
main=colnames(shrink2$draws$beta)[p])}
par(mfrow = old.par.mfrow)
par(mar = old.par.mar)