Tuesday, September 25, 2012

Determining Probabilities and Quantiles in R and SAS for a Normal Distribution

In R, let's say we wanted to determine the probability of P(X ≤ c). If X is already standardized, i.e. normalized, then we would do:
> pnorm(c)
If not, then we would do:
> pnorm(c,mu,sd)
where c is the value of interest, mu is the mean of the sample, and sd is the standard deviation. In SAS, we can use the PROC IML step:
PROC IML;
   prob = CDF('Normal',c);
   PRINT prob;
QUIT;
or
PROC IML;
   prob = CDF('Normal',c,mu,sd);
   PRINT prob;
QUIT;
Example: If we let c = 1.96, mu = 0, and sd = 1, then the probability associated with this particular example is 0.975. You should get familiar with this number because, when we do a two-sided hypothesis test, we assume α = 0.05 and test for 100(1-α/2) = 100(1-0.05/2) = 0.975.

In the case where we want to determine the quantile associated with a particular probability, i.e. what is the 100(n)th percentile (assuming X follows a normal distribution of mean mu and standard deviation mu), then in R we use:
> qnorm(n,mu,sd)
and in SAS we do:
PROC IML;
   quant = QUANTILE('Normal',n,mu,sd);
   PRINT quant;
QUIT;
NOTE: n is a value between 0 and 1. For example, if we are interested in the 90th percentile, then for either R or SAS, the input value is 0.90.

No comments:

Post a Comment