Message Boards Message Boards

0
|
2525 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

The probability of a random number less than a specific value

Posted 9 years ago
x = RandomVariate[NormalDistribution[1, 3], 10^4];

If x are some random numbers like that, how to write the program about the probability of x<1.2, thanks very much

POSTED BY: Axes Lee
5 Replies

There is also the new (i.e. MMA10.1) function FindDistribution.

n = 10^4;
data = RandomVariate[NormalDistribution[1, 3], n];
z = 1.2;
\[ScriptCapitalD] = FindDistribution[data];
NProbability[x <= z, x \[Distributed] \[ScriptCapitalD]]
(*0.529283*)

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 9 years ago

Here are two ways:

z = 1.2;

(* Estimate of Pr(X < z) *)
n = 10^4;
x = RandomVariate[NormalDistribution[1, 3], n];
N[Count[x, x_ /; x < z]/n]
N[Length[Select[x, # < z &]]/n]
POSTED BY: Jim Baldwin
Posted 9 years ago

Thank you, It helps me a lot. LOL

POSTED BY: Axes Lee
Posted 9 years ago

From your response I'm not convinced I answered your question. How to estimate (or calculate) Pr(X < z) depends on what you know and whether you are a Frequentist or a Bayesian. Here is an expansion on some possibilities if you are a Frequentist:

(* Generate a sample dataset *)
n = 10^4;
x = RandomVariate[NormalDistribution[1, 3], n];

(* Objective is to estimate Pr(X < z) with z=1.2 *);
z = 1.2;

(* Estimate of Pr(X < z) if all you know is that you have a simple \
random sample of size n from some unknown distribution *)
N[Count[x, x_ /; x < z]/n]
N[Length[Select[x, # < z &]]/n]

(* Calculation (rather than estimation) of Pr(X < z) if you know that \
you are sampling from a normal distribution with mean 1 and standard \
deviation 3 *)
CDF[NormalDistribution[1, 3], z]

(* Estimate of Pr(X < z) if all you know is that you have a simple \
random sample from a normal distribution with unknown mean and \
unknown standard deviation *)
CDF[NormalDistribution[Mean[x], StandardDeviation[x]], z]

0.5295

0.5295

0.526576

0.524444
POSTED BY: Jim Baldwin
Posted 9 years ago

Very nice, Marco!

For this particular example (10^4 samples from a normal distribution with mean 1 and standard deviation 3 and z = 1.2) the FindDistribution approach results in a smaller root mean square error for the estimator of Pr(X < z) than the naïve count approach and is almost as good as knowing that the distribution is normal. Here are the root mean square errors I found using 1,000 simulations:

 0.0041996  for the FindDistribution approach

 0.0048878  for the naïve count approach

 0.0039955  for the "knowing the distribution is normal but not the mean and standard deviation" approach.

Of course, depending on the distribution, the parameters of the distribution, the sample size, and the value of z, your mileage may vary.

POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract