The distribution can be extracted as:
a probability density function (type = "continuous"
), cf. extract_pdf()
.
a probability mass function (type = "discrete"
), cf. extract_pmf()
.
a series of equal-tailed confidence/credible intervals (type = "eti"
), cf. extract_ci()
.
a series of highest density confidence/credible intervals (type = "hdi"
), cf. extract_ci()
.
extract_distribution(
object,
parName = "",
type = c("continuous", "discrete", "eti", "hdi"),
transform = identity,
...
)
Object specifying the distribution as samples: can be a Stanfit object, a matrix (columns represents parameters, rows samples) or a vector.
Name of the parameter to extract.
Indicates how the distribution is summarised.
Function to apply to the samples.
Arguments to pass to extract_pmf()
, extract_pdf()
or extract_ci()
depending on type
.
Dataframe. The columns depends on the method that is used (see specific function for details).
This function can notably be used to prepare the data for plotting fan charts when type = "eti"
or "hdi"
.
In that case, the ggdist
package offers an alternative with ggdist::stat_lineribbon()
.
extract_draws()
for extracting draws of an object.
extract_distribution(runif(1e2), type = "continuous", support = c(0, 1))
#> Value Density Index Variable
#> 1 0.000000000 0.4098072 NA
#> 2 0.007874016 0.4393620 NA
#> 3 0.015748031 0.4694345 NA
#> 4 0.023622047 0.4998564 NA
#> 5 0.031496063 0.5304585 NA
#> 6 0.039370079 0.5610700 NA
#> 7 0.047244094 0.5915125 NA
#> 8 0.055118110 0.6215823 NA
#> 9 0.062992126 0.6511022 NA
#> 10 0.070866142 0.6798872 NA
#> 11 0.078740157 0.7077545 NA
#> 12 0.086614173 0.7344999 NA
#> 13 0.094488189 0.7599402 NA
#> 14 0.102362205 0.7839431 NA
#> 15 0.110236220 0.8063636 NA
#> 16 0.118110236 0.8270728 NA
#> 17 0.125984252 0.8458867 NA
#> 18 0.133858268 0.8627736 NA
#> 19 0.141732283 0.8776814 NA
#> 20 0.149606299 0.8905729 NA
#> 21 0.157480315 0.9014145 NA
#> 22 0.165354331 0.9101827 NA
#> 23 0.173228346 0.9169938 NA
#> 24 0.181102362 0.9219256 NA
#> 25 0.188976378 0.9250835 NA
#> 26 0.196850394 0.9265560 NA
#> 27 0.204724409 0.9265321 NA
#> 28 0.212598425 0.9252184 NA
#> 29 0.220472441 0.9228148 NA
#> 30 0.228346457 0.9195355 NA
#> 31 0.236220472 0.9155917 NA
#> 32 0.244094488 0.9112544 NA
#> 33 0.251968504 0.9067607 NA
#> 34 0.259842520 0.9023459 NA
#> 35 0.267716535 0.8982488 NA
#> 36 0.275590551 0.8947017 NA
#> 37 0.283464567 0.8918971 NA
#> 38 0.291338583 0.8900164 NA
#> 39 0.299212598 0.8892183 NA
#> 40 0.307086614 0.8896855 NA
#> 41 0.314960630 0.8914908 NA
#> 42 0.322834646 0.8946988 NA
#> 43 0.330708661 0.8993532 NA
#> 44 0.338582677 0.9054822 NA
#> 45 0.346456693 0.9131023 NA
#> 46 0.354330709 0.9221147 NA
#> 47 0.362204724 0.9324441 NA
#> 48 0.370078740 0.9439902 NA
#> 49 0.377952756 0.9566567 NA
#> 50 0.385826772 0.9702808 NA
#> 51 0.393700787 0.9846842 NA
#> 52 0.401574803 0.9996946 NA
#> 53 0.409448819 1.0151312 NA
#> 54 0.417322835 1.0308101 NA
#> 55 0.425196850 1.0465260 NA
#> 56 0.433070866 1.0620938 NA
#> 57 0.440944882 1.0773343 NA
#> 58 0.448818898 1.0920650 NA
#> 59 0.456692913 1.1061137 NA
#> 60 0.464566929 1.1193513 NA
#> 61 0.472440945 1.1316518 NA
#> 62 0.480314961 1.1429072 NA
#> 63 0.488188976 1.1529861 NA
#> 64 0.496062992 1.1618485 NA
#> 65 0.503937008 1.1694584 NA
#> 66 0.511811024 1.1757893 NA
#> 67 0.519685039 1.1808224 NA
#> 68 0.527559055 1.1845347 NA
#> 69 0.535433071 1.1869998 NA
#> 70 0.543307087 1.1882592 NA
#> 71 0.551181102 1.1883656 NA
#> 72 0.559055118 1.1873533 NA
#> 73 0.566929134 1.1853030 NA
#> 74 0.574803150 1.1823057 NA
#> 75 0.582677165 1.1784334 NA
#> 76 0.590551181 1.1737561 NA
#> 77 0.598425197 1.1683102 NA
#> 78 0.606299213 1.1621899 NA
#> 79 0.614173228 1.1554481 NA
#> 80 0.622047244 1.1481293 NA
#> 81 0.629921260 1.1402608 NA
#> 82 0.637795276 1.1318659 NA
#> 83 0.645669291 1.1229789 NA
#> 84 0.653543307 1.1136131 NA
#> 85 0.661417323 1.1037769 NA
#> 86 0.669291339 1.0934607 NA
#> 87 0.677165354 1.0826816 NA
#> 88 0.685039370 1.0714523 NA
#> 89 0.692913386 1.0597851 NA
#> 90 0.700787402 1.0476963 NA
#> 91 0.708661417 1.0352039 NA
#> 92 0.716535433 1.0223622 NA
#> 93 0.724409449 1.0092215 NA
#> 94 0.732283465 0.9958433 NA
#> 95 0.740157480 0.9822980 NA
#> 96 0.748031496 0.9686743 NA
#> 97 0.755905512 0.9550668 NA
#> 98 0.763779528 0.9415722 NA
#> 99 0.771653543 0.9282892 NA
#> 100 0.779527559 0.9153326 NA
#> 101 0.787401575 0.9027851 NA
#> 102 0.795275591 0.8907278 NA
#> 103 0.803149606 0.8792284 NA
#> 104 0.811023622 0.8683470 NA
#> 105 0.818897638 0.8581215 NA
#> 106 0.826771654 0.8485365 NA
#> 107 0.834645669 0.8395680 NA
#> 108 0.842519685 0.8311650 NA
#> 109 0.850393701 0.8232618 NA
#> 110 0.858267717 0.8157359 NA
#> 111 0.866141732 0.8084496 NA
#> 112 0.874015748 0.8012497 NA
#> 113 0.881889764 0.7939639 NA
#> 114 0.889763780 0.7863910 NA
#> 115 0.897637795 0.7783441 NA
#> 116 0.905511811 0.7696310 NA
#> 117 0.913385827 0.7600648 NA
#> 118 0.921259843 0.7494412 NA
#> 119 0.929133858 0.7375949 NA
#> 120 0.937007874 0.7244129 NA
#> 121 0.944881890 0.7097866 NA
#> 122 0.952755906 0.6936384 NA
#> 123 0.960629921 0.6758586 NA
#> 124 0.968503937 0.6564986 NA
#> 125 0.976377953 0.6355934 NA
#> 126 0.984251969 0.6132073 NA
#> 127 0.992125984 0.5894204 NA
#> 128 1.000000000 0.5643486 NA