options(
scipen = 999
)
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.3 ✓ dplyr 1.0.0
## ✓ tidyr 1.1.0 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
#make some data
set.seed(1488)
d = MASS::mvrnorm(n = 10e3,
mu = c(0, 0),
Sigma = matrix(c(1, .5, .5, 1), nrow = 2),
empirical = T) %>%
as_tibble()
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
#stats
psych::describe(d)
#cors
cor(d)
## V1 V2
## V1 1.0 0.5
## V2 0.5 1.0
#var and covar
var(d)
## V1 V2
## V1 1.0 0.5
## V2 0.5 1.0
#slopes
lm(V1 ~ V2, data = d)
##
## Call:
## lm(formula = V1 ~ V2, data = d)
##
## Coefficients:
## (Intercept) V2
## 0.00000000000000001221 0.49999999999999983347
lm(V2 ~ V1, data = d)
##
## Call:
## lm(formula = V2 ~ V1, data = d)
##
## Coefficients:
## (Intercept) V1
## 0.00000000000000000222 0.49999999999999944489
#change the scale of V1 to SD = 2
d2 = d
d2$V1 = d2$V1 * 2
#stats
psych::describe(d2)
#cors
cor(d2)
## V1 V2
## V1 1.0 0.5
## V2 0.5 1.0
#var and covar
var(d2)
## V1 V2
## V1 4 1
## V2 1 1
#slopes
lm(V1 ~ V2, data = d2)
##
## Call:
## lm(formula = V1 ~ V2, data = d2)
##
## Coefficients:
## (Intercept) V2
## 0.00000000000000002442 0.99999999999999966693
lm(V2 ~ V1, data = d2)
##
## Call:
## lm(formula = V2 ~ V1, data = d2)
##
## Coefficients:
## (Intercept) V1
## 0.00000000000000000222 0.24999999999999972244
Notes: