Skip to contents

Simulates two numeric variables linear correlated, given a Pearson linear correlation coefficient, that also follows a normal distribution.

Usage

rpearson(n = 25, pearson = 0.5, tol = 0.1, mean = 0, sd = 1)

Arguments

n

A numeric integer single value (default = 25), that will be the number of observations to simulate

pearson

A numeric single value (default = 0.50), that will be the expected Pearson linear correlation coefficient

tol

A numeric single value (default = 0.10), that will be the tolerance between the simulated and estimated correlation

mean

A numeric single value (default = 0), that will be the mean of the simulated data

sd

A numeric single value (default = 1), that will be the standard deviation of the simulated data

Value

A tibble (nx2) with two numeric variables (x and y).

Examples


df <- rpearson(n = 100, pearson = .8, mean = 3)

head(df)
#> # A tibble: 6 × 2
#>       x     y
#>   <dbl> <dbl>
#> 1  1.00 0.456
#> 2  2.00 1.18 
#> 3  3.42 1.62 
#> 4  2.94 2.20 
#> 5  2.92 2.13 
#> 6  2.97 2.22 

plot(df)