Last data update: 2014.03.03

R: Simulate multivariate data for testing
simdataR Documentation

Simulate multivariate data for testing

Description

Creates multivariate normal or normal and binary data, as used in the simulation study.

Usage

simdata(n = 2000, mymean = rep(0, 4), mysigma = matrix(
	c( 1,   0.2, 0.1, -0.7,
	   0.2, 1,   0.3,  0.1,
	   0.1, 0.3, 1,    0.2,
	  -0.7, 0.1, 0.2,  1), byrow = TRUE, nrow = 4, ncol = 4),
	residsd = 1, x2binary = FALSE)

Arguments

n

number of observations to create.

mymean

vector of length 4, giving the mean of each variable.

mysigma

variance-covariance matrix of multivariate normal distribution from which x1-x4 are to be drawn.

residsd

residual standard deviation.

x2binary

if TRUE, x2 is converted to a binary factor variable (1, 2) with probability equal to the logistic of the underlying normally distributed variable.

Value

Data frame with 5 columns:

y

continuous, generated by y = x1 + x2 + x3 + normal error if x2 is continuous, or y = x1 + x2 + x3 - 1 + normal error if x2 is a factor with values 1 or 2

x1

continuous

x2

continuous or binary (factor) with value 1 or 2

x3

continuous

x4

continuous

See Also

makemar

Examples

set.seed(1)
simdata(n=4, x2binary=TRUE)
#             y          x1 x2         x3        x4
# 1 -0.06399616 -1.23307320  2 -0.6521442 1.6141842
# 2  1.00822173 -0.05167026  1  0.4659907 0.5421826
# 3  2.87886825  0.43816687  1  1.5217240 0.2808691
# 4  0.79129101 -0.72510640  1  0.7342611 0.1820001

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(CALIBERrfimpute)
Loading required package: mice
Loading required package: Rcpp
mice 2.25 2015-11-09
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/CALIBERrfimpute/simdata.Rd_%03d_medium.png", width=480, height=480)
> ### Name: simdata
> ### Title: Simulate multivariate data for testing
> ### Aliases: simdata
> 
> ### ** Examples
> 
> set.seed(1)
> simdata(n=4, x2binary=TRUE)
            y          x1 x2         x3        x4
1 -0.06399616 -1.23307320  2 -0.6521442 1.6141842
2  1.00822173 -0.05167026  1  0.4659907 0.5421826
3  2.87886825  0.43816687  1  1.5217240 0.2808691
4  0.79129101 -0.72510640  1  0.7342611 0.1820001
> #             y          x1 x2         x3        x4
> # 1 -0.06399616 -1.23307320  2 -0.6521442 1.6141842
> # 2  1.00822173 -0.05167026  1  0.4659907 0.5421826
> # 3  2.87886825  0.43816687  1  1.5217240 0.2808691
> # 4  0.79129101 -0.72510640  1  0.7342611 0.1820001
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>