Generic function that computes posterior model probabilities from marginal likelihoods.
Usage
post_prob(x, ..., prior_prob = NULL, model_names = NULL)
# S3 method for class 'bridge'
post_prob(x, ..., prior_prob = NULL, model_names = NULL)
# S3 method for class 'bridge_list'
post_prob(x, ..., prior_prob = NULL, model_names = NULL)
# Default S3 method
post_prob(x, ..., prior_prob = NULL, model_names = NULL)Arguments
- x
Object of class
"bridge"or"bridge_list"as returned frombridge_sampler. Additionally, the default method assumes that all passed objects are numeric log marginal likelihoods (e.g., fromlogml) and will throw an error otherwise.- ...
further objects of class
"bridge"or"bridge_list"as returned frombridge_sampler. Or numeric values for the default method.- prior_prob
numeric vector with prior model probabilities. If omitted, a uniform prior is used (i.e., all models are equally likely a priori). The default
NULLcorresponds to equal prior model weights.- model_names
If
NULL(the default) will use model names derived from deparsing the call. Otherwise will use the passed values as model names.
Value
For the default method and the method for "bridge" objects, a
named numeric vector with posterior model probabilities (i.e., which sum to
one).
For the method for "bridge_list" objects, a matrix consisting of
posterior model probabilities where each row sums to one and gives the
model probabilities for one set of logmls. The (named) columns correspond
to the models and the number of rows is given by the "bridge_list"
element with the most repetitions. Elements with fewer repetitions
will be recycled (with warning).
Note
For realistic examples, see bridge_sampler and the
accompanying vignettes: vignette("bridgesampling_example_jags")
vignette("bridgesampling_example_stan")
Examples
H0 <- structure(list(logml = -20.8084543022433, niter = 4, method = "normal"),
.Names = c("logml", "niter", "method"), class = "bridge")
H1 <- structure(list(logml = -17.9623077558729, niter = 4, method = "normal"),
.Names = c("logml", "niter", "method"), class = "bridge")
H2 <- structure(list(logml = -19, niter = 4, method = "normal"),
.Names = c("logml", "niter", "method"), class = "bridge")
post_prob(H0, H1, H2)
#> H0 H1 H2
#> 0.04111453 0.70804533 0.25084015
post_prob(H1, H0)
#> H1 H0
#> 0.94511915 0.05488085
## all produce the same (only names differ):
post_prob(H0, H1, H2)
#> H0 H1 H2
#> 0.04111453 0.70804533 0.25084015
post_prob(H0$logml, H1$logml, H2$logml)
#> H0$logml H1$logml H2$logml
#> 0.04111453 0.70804533 0.25084015
post_prob(c(H0$logml, H1$logml, H2$logml))
#> c(H0$logml, H1$logml, H2$logml) c(H0$logml, H1$logml, H2$logml).1
#> 0.04111453 0.70804533
#> c(H0$logml, H1$logml, H2$logml).2
#> 0.25084015
post_prob(H0$logml, c(H1$logml, H2$logml))
#> H0$logml c(H1$logml, H2$logml) c(H1$logml, H2$logml).1
#> 0.04111453 0.70804533 0.25084015
post_prob(H0$logml, c(H1$logml, H2$logml), model_names = c("H0", "H1", "H2"))
#> H0 H1 H2
#> 0.04111453 0.70804533 0.25084015
### with bridge list elements:
H0L <- structure(list(logml = c(-20.8088381186739, -20.8072772698116,
-20.808454454621, -20.8083419072281, -20.8087870541247, -20.8084887398113,
-20.8086023582344, -20.8079083169745, -20.8083048489095, -20.8090050811436
), niter = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4), method = "normal",
repetitions = 10), .Names = c("logml", "niter", "method",
"repetitions"), class = "bridge_list")
H1L <- structure(list(logml = c(-17.961665507006, -17.9611290723151,
-17.9607509604499, -17.9608629535992, -17.9602093576442, -17.9600223300432,
-17.9610157118017, -17.9615557696561, -17.9608437034849, -17.9606743200309
), niter = c(4, 4, 4, 4, 4, 4, 4, 4, 3, 4), method = "normal",
repetitions = 10), .Names = c("logml", "niter", "method",
"repetitions"), class = "bridge_list")
post_prob(H1L, H0L)
#> H1L H0L
#> [1,] 0.9451723 0.05482765
#> [2,] 0.9451192 0.05488076
#> [3,] 0.9451999 0.05480015
#> [4,] 0.9451882 0.05481178
#> [5,] 0.9452451 0.05475488
#> [6,] 0.9452394 0.05476064
#> [7,] 0.9451938 0.05480620
#> [8,] 0.9451298 0.05487017
#> [9,] 0.9451873 0.05481270
#> [10,] 0.9452323 0.05476767
post_prob(H1L, H0L, H0) # last element recycled with warning.
#> Warning: Not all objects provide 10 logmls. Some values are recycled.
#> H1L H0L H0
#> [1,] 0.8960265 0.05197679 0.05199675
#> [2,] 0.8960037 0.05202875 0.05196754
#> [3,] 0.8960938 0.05195311 0.05195312
#> [4,] 0.8960781 0.05196387 0.05195803
#> [5,] 0.8961597 0.05191153 0.05192881
#> [6,] 0.8961632 0.05191751 0.05191930
#> [7,] 0.8960760 0.05195815 0.05196584
#> [8,] 0.8959934 0.05201751 0.05198912
#> [9,] 0.8960782 0.05196480 0.05195703
#> [10,] 0.8961265 0.05192243 0.05195104