♣ 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

equation

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

Graph depicts scatter-plot generated by the line plot(survey$Height, survey$Wr.Hnd).

Figure 21.1: A scatter-plot generated by the line “plot(survey$Height, survey$Wr.Hnd).”

Get The Big R-Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.