library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(datasets)
datasets::anscombe
##    x1 x2 x3 x4    y1   y2    y3    y4
## 1  10 10 10  8  8.04 9.14  7.46  6.58
## 2   8  8  8  8  6.95 8.14  6.77  5.76
## 3  13 13 13  8  7.58 8.74 12.74  7.71
## 4   9  9  9  8  8.81 8.77  7.11  8.84
## 5  11 11 11  8  8.33 9.26  7.81  8.47
## 6  14 14 14  8  9.96 8.10  8.84  7.04
## 7   6  6  6  8  7.24 6.13  6.08  5.25
## 8   4  4  4 19  4.26 3.10  5.39 12.50
## 9  12 12 12  8 10.84 9.13  8.15  5.56
## 10  7  7  7  8  4.82 7.26  6.42  7.91
## 11  5  5  5  8  5.68 4.74  5.73  6.89
colMeans(anscombe)
##       x1       x2       x3       x4       y1       y2       y3       y4 
## 9.000000 9.000000 9.000000 9.000000 7.500909 7.500909 7.500000 7.500909
View(anscombe)

round(sapply(anscombe, mean), 3)
##    x1    x2    x3    x4    y1    y2    y3    y4 
## 9.000 9.000 9.000 9.000 7.501 7.501 7.500 7.501
round(sapply(anscombe, sd), 3)
##    x1    x2    x3    x4    y1    y2    y3    y4 
## 3.317 3.317 3.317 3.317 2.032 2.032 2.030 2.031
round(cor(anscombe[,1:4], anscombe[5:8]), 3)
##        y1     y2     y3     y4
## x1  0.816  0.816  0.816 -0.314
## x2  0.816  0.816  0.816 -0.314
## x3  0.816  0.816  0.816 -0.314
## x4 -0.529 -0.718 -0.345  0.817
lm(y1 ~ x1, data = anscombe)
## 
## Call:
## lm(formula = y1 ~ x1, data = anscombe)
## 
## Coefficients:
## (Intercept)           x1  
##      3.0001       0.5001
lm(y2 ~ x2, data = anscombe)
## 
## Call:
## lm(formula = y2 ~ x2, data = anscombe)
## 
## Coefficients:
## (Intercept)           x2  
##       3.001        0.500
lm(y3 ~ x3, data = anscombe)
## 
## Call:
## lm(formula = y3 ~ x3, data = anscombe)
## 
## Coefficients:
## (Intercept)           x3  
##      3.0025       0.4997
lm(y4 ~ x4, data = anscombe)
## 
## Call:
## lm(formula = y4 ~ x4, data = anscombe)
## 
## Coefficients:
## (Intercept)           x4  
##      3.0017       0.4999

Ozetle \[\overline{x}=9\]

\[\overline{y}=4.5\]

\[sd_\overline{x}=3.32\] \[sd_\overline{y}=4.125\]

\[cor_{xy}=0.816\] \[y = 3 + 0.5x\]

library(quartets)
library(ggplot2)
library(dplyr)
ggplot(anscombe_quartet, aes(x=x, y=y)) +
  geom_point() +
    geom_smooth(method= "lm", formula= "y~ x") +
  facet_wrap(.~dataset)