WeBWorK Main Forum

The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

by tim Payer -
Number of replies: 4

I was editing some webwork problems for probability and thought I had a faulty variable as I was getting p-values that exceed one.

It turns out that it is the normal_prob() command.

Apparently the threshold for valid Z-scores to use for inputs is within  plus/minus 3.71 standard deviations.

Using 
$pv = normal_prob(-infty, $zh1, mean=>0, deviation=>1);

Results in the associated output:

P(Z < -3.71) = 0.000104  Correct
P(Z < -3.72) = 22.1828
P(Z < -3.73) = 21.0955
P(Z < -3.74) = 20.008
P(Z < -3.75) = 18.9209
P(Z < -3.8) = 14.5716

Can this interval be widened? Or does it look like I must modify my problem sets to stay within plus/minus 3.7 standard deviation?

Thanks for any feedback,

Tim

In reply to tim Payer

Re: The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

by Alex Jordan -

The actual value of P(Z < -3.72) is:

0.0000996114

which in scientific notation is

9.96114e-5

And if something interprets "e" as Euler's constant and the "-" as subtraction, the above is:

22.077

which is close to what you report here. So I think that (a) there is a small rounding error in play, and (b) more importantly you have something at some point in your code that sends something close to "9.96114e-5" as a string to a MathObject constructor, where the "e" is interpreted as Euler's constant and the "-" as subtraction.

Fixing (b) should be easy. Review your problem code for the chain of commands that produces the 22.1828, and edit it to prevent the string interpolation.

(a) might be an issue built into the library that PGstatisticsmacros relies on. If addressing (b) is not enough for your purposes, post more details and we can continue working to make that function perform better.

In reply to Alex Jordan

Re: The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

by tim Payer -

Thank you Alex, that makes sense.


Here is the adaptation that I used to prevent the reading of scientific notation as and operation using "e" as a multiple, and the exponent as a term to be added or subtracted:

## Testing p-value ranges:

$z = Compute("-4.89");

$q = normal_prob(-infty, $z, mean=>0, deviation=>1);

$qz = Real($q);

$p = Compute("$qz")->with(

  tolType => 'absolute',

  tolerance => .00001,

  );


###

Squeezing in a Real() command prevents the reading of Sci-Fi notation as an operation.

Now the lower and upper limit of extreme probability values for Z-scores are: (-4.89 < Z < 7.03).

Outside of these values the probabilities of Z-scores on the normal_prob() command all go to zero. This is a big improvement over the Z-values less than Z = -3.7 returning probabilities with absolute values larger than one.

Best, tim

In reply to tim Payer

Re: The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

by Danny Glin -

You can simplify your code a bit here.  Because "Real" already creates a MathObject the extra "Compute" isn't really doing anything.

You could skip to

$p = Real($q)->with(

tolType => 'absolute',

  tolerance => .00001,

  );


Or even

$p = Real (normal_prob(-infty, $z, mean=>0, deviation=>1))->with(

tolType => 'absolute',

  tolerance => .00001,

  );

Also, you don't need to convert your z-score to a MathObject (unless you are using it elsewhere in the problem), so the Compute call on $z isn't necessary for the code snippet you posted.
In reply to Danny Glin

Re: The normal_prob() command produces probabilities greater than 1 beyond +/- 3.7 sd

by tim Payer -

Thank you Danny!

That will help streamline the code block.


Best, Tim