NProbability

NProbability[pred,xdist]

gives the numerical probability for an event that satisfies the predicate pred under the assumption that x follows the probability distribution dist.

NProbability[pred,{x1,x2,}dist]

gives the numerical probability that an event satisfies pred under the assumption that {x1,x2,} follows the multivariate distribution dist.

NProbability[pred,{x1dist1,x2dist2,}]

gives the numerical probability that an event satisfies pred under the assumption that x1, x2, are independent and follow the distributions dist1, dist2, .

NProbability[pred1pred2,]

gives the numerical conditional probability of pred1 given pred2.

Details and Options

  • xdist can be entered as x dist dist or x \[Distributed]dist.
  • pred1pred2 can be entered as pred1 cond pred2 or pred1 \[Conditioned]pred2.
  • NProbability works like Probability except numerical summation and integration methods are used.
  • For a continuous distribution dist, the probability of pred is given by Boole[pred]f[x]x where f[x] is the probability density function of dist and the integral is taken over the domain of dist.
  • For a discrete distribution dist, the probability of pred is given by Boole[pred]f[x] where f[x] is the probability density function of dist and the summation is taken over the domain of dist.
  • NProbability[pred,{x1dist1,x2dist2}] corresponds to NExpectation[NProbability[pred,x2dist2],x1dist1] so that the last variable is summed or integrated first.
  • N[Probability[]] calls NProbability for probabilities that cannot be done symbolically.
  • The following options can be given:
  • AccuracyGoal digits of absolute accuracy sought
    PrecisionGoal Automaticdigits of precision sought
    WorkingPrecision MachinePrecisionthe precision used in internal computations
    Method Automaticwhat method to use

Examples

open allclose all

Basic Examples  (3)

Compute the probability of a simple event:

Compute the probability of a nonlinear and logical combination of inequalities:

Compute a conditional probability:

Scope  (27)

Basic Uses  (9)

Compute the probability of an event in a continuous univariate distribution:

Discrete univariate distribution:

Continuous multivariate distribution:

Discrete multivariate distribution:

Compute the probability using independently distributed random variables:

Find the conditional probability with general nonzero probability conditioning:

Discrete univariate distribution:

Multivariate continuous distribution:

Multivariate discrete distribution:

Compute the conditional probability with a zero-probability conditioning event:

Apply N[Probability[]] to invoke NProbability if symbolic evaluation fails:

Use nonlinear predicates and arbitrary logical combinations:

Multivariate nonlinear predicates:

Visualize the region of the event:

Obtain results with different precisions:

Probability of an event for a time slice of a Poisson process:

Find the probability of an event when a distribution is specified by a list:

Quantity Uses  (3)

Probability of events specified using Quantity:

Probability involving QuantityDistribution:

Conditional probability specified using Quantity:

Parametric Distributions  (4)

Compute probabilities for univariate continuous distributions:

Compute probabilities for univariate discrete distributions:

Probabilities for multivariate continuous distributions:

Probabilities for multivariate discrete distributions:

Nonparametric Distributions  (2)

Using a univariate HistogramDistribution:

A multivariate histogram distribution:

Using a univariate KernelMixtureDistribution:

Derived Distributions  (9)

Compute the probability using a TransformedDistribution:

An equivalent way of formulating the same probability:

Find the probability using a ProductDistribution:

An equivalent formulation for the same probability:

Using a component mixture of normal distributions:

Parameter mixture of exponential distributions:

Truncated Dirichlet distribution:

Censored triangular distribution:

Marginal distribution:

An equivalent way of formulating the same probability:

Copula distribution:

Formula distribution:

Generalizations & Extensions  (2)

Compute a numerical probability for a mixture of discrete and continuous distributions:

Specify independent distributions using && rather than a list notation:

Options  (6)

AccuracyGoal  (1)

Obtain a result with the default setting for accuracy:

Use AccuracyGoal to obtain the result with a different accuracy:

Method  (3)

Use the Method option to increase the number of recursive bisections for numerical integration:

Compare with the exact result from Probability:

Calculate the probability of an event:

Obtain an estimate based on simulation:

Specify sample size:

Compute the probability of an event for a continuous distribution:

This example uses NIntegrate:

