30
votes
Accepted
Huge bug involving MultinormalDistribution?
I almost believe the precision argument. But not quite.
...
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 ...
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]
...
22
votes
More efficient method to compute moments of the Johnson $S_B$ distribution
I'll preface this answer first with a complaint:
NExpectation[] and NProbability[] are not sufficiently resilient obviously ...
17
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 \...
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:
...
15
votes
More efficient method to compute moments of the Johnson $S_B$ distribution
As a minor addition to J.M.'s excellent answer,
If something breaks while evaluating NExpectation[] or NProbability[], a ...
15
votes
Accepted
How to plot paired smooth histogram/distribution plots?
Here is something using a custom ChartElementFunction
...
14
votes
Accepted
Update: Combining DistributionChart and BoxWhiskerChart
Final Update: Adding Callouts to special points
...
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 ...
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
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" ...
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.
...
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 ...
12
votes
Is there any function that compares distributions of two populations?
SeedRandom[1];
data1 = RandomVariate[NormalDistribution[2, 3], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], 10^3];
Use ...
12
votes
Accepted
Is there any function that compares distributions of two populations?
Data
data1 = RandomVariate[NormalDistribution[2, 3], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], 10^3];
Visual comparison
...
12
votes
Accepted
Scale SmoothHistogram curve to Histogram
If you really want to, you can scale up from the "PDF". The "scaling" factor depends on how the Histogram was binned, but we can use HistogramDistribution to ...
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 ...
12
votes
Accepted
Finding the covariance of two discrete random variables
This solution uses built-in functions :
...
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 ...
11
votes
Compiling the VoigtDistribution PDF
Here is a compiled implementation of the Voigt profile function, based on an approximation derived by Chiarella and Reichel and improved by Abrarov, Quine and Jagpal:
...
11
votes
Accepted
Adding two random variables (probability distributions)
As Eric Brown suggested you should use TransformedDistribution[]. Also I'd suggest using built in distributions if possible, here I mean DiscreteUniformDistribution[].
...
11
votes
Accepted
Random Variate generating strange results when using ProbabilityDistribution
There seems to be a bug in version 10.1 that has been fixed in 10.3. You can always try writing your own random number generator. Here is a simple acceptance rejection method based on generalized ...
11
votes
Accepted
P-values differ in tests for normality between Mathematica and SAS
I should have looked at your code but I didn't, because I saw that the test-statistics for the tests in question were the same.
What I did then is to look up how p-values are computed for Anderson-...
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$, $\...
11
votes
Huge bug involving MultinormalDistribution?
dist = MultinormalDistribution[{0, 0}, ({{1, 37/40}, {37/40, 1}})];
MachinePrecision: "Machine-precision numbers (often called ...
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$
...
11
votes
The sampling without replacement
I am a bit late but another way to use MultivariateHypergeometricDistribution:
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
distributions × 821probability-or-statistics × 530
fitting × 98
random × 97
plotting × 80
histograms × 42
calculus-and-analysis × 37
numerical-integration × 27
bugs × 27
performance-tuning × 26
functions × 22
equation-solving × 14
data × 14
symbolic × 12
convolution × 12
list-manipulation × 11
graphics × 11
numerics × 11
mathematical-optimization × 11
special-functions × 8
machine-learning × 8
conditional × 8
implementation-details × 8
parameters × 8
sampling × 8