rsim: Simulating Correlated Scores

View source: R/rsim.R

rsimR Documentation

Simulating Correlated Scores

Description

Simulates vectors of scores with specified correlation, means, and standard deviations.

Usage

rsim(n, rho, x, meanx = 0, sdx = 1, meany = 0, sdy = 1, to.data.frame = FALSE)

Arguments

n

number of observations. If length(n) > 1, the length is taken to be the number required.

rho

correlation in the population.

x

vector of scores to be correlated with. If x is supplied, n is overridden to be length(x), meanx and sdx are set to mean(x) and sd(x), and y is created to correlate at rho with x.

meanx, sdx

the desired mean and standard deviation of x.

meany, sdy

the desired mean and standard deviation of y.

to.data.frame

should the results be converted to a data.frame? Defaults to FALSE.

Value

When to.data.frame is TRUE, returns a data frame of scores on x and y. Otherwise, a list containing:

x

x when supplied, or the simulated vector of scores

y

the vector y sampled from a population correlating with x at rho

rho

the supplied correlation rho

r

the estimated correlation between x and y

meanx, sdx, meany, sdy

the means and standard deviations of x and y


talbano/epmr documentation built on May 1, 2024, 11:10 a.m.