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.

Describing populations 1455.7 Toss two coins. Let X be the number of heads and Y the number of tails. Are X andY independent?5.2 Families of distributionsIn statistics there are a number of distributions that come in families. Each family isdescribed by a function that has a number of parameters characterizing the distribution.For example, the uni<strong>for</strong>m distribution is a continuous distribution on the interval [a,b]that assigns equal probability to equal-sized areas in the interval. The parameters are aand b, the endpoints of the intervals.5.2.1 The d, p, q, and r functionsR has four types of functions <strong>for</strong> getting in<strong>for</strong>mation about a family of distributions.The “d” functions return the p.d.f. of the distribution, whereas the “p” functions return thec.d.f. of the distribution. The “q” functions return the quantiles, and the “r” functionsreturn random samples from a distribution.These functions are all used similarly. Each family has a name and some parameters.The function name is found by combining either d, p, q, or r with the name <strong>for</strong> the family.The parameter names vary from family to family but are consistent within a family.For example, the uni<strong>for</strong>m distribution on [a,b] has two parameters. The family nameis unif. In R the parameters are named min= and max=.> dunif(x=1, min=0, max=3)[1] 0.3333> punif(q=2, min=0, max=3)[1] 0.6667> qunif(p=1/2, min=0, max=3)[1] 1.5> runif(n=1, min=0, max=3)[1] 1.260The above commands are <strong>for</strong> the uni<strong>for</strong>m distribution on [0, 3]. They show that thedensity is 1/3 at x=1 (as it is <strong>for</strong> all 0≤x≤3); the area to the left of 2 is 2/3; the median or.5-quantile is 1.5; and a realization of a random variable is 1.260. This last command willvary each time it is run.It is useful to know that the arguments to these functions can be vectors, in which caseother arguments are recycled. For example, multiple quantiles can be found at once.These commands will find the quintiles:> ps = seq(0,1,by=.2) # vector> names(ps)=as.character(seq(0,100,by=20)) # give names> qunif(ps, min=0, max=1)0 20 40 60 80 1000.0 0.2 0.4 0.6 0.8 1.0

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

Saved successfully!

Ooh no, something went wrong!