Last updated: 2019-03-31

Checks: 2 0

Knit directory: fiveMinuteStats/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.Rhistory
    Ignored:    analysis/bernoulli_poisson_process_cache/

Untracked files:
    Untracked:  _workflowr.yml
    Untracked:  analysis/CI.Rmd
    Untracked:  analysis/gibbs_structure.Rmd
    Untracked:  analysis/libs/
    Untracked:  analysis/results.Rmd
    Untracked:  analysis/shiny/tester/
    Untracked:  docs/MH_intro_files/
    Untracked:  docs/citations.bib
    Untracked:  docs/figure/MH_intro.Rmd/
    Untracked:  docs/hmm_files/
    Untracked:  docs/libs/
    Untracked:  docs/shiny/tester/

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
html 34bcc51 John Blischak 2017-03-06 Build site.
Rmd 5fbc8b5 John Blischak 2017-03-06 Update workflowr project with wflow_update (version 0.4.0).
html fb0f6e3 stephens999 2017-03-03 Merge pull request #33 from mdavy86/f/review
Rmd 02d2d36 stephens999 2017-02-20 add shiny binomial example
html 02d2d36 stephens999 2017-02-20 add shiny binomial example

Overview

The purpose of this vignette is to introduce the Dirichlet distribution. You should be familiar with the Beta distribution since the Dirichlet can be thought of as a generalization of the Beta distribution.

If you want more details you could look at Wikipedia.

The Dirichlet Distribution

You can think of the \(J\)-dimensional Dirichlet distribution as a distribution on probability vectors, \(q=(q_1,\dots,q_J)\), whose elements are non-negative and sum to 1. It is perhaps the most commonly-used distribution for probability vectors, and plays a central role in Bayesian inference from multinomial data.

The Dirichlet distribution has \(J\) parameters, \(\alpha_1,\dots,\alpha_J\) that control the mean and variance of the distribution. If \(q \sim \text{Dirichlet}(\alpha_1,\dots,\alpha_J)\) then:

  • The expectation of \(q_j\) is \(\alpha_j/(\alpha_1 + \dots + \alpha_J)\).

  • The variance of \(q_j\) becomes smaller as the sum \(\sum_j \alpha_j\) increases.

As a generalization of the Beta distribution

The 2-dimensional Dirichlet distribution is essentially the Beta distribution. Specifically, let \(q=(q_1,q_2)\). Then \(q \sim Dirichlet(\alpha_1,\alpha_2)\) implies that \[q_1 \sim \text{Beta}(\alpha_1,\alpha_2)\] and \(q_2 = 1-q_1\).

Other connections to the Beta distribution

More generally, the marginals of the Dirichlet distribution are also beta distributions.

That is, if \(q \sim \text{Dirichlet}(\alpha_1, \dots,\alpha_J)\) then \(q_j \sim \text{Beta}(\alpha_j,\sum_{j' \neq j} \alpha_{j'})\).

Density

The density of the Dirichlet distribution is most conveniently written as \[p(q | \alpha) = \frac{\Gamma(\alpha_1+\dots+\alpha_J)}{\Gamma(\alpha_1)\dots \Gamma(\alpha_J)}\prod_{j=1}^J q_j^{\alpha_j-1} \qquad (q_j \geq 0; \quad \sum_j q_j =1).\] where \(Gamma\) here denotes the gamma function.

Actually when writing the density this way, a little care needs to be taken to make things formally correct. Specifically, if you perform standard (Lebesgue) integration of this “density” over the \(J\) dimensional space \(q_1,\dots, q_J\) it integrates to 0, and not 1 as a density should. This problem is caused by the constraint that the \(q\)s must sum to 1, which means that the Dirichlet distribution is effectively a \(J-1\)-dimensional distribution and not a \(J\) dimensional distribution.

The simplest resolution to this is to think of the \(J\) dimensional Dirichlet distribution as a distribution on the \(J-1\) numbers \((q_1, \dots, q_{J-1})\), satisfying \(\sum_{j=1}^{J-1} q_j \leq 1\), and then define \(q_J := (1-q_1-q_2-\dots - q_{J-1})\). Then, if we integrate the density \[p(q_1,\dots,q_{J-1} | \alpha) = \frac{\Gamma(\alpha_1+\dots+\alpha_J)}{\Gamma(\alpha_1)\dots \Gamma(\alpha_J)} \prod_{j=1}^{J-1} q_j^{\alpha_j-1} (1-q_1-\dots - q_{J-1})^{\alpha_J} \qquad (q_j \geq 0; \quad \sum_{j=1}^{J-1} q_j \leq 1). \] over \((q_1,\dots,q_{J-1})\), it integrates to 1 as a density should.

Examples


This site was created with R Markdown