Load the data from Table 1 in Section 4.1 into R.

Table1 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter4/Table1.csv")
head(Table1,n=4)
##   Speed Distance
## 1   100      257
## 2   102      264
## 3   103      274
## 4   101      266

Rather than reading the data from Github, we could manually enter the data into R.

Table1a=data.frame("Speed"=c(100, 102, 103, 101, 105, 100, 99, 105), "Distance"=c(257, 264, 274, 266, 277, 263, 258, 275))

Base R

To determine the correlation coefficient in base R, use the cor( ) command. The syntax for the plot command is

cor(table$x-variable, table$y-variable)

cor(Table1$Speed, Table1$Distance)
## [1] 0.9386958

Mosaic

install.packages("Mosaic")

To create a scatter diagram in Mosaic, use the cor command. The syntax for the command is:

cor(y-variable ~ x-variable, data = df_name)

library(mosaic)
cor(Distance ~ Speed,data=Table1)
## [1] 0.9386958