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 152axis in the histogram using xlim=to get the axes to match. Other layouts are possible, asdetailed in the help page ?lay out.)Figure 5.6 Histogram and boxplot of50 samples from the Uni<strong>for</strong>m(0, 10)distribution and the Exponential(1/5)distribution. Both empiricaldensities and population densitiesare drawn.Exponential distributionThe exponential distribution is an example of a skewed distribution. It is a popular model<strong>for</strong> populations such as the length of time a light bulb lasts. The density is f(x\λ)=λe −λx ,x≥0. The parameter λ is related to the mean by µ=1/λ and to the standard deviation byσ=1/λ.In R the family name is exp and the parameter is labeled rate=. We refer to thisdistribution as Exponential (λ).The right graphic of Figure 5.6 shows a random sample of size 50 from theExponential (1/5) distribution, made as follows:> res = rexp(50, rate=1/5)## boxplot> par(fig=c(0,1,0,.35))> boxplot(res, horizontal=TRUE, bty="n",xlab="exponential sample”)## histogram> par(fig=c(0,1,.25,1), new=TRUE)## store values, then find largest y one to set ylim=> tmp.hist = hist(res, plot=FALSE)> tmp.edens = density(res)> tmp.dens = dexp(0, rate=1/5)> y.max = max(tmp.hist$density, tmp.edens$y, tmp.dens)## make plots

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

Saved successfully!

Ooh no, something went wrong!