lowerTail
true asks for
P(X ≤ x); false asks for P(X > x). Use the upper-tail
calculation directly for rare exceedances.
Beginner tutorial · built-in distributions
A density describes local plausibility, a CDF answers “at most?”, a quantile finds a cutoff, and a random method simulates what could happen. JDistlib uses these four operations consistently.
The mental model
In Java these are named density, cumulative,
quantile, and random. They mirror R's d/p/q/r convention.
First code
Import the distribution class, then state the value, parameters, lower-tail choice, and whether the probability is logarithmic.
import jdistlib.Normal;
double probability = Normal.cumulative(
1.96, 0.0, 1.0, true, false);
double cutoff = Normal.quantile(
0.975, 0.0, 1.0, true, false);
// probability and cutoff are both about 0.975 and 1.96.
An instance remembers its parameters and is convenient when you reuse a law:
Normal measurement = new Normal(100.0, 15.0);
double below130 = measurement.cumulative(130.0, true, false);
double[] densities = measurement.density(
new double[] {85.0, 100.0, 115.0});
Two switches
lowerTailtrue asks for
P(X ≤ x); false asks for P(X > x). Use the upper-tail
calculation directly for rare exceedances.
logPtrue returns the logarithm of
a probability. This avoids underflow and is useful when likelihoods multiply
many small probabilities.
double failureRisk = Normal.cumulative(
180.0, 100.0, 15.0, false, false);
double logFailureRisk = Normal.cumulative(
180.0, 100.0, 15.0, false, true);
Reproducible simulation
Give each independent task its own RandomEngine. A fixed seed makes
a tutorial, test, or analysis repeatable.
import jdistlib.Normal;
import jdistlib.rng.MersenneTwister;
import jdistlib.rng.RandomEngine;
RandomEngine random = new MersenneTwister(20260826L);
double[] simulated = Normal.random(
1_000, 100.0, 15.0, random);
Do not share one mutable random engine between threads. Give each worker a separate, explicitly seeded stream.
Avoid surprises
For a continuous law,
use cumulative(b)-cumulative(a) for P(a < X ≤ b). A density
value can exceed one.
Scale, rate, shape, and degrees of freedom are not interchangeable. Confirm them in the catalog.
For a binomial or Poisson law,
density(k,...) is the exact probability of k.
A goodness-of-fit reference distribution should normally be fully specified. If parameters came from the same data, account for that estimation in the resampling procedure.
Next
Continue with the response-time vignette, browse the full catalog, build a custom distribution, or learn how to adjust a collection of p-values in 0.7.0+.