mrnorm {NCStats}R Documentation

Multiple Simulations from Normal Distributions

Description

Random generation from multiple normal distributions with potentially different means and standard deviations.

Usage

mrnorm(n, mean, sd, exact = TRUE, grp.labels = LETTERS[1:length(n)],
  var.labels = c("measure", "group"), digits = NULL)

Arguments

n

vector of number of observations.

mean

vector of means.

sd

vector of standard deviations.

exact

a logical that indicates whether the resulting vector of random numbers will have the exact mean and standard deviation supplied in mean and sd.

grp.labels

Labels for the levels representing the different groups.

var.labels

Labels for or names for the columns of the resulting data.frame.

digits

A number of digits to which the numeric data should be rounded.

Details

All of n, mean, sd, and grp.labels must be of the same length.

If digits is non-null and exact=TRUE the resulting quantitative data will only be approximately exact (due to the rounding).

Value

A data.frame with two columns is returned. The first columns is the random normal deviates and the second column are the group levels.

Note

This function can be used to generate “realistic” data when one knows the sample size, mean, and standard deviation for several groups and it can be assumed that the data in each group follows a normal distribution. Thus, this function can be used to generate “actual” data for, for example, one-way and two-way ANOVA from summaries of group sample sizes, means, and standard deviations. Note that standard deviations can often be estimated by “back-calculating” from given standard errors or confidence intervals.

See Also

rnorm.

Examples

# using default names
rand.data <- mrnorm(n=c(10,15,20),mean=c(10,15,15),sd=c(3,4,5))
# using custom names
rand.data1 <- mrnorm(n=c(10,15),mean=c(10,15),sd=c(3,4),
  grp.labels=c("First","Second"),var.labels=c("Y","X"))

if (require(FSA)) { 
Summarize(measure~group,data=rand.data)
Summarize(Y~X,data=rand.data1)
}


[Package NCStats version 0.4.7 Index]