simCorVars

0th

Percentile

Simulate correlated variables.

The function simulates a pair of correlated variables.

Keywords
univar
Usage
simCorVars(n, r, mu1 = 0, mu2 = 0, sd1 = 1, sd2 = 1, plot = TRUE)
Arguments
n

integer: sample size.

r

numeric: correlation.

mu1

numeric: mean of first variable.

mu2

numeric: mean of second variable.

sd1

numeric: SD of first variable.

sd2

numeric: SD of second variable.

plot

logical: generate scatter plot of the variables.

Details

The function is mainly for teaching purposes and simulates n observations from a pair of normal distributed variables with correlation r.

By specifying plot = TRUE a scatter plot of the data is generated.

Value

data.frame with entries Var1 and Var2

Aliases
  • simCorVars
Examples
# NOT RUN {
set.seed(123)
res <- simCorVars(n = 100, r = 0.8)
cor(res$Var1, res$Var2)
colMeans(res)
apply(res, 2, sd)
set.seed(123)
res <- simCorVars(n = 100, r = 0.8, mu1 = -1, mu2 = 1, sd1 = 2, sd2 = 0.5)
cor(res$Var1, res$Var2)
colMeans(res)
apply(res, 2, sd)
# }
Documentation reproduced from package MKdescr, version 0.5, License: LGPL-3

Community examples

Looks like there are no examples yet.