Skip to main content
29 votes
Accepted

Huge bug involving MultinormalDistribution?

I almost believe the precision argument. But not quite. ...
Eric Towers's user avatar
  • 3,050
28 votes
Accepted

Backtesting a Probability of Default (PD) model

This kind of backtest is often performed using approximations, for instance with normal distributions, which may not be always valid. An exact test would be very nice to have. The probability ...
Sjoerd C. de Vries's user avatar
26 votes
Accepted

Sisyphus Random Walk

We can iterate with FoldList: data = {0, 1, 1, 0, 1, 0, 1, 1, 1, 1}; FoldList[#2 * (#1 + #2)&, data] ...
Greg Hurst's user avatar
  • 36.2k
18 votes
Accepted

How to implement Kullback-Leibler divergence using Mathematica's probability and distribution functions?

In the continuous case the Kullback-Leibler-Divergence from distribution $Q$ to distribution $P$ is defined as \begin{equation} D_{KL}( P ||Q) = \int \limits_{-\infty}^{+\infty} p(x)\cdot \log \...
gwr's user avatar
  • 13.5k
16 votes
Accepted

Does Mathematica have an implementation of the Poisson binomial distribution?

Mathematica does not know about the PoissonBinomialDistribution, but you can use the formula given for the PDF on Wikipedia: ...
gwr's user avatar
  • 13.5k
15 votes
Accepted

How to plot paired smooth histogram/distribution plots?

Here is something using a custom ChartElementFunction ...
chuy's user avatar
  • 11.2k
14 votes
Accepted

Update: Combining DistributionChart and BoxWhiskerChart

Final Update: Adding Callouts to special points ...
kglr's user avatar
  • 396k
14 votes
Accepted

Define a simple discrete probability distribution

You can first define a piecewise function piece[x_] := Piecewise[{{0.3, x == 0}, {0.4, x == 1}, {0.3, x == 2}}] and feed it to ...
corey979's user avatar
  • 24k
14 votes
Accepted

How to replace $x$ and $x^2$ with different value?

Give the replacement rules in a list: expr /. {x^2 -> k p + k (k - 1) p^2, x -> k p} 2 k p + (-1 + k) k p^2
kglr's user avatar
  • 396k
13 votes
Accepted

Histogram "PDF" vs "Probability"

I believe that when you specify "PDF", the value on the ordinate is the average probability density within a given bin. And to get the "within-this-bin" ...
user15994's user avatar
  • 509
13 votes

Uniform distribution on z = 1 − √( x ^2 + y ^2) , z ≥ 0

If you set up your region S as a region in Mathematica you can use RandomPoint to generate uniformly distributed points over it. ...
aardvark2012's user avatar
  • 5,424
13 votes
Accepted

Why does FindDistribution give nonrepeatable results for fit parameters?

I don't know what FindDistribution is doing because it doesn't produce estimates that match any of those produced by ...
JimB's user avatar
  • 41.8k
12 votes
Accepted

How to measure accuracy of prediction distribution?

One possibility is to use a generalized linear model for which Mathematica has the function GeneralizedLinearModelFit. For your potentially Poisson data the ...
JimB's user avatar
  • 41.8k
12 votes
Accepted

Finding the covariance of two discrete random variables

This solution uses built-in functions : ...
A.G.'s user avatar
  • 4,362
12 votes

Selecting a random subset to match PDF of another or a given distribution

This problem is known and can even be more generalized than you have described it. Especially, when researching fields like cardiovascular diseases or aortic valve problems, it is often the case that ...
halirutan's user avatar
  • 113k
11 votes
Accepted

Speed up RandomVariate on a custom probability distribution

A few thoughts: Notation Defining: {α, β, s, cMakeham} = Table[ blah matrix] ... looks like an invitation for trouble, since you are setting up $\alpha$, $\...
wolfies's user avatar
  • 8,722
11 votes

Huge bug involving MultinormalDistribution?

dist = MultinormalDistribution[{0, 0}, ({{1, 37/40}, {37/40, 1}})]; MachinePrecision: "Machine-precision numbers (often called ...
Bob Hanlon's user avatar
  • 159k
11 votes
Accepted

The sampling without replacement

You can do it this way but it is a bit clumsy: For $ \left | x2-x1 \right |=0$ ...
bobbym's user avatar
  • 2,638
11 votes

The sampling without replacement

I am a bit late but another way to use MultivariateHypergeometricDistribution: ...
ubpdqn's user avatar
  • 61.5k
11 votes
Accepted

Can this code be changed to run faster?

I'm concentrating on the calculation of samplemanycyclesper5years and samplecycledistributions. For the first one, you select ...
halirutan's user avatar
  • 113k
11 votes

Can I use Compile to speed up InverseCDF?

This is a little long for a comment, beside which it points out an unexpected difference probably resulting from subsystems evolving independently at different times. In addition to Henrik's comment ...
Michael E2's user avatar
  • 236k
11 votes
Accepted

Overloading functions like Mean for distributions

Symbolic(!) distributions are recognized by their head, not by their PDF: Mean[PDF[NormalDistribution[0, 1], x]] Mean[E^(-(...
Henrik Schumacher's user avatar
11 votes
Accepted

How do you generate a random number with a pre-specified probability distribution?

...
kglr's user avatar
  • 396k
10 votes

RandomVariate from 2-dimensional probability distribution

There is some hidden MCMC (Markov Chain Monte Carlo) functionality in Mathematica that can come in handy, though there are obviously no guarantees about how well it works since it's unexposed. Here's ...
Sjoerd Smit's user avatar
  • 23.6k
10 votes
Accepted

Deriving a PDF for an annulus distribution

An alternative, and faster, way to generate samples with the desired distribution using TransformedDistribution: ...
kglr's user avatar
  • 396k
10 votes
Accepted

Sampling a Dirichlet Distribution efficiently

Dirichelet random variates are constructed from gamma random variates. Let $$ v_j \stackrel{\text{iid}}{\sim} \textsf{Gamma}(\alpha_j,1) $$ for $j = 1, \ldots, n$ and set $$ x_j = \frac{v_j}{\sum_{j=...
mef's user avatar
  • 1,629
10 votes
Accepted

package for calculating exponent of power law distribution

Start here to see what statistics functionality is available: http://reference.wolfram.com/language/guide/Statistics.html http://reference.wolfram.com/language/guide/ProbabilityAndStatistics.html ...
Szabolcs's user avatar
  • 235k
10 votes
Accepted

Expanded Distribution Coverage: Mathematica 11

I have asked this question and @Searke provided the following image (quite large when you click on it to follow its link) in the Mma.SE chat room. Hope this helps.
Edmund's user avatar
  • 42.3k
10 votes
Accepted

Mosteller's First Ace Problem

I would like to choose a slightly different approach here and point out, that this is an example for the Negative Hypergeometric Distribution. Wikipedia does give a nice table for this: While for ...
gwr's user avatar
  • 13.5k
10 votes
Accepted

Inverse CDF of non-builtin probability distribution

Clear[RaisedCosineDistribution] As with built-in distributions, you need to include the parameters in the distribution definition, and the constraints on the ...
Bob Hanlon's user avatar
  • 159k

Only top scored, non community-wiki answers of a minimum length are eligible