| generator {stats4teaching} | R Documentation |
Generation of multivariate normal data.
Description
This function generates univariate and multivariate normal data. It allows simulating correlated and independent samples. Moreover, normality tests and numeric informations are provided.
Usage
generator(n , mean = 0, sigma = 1, coefvar = NULL,
sigmaSup = NULL, dec = 2)
Arguments
n |
vector size of samples. |
mean |
vector of means. |
sigma |
vector of standard deviations or covariance/correlation matrix. |
coefvar |
an optional vector of coefficients of variation. |
sigmaSup |
an optional vector of standard deviations if sigma is a correlation matrix. |
dec |
number of decimals for observations. |
Details
If mean or sigma are not specified it's assumed the default values of 0 and 1.
If coefvar (= sigma/mean) is specified, function omits sigma and sigmaSup. It's assumed that independent samples are desired.
Number of samples are choosen by taken the longest parameter (n, mean, sigma, coefvar). Therefore, function rep is used. Pay attention if vectors don't have same length!
If sigma is a vector, samples are independent. In other case (sigma is a matrix), samples are dependent (following information meanst be taken into account: if sigma is a correlation matrix, sigmaSup is required).
Value
List containing the following components for independent (with the same length) and dependent samples:
-
Samples: a data frame containing the samples created. Test normality test for the data (
shapiro.test()for n <= 50 andlillie.test()in other case).
List containing the following components for independent samples with different lengths:
-
X_isample number i.
Examples
generator(4,0,2)
sigma <- matrix(c(1,0.8,0.8,1),nrow = 2, byrow = 2)
d <- generator(4,mean = c(1,2),sigma, sigmaSup = 1)
generator(10,1,coefvar = c(0.3,0.5))
generator(c(10,11,10),c(1,2),coefvar = c(0.3,0.5))