10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> R <strong>for</strong> introductory statistics 146This command, on the other hand, will find five uni<strong>for</strong>m samples from five differentdistributions.> runif(5, min=0, max=1:5) # recycle min,[1] 0.6331 0.6244 1.9252 2.8582 3.00765.2.2 Binomial, normal, and some other named distributionsThere are a few basic distributions that are used in many different probability models:among them are the Bernoulli, binomial, and normal distributions.Bernoulli random variablesA Bernoulli random variable X is one that has only two values: a or 1. The distributionof X is characterized by p=P(X = 1). We use Bernoulli (p) to refer to this distribution.Often the term “success” is given to the event when X=1 and “failure” to the event whenX=a. If we toss a coin and let X be 1 if a heads occurs, then X is a Bernoulli randomvariable where the value of p would be 1/2 if the coin is fair. A sequence of coin tosseswould be an i.i.d. sequence of Bernoulli random variables, also known as a sequence ofBernoulli trials.A Bernoulli random variable has a mean µ=p and a variance σ 2 =p( 1−p).In R, the sample() command can be used to generate random samples from thisdistribution. For example, to generate ten random samples when p=1/4 can be done with> n = 10; p = 1/4> sample(0:1, size=n, replace=TRUE,prob=c(1-p,p))[1] 0 0 0 0 0 0 0 1 0 0Binomial random variablesA binomial random variable X counts the number of successes in n Bernoulli trials.There are two parameters that describe the distribution of X: the number of trials, n, andthe success probability, p. Let Binomial (n, p) denote this distribution. The possible rangeof values <strong>for</strong> X is 0, 1, …, n. The distribution of X is known to beThe termis called the binomial coefficient and is defined bywhere n! is the factorial of n, or n·(n−1) … 2·1. By convention, 0!=1. The binomialcoefficient, counts the number of ways k objects can be chosen from n distinct objectsand is read “n choose k.” The choose() function finds the binomial coefficients.The mean of a Binomial (n, p) random variable is µ=np, and the standard deviation is

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!