genmvnorm: Genmvnorm

View source: R/genmvnorm.R

genmvnormR Documentation

Genmvnorm

Description

Generates a multivariate normal dataset based on a specified correlation matrix.

Usage

genmvnorm(cor, k, n, seed = FALSE)

Arguments

cor

Can be a correlation matrix– e.g., data<-cor(xyz)– or the lower half of a correlation matrix, e.g., for a 3 variable dataset, data<-c(.7,.3,.2)– useful for creating datasets without having to specify both halves of the correlation matrix.

k

Indicate the number of variables in your dataset.

n

Indicate the number of observations in your new synthetic dataset.

seed

For reproducability of results, set a specific seed number.

Details

For creating synthetic datasets. Based on the SAS chapter by Fan et al. (2002).

Author(s)

Francis Huang

References

Based on:

Fan, X., Felsovalyi, A., Sivo, S., & Keenan, S. (2002). SAS for Monte Carlo studies: A guide for quantitative researchers. SAS Institute.

See Also

revcode dtrans recalib

Examples

sdata<-genmvnorm(cor=c(.7,.2,.3),k=3,n=500,seed=12345)
cor(sdata)
#dataset above uses the lower half of a correlation table
#     1  .7  .2
#     .7  1  .3
#     .2 .3   1
# Can also use a correlation table

data(iris)
dat<-cor(iris[,1:3])
dat
sdata<-genmvnorm(cor=dat,k=3,n=100,seed=123)
cor(sdata)

#example above uses the IRIS dataset.

gendata documentation built on May 10, 2022, 1:05 a.m.