library(magrittr)
# as pearson's correlation
cor <- anscombe %$% cor(y1, x1)
cor
## [1] 0.8164205
# as a linear model
fit <- anscombe %$% lm(y1 ~ x1)
fit
##
## Call:
## lm(formula = y1 ~ x1)
##
## Coefficients:
## (Intercept) x1
## 3.0001 0.5001
# as a linear model with standardized parameters
fit.scaled <- anscombe %$% lm(scale(y1) ~ scale(x1))
fit.scaled
##
## Call:
## lm(formula = scale(y1) ~ scale(x1))
##
## Coefficients:
## (Intercept) scale(x1)
## -1.674e-17 8.164e-01
# is the standardized parameter for x1 equal to pearson's correlation?
coef(fit.scaled) == cor
## (Intercept) scale(x1)
## FALSE TRUE