Another topic related to

We can generate, display, and create the

gnrnd4( key1=967170506, key2=6121050612, key3=8600004 ) L1 L2 lm_L2L1 <- lm(L2~L1) lm_L2L1 cor(L1,L2)These produce the console text in Figure 1.

We use the information in Figure 1 to form the

We can even generate a plot of the

plot(L1,L2,xlim=c(0,80),xaxp=c(0,80,16), ylim=c(0,60),yaxp=c(0,60,12), main="Graph of Table 1 and Regression", las=1, cex.axis=0.7, pch=18, col="darkgreen") abline(v=seq(0,80,5), col="darkgray", lty=3) abline(h=seq(0,60,5), col="darkgray", lty=3) abline(lm_L2L1, col="red", lwd=2)That plot is shown in Figure 2.

We are looking for the

c_vals <- coefficients(lm_L2L1) c_vals y_vals <- c_vals[1]+c_vals[2]*L1 y_valsfirst retrieve the

`y_vals<-c_vals[1]+c_vals[2]*L1`

uses those
values, along with the
Those **expected y values** are the **y coordinates**
for the associated **x values** of points on the
**regression line**.
We add the plot of these points
to our graph via the
command

points(L1,y_vals,pch=17,col="blue")with the result shown in Figure 4.

On the graph we can represent the

for(i in 1:length(L1)) { lines(c(L1[i],L1[i]),c(L2[i],y_vals[i]),lwd=2)}accomplishes this as we see in Figure 5.

Although the graphic representation is nice, we really want to get the numeric values for the

r_vals <- L2-y_vals r_valsfind those differences, store the differences in

A most careful reader of these pages may recall that we actually saw a display of

Sure enough, there in Figure 7, are the

Recall that we used the

`lm_resid<-residuals(lm_L2L1)`

as shown in Figure 8.
The values shown in Figure 8 match the values we worked so hard to produce earlier.

`plot(L1,lm_resid)`

will produce such a graph, in this case the gaph in Figure 9.
This example has 59 pairs of values. However, the analysis process is the same. As before, we use

gnrnd4( key1=967175806, key2=6121050612, key3=8600004 ) L1 L2 lm_L2L1 <- lm(L2~L1) lm_L2L1 cor(L1,L2)to generate and display (just for verification) the data, as well as to create and display a new

The commands

plot(L1,L2,xlim=c(0,85),xaxp=c(0,85,17), ylim=c(0,65),yaxp=c(0,65,13), main="Graph of Table 2 and Regression", las=1, cex.axis=0.7, pch=18, col="darkgreen") abline(v=seq(0,85,5), col="darkgray", lty=3) abline(h=seq(0,65,5), col="darkgray", lty=3) abline(lm_L2L1, col="red", lwd=2)produce a graph, as shown in Figure 11.

Although we learned above that to just find the

We generate the

c_vals <- coefficients(lm_L2L1) c_vals y_vals <- c_vals[1]+c_vals[2]*L1 y_valswith the console output in Figure 12.

We graph the

points(L1,y_vals,pch=17,col="blue") for(i in 1:length(L1)) { lines(c(L1[i],L1[i]),c(L2[i],y_vals[i]),lwd=2)}changing the graph to that in Figure 13.

We compute and display the

r_vals <- L2-y_vals r_valsas shown in Figure 14.

Then, just so that we can see the values we use the

Note that there is a subtle change to the format of the output in Figure 15 compared to the format that we saw back in Figure 7. In the earlier display, R actually gave us the 6

We use the commands

lm_resid <- residuals(lm_L2L1) lm_residto retrieve the

The display in Figure 16 takes up a bit more room than did our earleir display, in Figure 14, of the

Finally, we use the command

`plot(L1,lm_resid)`

to plot
the ©Roger M. Palay Saline, MI 48176 November, 2015