Description Usage Arguments Value Intercept (after predictors centered) Adjusted scales Coefficients in Q-space See Also Examples

View source: R/prior_summary.R

The `prior_summary`

method provides a summary of the prior distributions
used for the parameters in a given model. In some cases the user-specified
prior does not correspond exactly to the prior used internally by
rstanarm (see the sections below). Especially in these cases, but also
in general, it can be much more useful to visualize the priors. Visualizing
the priors can be done using the `posterior_vs_prior`

function,
or alternatively by fitting the model with the `prior_PD`

argument set
to `TRUE`

(to draw from the prior predictive distribution instead of
conditioning on the outcome) and then plotting the parameters.

1 2 | ```
## S3 method for class 'stanreg'
prior_summary(object, digits = 2, ...)
``` |

`object` |
A fitted model object returned by one of the
rstanarm modeling functions. See |

`digits` |
Number of digits to use for rounding. |

`...` |
Currently ignored by the method for stanreg objects. |

A list of class "prior_summary.stanreg", which has its own print method.

For rstanarm modeling functions that accept a `prior_intercept`

argument, the specified prior for the intercept term applies to the
intercept after rstanarm internally centers the predictors so they
each have mean zero. The estimate of the intercept returned to the user
correspond to the intercept with the predictors as specified by the user
(unmodified by rstanarm), but when *specifying* the prior the
intercept can be thought of as the expected outcome when the predictors are
set to their means. The only exception to this is for models fit with the
`sparse`

argument set to `TRUE`

(which is only possible with a
subset of the modeling functions and never the default).

For some models you may see "`adjusted scale`

"
in the printed output and adjusted scales included in the object returned
by `prior_summary`

. These adjusted scale values are the prior scales
actually used by rstanarm and are computed by adjusting the prior
scales specified by the user to account for the scales of the predictors
(as described in the documentation for the `autoscale`

argument). To disable internal prior scale adjustments set the
`autoscale`

argument to `FALSE`

when setting a prior using one of
the distributions that accepts an `autoscale`

argument. For example,
`normal(0, 5, autoscale=FALSE)`

instead of just `normal(0, 5)`

.

For the models fit with an rstanarm modeling function that supports
the `QR`

argument (see e.g, `stan_glm`

), if `QR`

is
set to `TRUE`

then the prior distributions for the regression
coefficients specified using the `prior`

argument are not relative to
the original predictor variables *X* but rather to the variables in the
matrix *Q* obtained from the *QR* decomposition of *X*.

In particular, if `prior = normal(location,scale)`

, then this prior on
the coefficients in *Q*-space can be easily translated into a joint
multivariate normal (MVN) prior on the coefficients on the original
predictors in *X*. Letting *θ* denote the coefficients on
*Q* and *β* the coefficients on *X* then if *θ ~ N(μ, σ)* the corresponding prior on
*β* is *β ~ MVN(Rμ,
R'Rσ)*, where *μ* and *σ* are vectors of the
appropriate length. Technically, rstanarm uses a scaled *QR*
decomposition to ensure that the columns of the predictor matrix used to
fit the model all have unit scale, when the `autoscale`

argument
to the function passed to the `prior`

argument is `TRUE`

(the
default), in which case the matrices actually used are
*Q* = Q (n-1)^0.5* and *R* = (n-1)^(-0.5) R*. If `autoscale = FALSE`

we instead scale such that the lower-right element of *R** is
*1*, which is useful if you want to specify a prior on the coefficient
of the last predictor in its original units (see the documentation for the
`QR`

argument).

If you are interested in the prior on *β* implied by the prior on
*θ*, we strongly recommend visualizing it as described above in
the **Description** section, which is simpler than working it out
analytically.

The priors help page and the *Prior
Distributions* vignette.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
if (!exists("example_model")) example(example_model)
prior_summary(example_model)
priors <- prior_summary(example_model)
names(priors)
priors$prior$scale
priors$prior$adjusted_scale
# for a glm with adjusted scales (see Details, above), compare
# the default (rstanarm adjusting the scales) to setting
# autoscale=FALSE for prior on coefficients
fit <- stan_glm(mpg ~ wt + am, data = mtcars,
prior = normal(0, c(2.5, 4)),
prior_intercept = normal(0, 5),
iter = 10, chains = 1) # only for demonstration
prior_summary(fit)
fit2 <- update(fit, prior = normal(0, c(2.5, 4), autoscale=FALSE),
prior_intercept = normal(0, 5, autoscale=FALSE))
prior_summary(fit2)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.