Use Activate to evaluate the result:

PrecisionGoal  (1)

Obtain a result with the default setting for precision:

Use PrecisionGoal to obtain the result with a different precision:

WorkingPrecision  (1)

By default, NProbability uses machine precision:

Use WorkingPrecision to obtain results with higher precision:

Applications  (26)

Random Experiments  (5)

A coin-tossing experiment consists of tossing a fair coin repeatedly until a head results. Simulate the process:

Compute the probability that at least 5 coin tosses will be necessary:

Compute the expected number of coin tosses:

The number of heads in flips with a fair coin can be modeled with BinomialDistribution:

Show the distribution of heads for 100 coin flips:

Compute the probability that there are between 60 and 80 heads in 100 coin flips:

Now, suppose that for an unfair coin the probability of heads is 0.6:

The distribution and the corresponding probabilities have changed:

A fair six-sided die can be modeled using a DiscreteUniformDistribution:

Generate 10 throws of a die:

Compute the probability that the sum of three dice values is less than 6:

Verify by generating random dice throws, in this case dice throws:

Verify by explicitly enumerating all possible dice outcomes:

The number of tails before getting 4 heads with a fair coin:

Plot the distribution of tail counts:

Compute the probability of getting at least 6 tails before getting 4 heads:

Compute the expected number of tails before getting 4 heads:

Suppose an urn has 100 elements, of which 40 are special:

The probability distribution that there are 20 special elements in a draw of 50 elements:

Compute the probability that there are more than 25 special elements in a draw of 50 elements:

Compute the expected number of special elements in a draw of 50 elements:

Sports and Games  (3)

Gary Kasparov, chess champion, plays in a tournament simultaneously against 100 amateurs. It has been estimated that he loses about 1% of such games. Find the probability of his losing 0, 2, 5, and 10 games:

Use a Poisson approximation to compute the same probabilities:

Perform the same computation when he is playing 5 games, but with stronger opposition so that his loss probability is 10% instead:

In this case the Poisson approximation is less accurate:

A basketball player has a free-throw percentage of 0.75. Simulate 10 free throws:

Find the probability that the player hits 2 out of 3 free throws in a game:

Find the distribution of the number of spades in a five-card poker hand:

Find the probability that there are at least 2 spades in the poker hand:

Weather  (3)

Logistic distribution can be used to approximate wind speeds:

Find the estimated distribution:

Compare the PDF to the histogram of the wind data:

Find the probability of a day with wind speed greater than 30 km/h:

Find the mean wind speed:

Simulate wind speeds for a month:

Cloud duration approximately follows a beta distribution with parameters 0.3 and 0.4 for a particular location. Find the probability that cloud duration will be longer than half a day:

Simulate the fraction of the day that is cloudy over a period of one month:

Find the average cloudiness duration for a day:

Find the probability of having exactly 20 days in a month with cloud duration less than 10%:

Find the probability of at least 20 days in a month with cloud duration less than 10%:

The expected number of raindrops falling into a bucket in a 5-second interval is 20. Simulate the raindrop count for each 5-second interval:

Find the probability that more than 20 raindrops fall into the bucket in 5 seconds:

Traffic  (2)

Two trains arrive at a station independently and stay for 10 minutes. If the arrival times are uniformly distributed, find the probability the two trains will meet at the station within one hour:

The region where the two trains meet:

A person is standing by a road counting cars until he sees a black one, at which point he restarts the count. Simulate the counting process, assuming that 10% of the cars are black:

Find the expected number of cars to come by before the count starts over:

Find the probability of counting 10 or more cars before a black one:

Actuarial Science  (4)

A group insurance policy covers the medical claims of the employees of a small company. The value of the claims made in one year is described by , where is a random variable with density function proportional to for . Find the conditional probability that exceeds 40000, given that exceeds 10000:

The waiting time for the first claim from a good driver and the waiting time for the first claim from a bad driver are independent and follow exponential distributions with means 6 years and 3 years, respectively. Compute the probability that the first claim from a good driver will be filed within 3 years and the first claim from a bad driver will be filed within 2 years:

