Macaulay2 » Documentation
Packages » Probability » ProbabilityDistribution » DensityFunction » density
next | previous | forward | backward | up | index | toc

# density -- probability density (or mass) function

- Usage:
    `density_X x`
- Inputs:
  - X, a probability distribution,
  - x, a real number,
- Outputs:
  - a real number,

## Description

For a discrete probability distribution, this returns values of of the probability mass function of the distribution, i.e., \(f_X(x) = P(X = x)\).

    i1 : X = binomialDistribution(5, 0.25)

    o1 = B(5,.25)

    o1 : DiscreteProbabilityDistribution

    i2 : density_X 2

    o2 = .263671875

    o2 : RR (of precision 53)

    i3 : binomial(5, 2) * 0.25^2 * 0.75^3

    o3 = .263671875

    o3 : RR (of precision 53)

For a continuous probability distribution, this returns values of the probability density function of the distribution, i.e., the integrand in \(\int_a^b f_X(x)\,dx = P(a\leq X \leq b)\).

    i4 : Z = normalDistribution()

    o4 = N(0,1)

    o4 : ContinuousProbabilityDistribution

    i5 : density_Z 0

    o5 = .3989422804014327

    o5 : RR (of precision 53)

    i6 : 1/sqrt(2 * pi)

    o6 = .3989422804014327

    o6 : RR (of precision 53)

    i7 : integrate(density_Z, -1, 1)

    o7 = .682689492137086

    o7 : RR (of precision 53)

    i8 : integrate(density_Z, -2, 2)

    o8 = .9544997361034697

    o8 : RR (of precision 53)

    i9 : integrate(density_Z, -3, 3)

    o9 = .997300204130616

    o9 : RR (of precision 53)

## Ways to use density:

- `density(DiscreteProbabilityDistribution,Number)`
- `density(ProbabilityDistribution,Number)`

## For the programmer

The object density is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Probability.m2:646:0.