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 98> the.labels = c("lm","lm w/o 1","least trimmedsquares”,+ "rlm with MM")> the.ltys = 1:4> legend(5000,6000,legend=the.labels,lty=the.Itys)Figure 3.15 Emissions data with fourdifferent regression lines3.4.7 Trend linesIf a scatterplot suggests some relationship, but not an obvious trans<strong>for</strong>mation to make alinear relationship, we can still superimpose a “trend line” on top of the data using one ofthe many scatterplot smoothing techniques available in R. These produce a smooth curvesummarizing the relationship between the two variables.The stats package provides several functions <strong>for</strong> creating trend lines. The scatter.smooth() function uses the loess() function from the same package to plot both thescatterplot and a trend line. Additionally, smooth. spline() will fit the data using cubicsplines, and the supsmu() function will per<strong>for</strong>m Friedman’s “super smoother” algorithm.■ Example 3.9: Five years of temperature data Weather data should show seasonaltrends. The data set five.yr. temperature (<strong>Using</strong>R) has five years of New York Citytemperature data. A scatterplot shows a periodic, sinusoidal pattern. In Figure 3.16, threetrend lines are shown, although two are nearly identical.> attach(five.yr.temperature)> scatter.smooth(temps ~ days,col=gray(.75),bty="n”)> lines(smooth.spline(temps ~ days), lty=2, lwd=2)> lines(supsmu(days, temps), lty=3, lwd=2)> legend(locator(1),lty=c(1,2,3),lwd=c(1,2,2),+ legend=c("scatter.smooth","smooth.spline","supsmu"))> detach(five.yr.temperature)

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

Saved successfully!

Ooh no, something went wrong!