Two insurers provide bids on an insurance policy to a large company. The bids must be between 2000 and 2200. The company decides to accept the lower bid if the two bids differ by 20 or more. Otherwise, the company will consider the two bids further. Assume that the two bids are independent and are both uniformly distributed on the interval from 2000 to 2200. Determine the probability that the company considers the two bids further:

Claims filed under auto insurance policies follow a normal distribution with mean 19400 and standard deviation 5000. Find the probability that the average of 25 randomly selected claims exceeds 20000:

Reliability  (3)

A battery has a lifetime that is approximately normally distributed with a mean of 1000 hours and a standard deviation of 50 hours. Find the fraction with a lifetime between 800 and 1000 hours:

Out of 100 batteries, compute how many have a lifetime between 800 and 1000 hours:

A system is composed of 4 independent components, each with lifespan exponentially distributed with parameter . Find the probability that no component fails before 500 hours:

Directly use SurvivalFunction:

Find the probability that exactly one component will fail in the first 1200 hours:

Directly use CDF and SurvivalFunction:

By using BooleanCountingFunction you can also define the logical condition:

A budget-priced lighter has 0.90 probability of lighting on any given attempt. Simulate the lighting process; the result indicates the number of failures before successful lighting:

Find the probability that the lighter lights in 3 trials or less:

Other Applications  (6)

A radioactive material on average emits 3.2 -particles per second; show the distribution:

Compute the probability that more than 4 -particles are emitted over the next second:

Simulate a typical particle count per second over 10 minutes:

A company manufactures nails with length normally distributed, mean 0.497 inches, and standard deviation 0.002 inches. Find the fraction that satisfies the specification of length equal to 0.5 inches plus/minus 0.004 inches:

Assume the waiting time a customer spends in a restaurant is exponentially distributed with an average wait time of 5 minutes. Find the probability that the customer will have to wait more than 10 minutes:

Find the probability that the customer will have to wait an additional 10 minutes, given that he or she has already been waiting for at least 10 minutes (the past does not matter):

A drug has proven to be effective in 30% of cases. Find the probability it is effective in 3 of 4 patients:

Suppose there are 5 defective items in a batch of 10 items, and 6 items are selected for testing. Simulate the process of testing when the number of defective items found is counted:

Find the probability that there are 2 defective items in the sample:

Assume that the duration of telephone calls is exponentially distributed. The average length of a telephone call is 3.7 minutes. Find the probability that 9 consecutive phone calls will be longer than 25 minutes:

Summing 9 independent phone call durations:

The probability that they last longer than 25 minutes:

Properties & Relations  (11)

The probability of an event in a continuous distribution is defined by an integral:

The probability of an event in a discrete distribution is defined by a sum:

The CDF and SurvivalFunction of a distribution can be expressed as probabilities:

The survival function for a distribution can be expressed as a probability:

The hazard function for a distribution can be expressed as a probability:

The probability of an impossible event is 0:

The probability of a certain event is 1:

The probability of an arbitrary event must lie between 0 and 1:

Use Probability to find a symbolic expression for the probability of an event:

N[Probability[]] is equivalent to NProbability if symbolic evaluation fails:

A conditional probability is defined by a ratio of probabilities:

The probability of independent events is the sum of the individual probabilities:

For dependent events one needs to subtract the probability of an intersection event:

Compute the probability of an event:

Obtain the same result using NExpectation:

Possible Issues  (1)

NProbability may fail without a warning message in the presence of symbolic parameters:

Probability gives a closed-form result in this example:

Wolfram Research (2010), NProbability, Wolfram Language function, https://reference.wolfram.com/language/ref/NProbability.html.

Text

Wolfram Research (2010), NProbability, Wolfram Language function, https://reference.wolfram.com/language/ref/NProbability.html.

CMS

Wolfram Language. 2010. "NProbability." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NProbability.html.

APA

Wolfram Language. (2010). NProbability. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NProbability.html

BibTeX

@misc{reference.wolfram_2024_nprobability, author="Wolfram Research", title="{NProbability}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/NProbability.html}", note=[Accessed: 13-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_nprobability, organization={Wolfram Research}, title={NProbability}, year={2010}, url={https://reference.wolfram.com/language/ref/NProbability.html}, note=[Accessed: 13-November-2024 ]}