View source: R/TestFunctions.R
testFunction_SDDR | R Documentation |
Takes matrices of prior and posterior samples the effect parameters.
Calculates a deviance measure, D
, for the prior and posterior effect parameters.
A deviance value of 0 happens if there is no effect. Thus, the tested hypotheses are
H_0: D = 0
and H_1: D =/= 0
.
Returns Bayes factors related to both the null and alternative hypotheses.
See the "Deviance Measure" and "Bayes Factor Estimation with Savage-Dickey"
sections of the manual for more information about this procedure.
testFunction_SDDR(priorEffects, postEffects, devianceFunction = NULL, postMaxMult = 10, min_pKept = 0.9, truncatePosterior = TRUE, warnOnLength = TRUE)
priorEffects |
Numeric matrix of effect parameters sampled from the priors. Each column is one parameter and each row is one iteration. It must have at least two columns. |
postEffects |
Numeric matrix of effect parameters sampled from the posteriors. Must have the same number of columns as |
devianceFunction |
A function used for calculating the deviation of the effect parameters, |
postMaxMult |
The prior is cut off above |
min_pKept |
The minimum proportion of the prior that will be kept. Overrides |
truncatePosterior |
If |
warnOnLength |
If |
Due to a limitation of the density estimation procedure, the matrices of samples fom the prior and posterior should have the same number of rows. You will get a warning about this if they are not the same length. Given that sampling from the prior is usually relatively easy, once you have samples from the posterior, sample the same amount from the prior.
It is assumed that the prior may be diffuse, such as a Cauchy prior.
In that case, it is possible to have prior values of D
that are very far from the
largest posterior value (like 10^9 times farther). This hurts the ability of the
density estimation to estimate the density in the same way for the prior and
posterior, which could result in a bias. This function accounts for unusually large
prior D
values by only using prior D
at most 10 times larger than the largest
posterior D
.
Note that if this function is failing with errors from the density estimation procedure,
you should consider changing the defaults for postMaxMult
and min_pKept
.
It is possible to have cases where the prior is about as diffuse as the posterior, except
for extreme values of D
. In that case, using values from the prior substantialy larger than the
median of the prior can result in the left edge of the prior being very compacted and
the density estimation can't deal well with that. You can change the default values with
a curried function that then gets passed to, e.g., testHypothesis
. See the examples.
A list with four elements:
success
: A boolean indicating whether there was an exception during density estimation. If success
is FALSE
, all other values will be NULL
or NA
.
bf01
: The Bayes factor in favor of H0.
bf10
: The Bayes factor in favor of H1.
pKept
: The proportion of the prior distribution that was used to estimate the density;
## Not run: curriedTestFunction = function(priorEffects, postEffects) { testFunction_SDDR(priorEffects, postEffects, devianceFunction = sd, postMaxMult = 1.5, min_pKept = 0.95) } testHypothesis(..., testFunction = curriedTestFunction) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.