#
# script for topic 8a -- part 3
source("../gnrnd4.R")
gnrnd4(365340906, 6340400805, 2200003)
L1
L2
#
main_hold <- "Problem for Topic 8a, part3"
plot(L1,L2,main=main_hold,
xlim=c(0,26), ylim=c(0,55),
xaxp=c(0,26,13), yaxp=c(0,55,11), las=1,
pch=16, col="red", mar=c(2,0,0,0)+0.2,
ylab="y values", xlab="x values")
abline(h=seq(0,55,5), v=seq(0,26,1),
lty="dotted", col="blue")
# get the two values for our regression equation,
# the intercept and the slope
lm( L2 ~ L1)
# From the output of that command we see that the
# intercept is 13.81 and the slope is 1.27. So
# our regression equation is y = 13.81 + 1.27*x
# We sill graph it on our plot
abline( 13.81, 1.27, col="darkred")
#
# We can find the expected value when x=18
ev <- 13.81 + 1.27*18
ev
# And then we can plot that point on the graph
# with a green triangle
points( 18, ev, pch=17, col="darkgreen")
# And we can find the expected value for x=7
ev <- 13.81 + 1.27*7
ev
# And then we can plot that point on the graph
# with a blue square
points( 7, ev, pch=15, col="blue")
#
# Now find the correlation coefficient
cor( L1, L2 )
#
# One other issue is to find some residual values.
# Here we do that the hard way, we will compute the
# observed - expected value for a given x value.
# Find the residual value when x=17. The observed
# value when x=17 is y=26. We need to compute the
# expected value and then subtract that from 26 to
# get the residual value.
26 - ( 13.81 + 1.27*17)
#
# If we find all of the
# residual values and
# then get a scatter plot
# of the x and residual
# values, we want to see
# the points all over the
# scatter plot.
res_vals <- L2 -
( 13.81 + 1.27*L1)
plot( L1, res_vals,
main="Residuals")