12.07.2015 Views

Analytical Chem istry - DePauw University

Analytical Chem istry - DePauw University

Analytical Chem istry - DePauw University

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.

Chapter 5 Standardizing <strong>Analytical</strong> Methods193where y and x are the objects containing our data. To access the results ofthe regression analysis, we assign them to an object using the followingcommand> model = lm(signal ~ conc)where model is the name we assign to the object.You can choose any name for the objectcontaining the results of the regressionanalysis.Ev a l u a t i n g t h e Li n e a r Re g r e s s i o n Mod e lTo evaluate the results of a linear regression we need to examine the dataand the regression line, and to review a statistical summary of the model. Toexamine our data and the regression line, we use the plot command, whichtakes the following general formplot(x, y, optional arguments to control style)where x and y are objects containing our data, and the abline commandabline(object, optional arguments to control style)where object is the object containing the results of the linear regression.Entering the commands> plot(conc, signal, pch = 19, col = “blue”, cex = 2)> abline(model, col = “red”)creates the plot shown in Figure 5.21.To review a statistical summary of the regression model, we use thesummary command.> summary(model)The resulting output, shown in Figure 5.22, contains three sections.The first section of R’s summary of the regression model lists the residualerrors. To examine a plot of the residual errors, use the commandsignal0 10 20 30 40 50 60> plot(model, which=1)0.0 0.1 0.2 0.3 0.4 0.5concFigure 5.21 Example of a regression plot in R showing the data andthe regression line. You can customize your plot by adjusting theplot command’s optional arguments. The argument pch controlsthe symbol used for plotting points, the argument col allows you toselect a color for the points or the line, and the argument cex setsthe size for the points. You can use the commandhelp(plot)The name abline comes from the followingcommon form for writing the equationof a straight-line.y = a + bxThe reason for including the argumentwhich=1 is not immediately obvious.When you use R’s plot command on anobject created by the lm command, the defaultis to create four charts summarizingthe model’s suitability. The first of thesecharts is the residual plot; thus, which=1limits the output to this plot.to learn more about the options for plotting data in R.

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

Saved successfully!

Ooh no, something went wrong!