Lab 02: Linear Regression
function is used to load
, or groups of functions and data sets that are not included
in the base
Basic functions that perform least squares linear regression and other simple
analyses come standard with the base distribution, but more exotic functions require additional libraries.
Here we load the
package, which is a very large collection of data sets and functions. We also load the
package, which includes the data sets associated with this book.
## Attaching package: 'ISLR2'
## The following object is masked from 'package:MASS':
If you receive an error message when loading any of these libraries, it likely indicates that the corresponding
library has not yet been installed on your system.
Some libraries, such as
, come with
not need to be separately installed on your computer.
However, other packages, such as
be downloaded the first time they are used.
This can be done directly from within
. For example, on
a Windows system, select the
option under the
After you select any
mirror site, a list of available packages will appear.
Simply select the package you wish to install and
will automatically download the package.
Alternatively, this can be done at the
command line via
This installation only needs to be done the first time you use a package.
function must be called within each
Simple Linear Regression
library contains the
data set, which records
(median house value) for
tracts in Boston. We will seek to predict
predictors such as
(average number of rooms
(average age of houses), and
(percent of households with low socioeconomic status).
crim zn indus chas
dis rad tax ptratio lstat medv
## 1 0.00632 18
0 0.538 6.575 65.2 4.0900
## 2 0.02731
0 0.469 6.421 78.9 4.9671