♣ 21 ♣Regression Models
21.1 Linear Regression
Linear Regression
With a linear regression we try to estimate an unknown variable y based on a known variable x and some constants (a and b). Its form is
To illustrate the linear regression, we will use data of the dataset survey from the package MASS. This dataset contains some physical measures, such as the span of the hand (variable Wr.Hand), the height of the person (variable Height, and the gender (variable Sex). Let us first illustrate the data by plotting the hand size in function of the height (results in Figure 21.1 on page 376):
The package
stats, that is loaded at start of R, has a function called
lm() that can handle a linear regression. Its use is not difficult: we provide a data-frame (argument
data) and a formula (argument
formula). The formula has the shape of
Figure 21.1: A scatter-plot generated by the line “plot(survey$Height, survey$Wr.Hnd).”
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access