Showing posts with label probability. Show all posts
Showing posts with label probability. Show all posts

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.

Monday, September 10, 2012

How to calculate the probability from a poisson distribution?

Q: I had a question in regards to R for calculating the Poission when it was if you wish to find something such as P(X≥10). In R I typed dpois (x, lamba, log = FALSE) and could calculate items for example where I am looking for exactly 10 patients however, going back to looking for something such as P(X≥10) how would I input the command in R? I can't seem to find the actual command...please shed some light :)

A: Because the possion distribution ranges for x = {0, infinity}, you use the complement for determining such a value. For example, you want P(X≥10) and it's complement is 1 - P(X < 10) = 1 - P(X≤9), which can be determined using the ppos(x,lamba) command. In this case, it is:

> 1 - ppois(9,lambda)

where lambda is your parameter of interest.

Comment 1: As mentioned in the question, the dpois() function gives us the information for P(X=x), where little x is the quantity of interest. If we want P(X≤x), then we use ppois(), and if we want P(X≥x) we use the complement as stated. Why? Because if we wanted, for example, P(X≥10), then we would need: P(X = 10) + P(X = 11) + ... + P(X = ∞). Thus, since all probabilities must sum to equal 1, utilizing the properties of probabilities and its complement is the easiest route to take. Note that the same applies for a binomial distribution, dbinom() and pbinom().

Comment 2: Notice that, in the cases w/ discrete distributions, when we talk about the complement of P(X≥10), 1 - P(X < 10) = 1 - P(X≤9), we have to drop down a unit? Discretes use integer values, so less than 10 is the same as less than or equal to 9. Please keep this fact in mind when doing other probabilities; that is, there is a difference when we handle the inequalities (≤ and <) and (≥ and >).