ch5fig1.proc <- function(df = brainframe){
#
# Procedure to generate Fig. 1 in Chapter 5, comparing
# direct and inverse regression lines for the log-transformed
# brain weight vs. body weight dataset
#
# First, define the variables
#
x <- log(df[,"BodyWt"])
y <- log(df[,"BrainWt"])
#
# Next, fit the two regression models
#
olsfit1 <- lm(y ~ x)
olsfit2 <- lm(x ~ y)
#
# Convert the coefficients of the inverse model into direct form
#
bmod <- 1/olsfit2$coef[2]
amod <- - bmod * olsfit2$coef[1]
#
# Generate the plot with both lines
#
par(mfrow=c(1,1))
par(adj = 0.5)
plot(x,y)
abline(olsfit1)
abline(a = amod, b = bmod, lwd=3)
#
# Annotate the plot
#
text(5,8,"Thin = OLS")
text(5,7,"Thick = IR")
#
}