R Help Probability Distributions Fall 2003, Lecture notes of Probability and Statistics

How to use R to calculate probabilities associated with common distributions and graph probability distributions. It covers the Binomial, Poisson, and Normal distributions, as well as the t, F, and chi-square distributions. tables and examples of commands for each distribution. It also explains the binomial distribution and its probability mass function. examples of finding probabilities, percentiles, and endpoints of distributions using R functions.

Typology: Lecture notes

2021/2022

Uploaded on 05/11/2023

christin
christin 🇺🇸

4.6

(18)

263 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
R Help Probability Distributions Fall 2003
This document will describe how to use R to calculate probabilities associated with common distribu-
tions as well as to graph probability distributions.
R has a number of built in functions for calculations involving probability distributions, both discrete
and continuous. This semester we will see the Binomial,Poisson, and Normal distributions early during
our introduction to probability. Later, we will use the t,F, and chi-square distributions in our study of
statistical inference.
For each of these distributions (and others), R has four primary functions. Each function has a one
letter prefix followed by the root name of the function. The names make mnemonic sense for continuous
random variables but are used in both cases. For example dnorm is the height of the density of a normal
curve while dbinom returns the probability of an outcome of a binomial distribution. Here is a table of
these commands.
Meaning
Prefix Continuous Discrete
d density probability (pmf)
p probability (cdf) probability (cdf)
q quantile quantile
r random random
Distribution Root
Binomial binom
Poisson pois
Normal norm
tt
FF
Chi-square chisq
Graphing Probability Distributions. The file prob.R contains function that may be used to graph
and visualize the binomial and normal distributions. Here are some examples of their use.
> source("prob.R")
> gbinom(20, 0.3)
0 5 10 15 20
0.00 0.10
Binomial Distribution
n = 20 , p = 0.3
Possible Values
Probability
This plot will help visualize the probability of getting between 45 and 55 heads in 100 coin tosses.
> gbinom(100, 0.5, a = 45, b = 55, scale = T)
Bret Larget September 17, 2003
pf3
pf4
pf5

Partial preview of the text

Download R Help Probability Distributions Fall 2003 and more Lecture notes Probability and Statistics in PDF only on Docsity!

This document will describe how to use R to calculate probabilities associated with common distribu- tions as well as to graph probability distributions. R has a number of built in functions for calculations involving probability distributions, both discrete and continuous. This semester we will see the Binomial, Poisson, and Normal distributions early during our introduction to probability. Later, we will use the t, F, and chi-square distributions in our study of statistical inference. For each of these distributions (and others), R has four primary functions. Each function has a one letter prefix followed by the root name of the function. The names make mnemonic sense for continuous random variables but are used in both cases. For example dnorm is the height of the density of a normal curve while dbinom returns the probability of an outcome of a binomial distribution. Here is a table of these commands.

Meaning Prefix Continuous Discrete d density probability (pmf) p probability (cdf) probability (cdf) q quantile quantile r random random

Distribution Root Binomial binom Poisson pois Normal norm t t F F Chi-square chisq

Graphing Probability Distributions. The file prob.R contains function that may be used to graph and visualize the binomial and normal distributions. Here are some examples of their use.

source("prob.R") gbinom(20, 0.3)

Binomial Distribution

n = 20 , p = 0.

Possible Values

Probability

This plot will help visualize the probability of getting between 45 and 55 heads in 100 coin tosses.

gbinom(100, 0.5, a = 45, b = 55, scale = T)

Binomial Distribution

n = 100 , p = 0.

Possible Values

Probability

P(45 <= Y <= 55) = 0.

The Binomial Distribution. The binomial distribution is applicable for counting the number of out- comes of a given type from a prespecified number n independent trials, each with two possible outcomes, and the same probability of the outcome of interest, p. The distribution is completely determined by n and p. The probability mass function is defined as:

Pr{Y = j} =

n j

pj^ (1 − p)n−j

where (^) ( n j

n! j!(n − j)!

is called a binomial coefficient. (Some textbooks use the notation (^) nCj instead.) In R, the function dbinom returns this probability. There are three required arguments: the value(s) for which to compute the probability (j), the number of trials (n), and the success probability for each trial (p). For example, here we find the complete distribution when n = 5 and p = 0.1.

dbinom(0:5, 5, 0.1)

[1] 0.59049 0.32805 0.07290 0.00810 0.00045 0.

If we want to find the single probability of exactly 10 successes in 100 trials with p = 0.1, we do this.

dbinom(10, 100, 0.1)

[1] 0.

Heights of individual corn plants may be modeled as normally distributed with a mean of 145 cm and a standard deviation of 22 cm (Samuels and Witmer, third edition, exercise 4.29). Here are several example normal calculations using R. The commands using gnorm allow you to visualize the answers. Find the proportion of plants:

... larger than 100cm;

1 - pnorm(100, 145, 22)

[1] 0.

gnorm(145, 22, a = 100)

Normal Distribution

mu = 145 , sigma = 22

Possible Values

Probability Density

P( X < 100 ) = 0. P( X > 100 ) = 0.

... between 120cm and 150cm:

pnorm(150, 145, 22) - pnorm(120, 145, 22)

[1] 0.

gnorm(145, 22, a = 120, b = 150)

Normal Distribution

mu = 145 , sigma = 22

Possible Values

Probability Density

P( 120 < X < 150 ) = 0. P( X < 120 ) = 0. P( X > 150 ) = 0.

... 150cm or less:

pnorm(150, 145, 22)

[1] 0.

gnorm(145, 22, b = 150)

Normal Distribution

mu = 145 , sigma = 22

Possible Values

Probability Density

P( X < 150 ) = 0. P( X > 150 ) = 0.

Find the 75th percentile.

qnorm(0.75, 145, 22)

Other Distributions Other distributions work in a similar way, except that I have not yet written anal- ogous graphing functions. Details on how to express the parameters for different probability distributions can be found from the help files. For example, to learn about find Poisson probabilities, type ?dpois.