Learn R Programming

simBKMRdata (version 0.1.1)

simulate_group_gaussian: Simulate Group Multivariate Gaussian Data

Description

This function generates data for each group from a Multivariate Gaussian (Normal) Distribution by invoking this distribution's random generator once per group. It binds the generated data together into a single data frame.

Usage

simulate_group_gaussian(param_list, group_col_name)

Value

A data frame with the simulated data for all groups, including the grouping column.

Arguments

param_list

A list of named sublists, where each sublist contains the parameters for a group (sample size, mean, standard deviation, and correlation matrix). The dimension of the parameters for each group must be the same.

group_col_name

The column name of the grouping/label column to be created in the final data frame. The values are taken from the names of the sublists of param_list. Defaults to "group". See the example below.

Examples

Run this code
# Example using MASS::mvrnorm for normal distribution
param_list <- list(
  Male = list(
    sampSize = 50,
    mean_vec = c(1, 2),
    sampSD = c(2, 1),
    sampCorr_mat = matrix(c(1, 0.5, 0.5, 1), 2, 2)
  ),
  Female = list(
    sampSize = 100,
    mean_vec = c(2, 3),
    sampSD = c(1, 2),
    sampCorr_mat = matrix(c(1, 0.3, 0.3, 1), 2, 2)
  )
)
simulate_group_gaussian(param_list, "Sex")

Run the code above in your browser using DataLab