The inverse, if needed, could be accomplished with erfi Although I also
interpreted the question to be how to get the cdf.
#
# if single argument, return quantile corresponding to the given
# probability from the standard normal distribution
#
# if three arguments, return quantile from a normal distribution with
# the given mean and variance
#
sub normal_qdf {
@_ == 1 or @_ == 3 or die;
my ($mean, $var, $p) = @_ == 1 ? (0, 1, @_) : @_;
return sqrt(2*$var)*erfi(2*$p-1) + $mean;
}
> I think there is some confusion about terminology here:
>
> PDL::GSL::RNG can give random deviates from the standard normal
> distribution (and a whole bunch others) and does this quite well.
>
> This is what I would have understood from Steve's question, however
> the example says pnorm(0) = 0.5 which uses the notation in R for the
> CDF. To calculate this you need to do an integral yourself AFAIK.
>
> If you want a general function ala R, you can do something like:
>
> sub pnorm {
> my ($x, $sigma, $mu) = @_;
> $sigma= 1 unless defined($sigma);
> $mu = 0 unless defined($mu);
>
> return 0.5*(1+erf(($x-$mu)/(sqrt(2)*$sigma)));
>
> }
>
> (very similar to Pete Ratzlaff's statement earlier). The inverse of
> this is more fiddly - the only Perl implementation I know of (probably
> there are more!) is this one: http://home.online.no/~pjacklam/notes/invnorm/
> (which you also find linked from one of the Wikipedia articles about
> the normal distribution or quantile functions, I forget which). This
> is what R calls qnorm.
>
> Cheers,
> Jarle.
>
>
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl