sim_2arm_prepost: Simulate Pretest-Postest data

View source: R/SimTools.R

sim_2arm_prepostR Documentation

Simulate Pretest-Postest data

Description

Generates simulated data for use in study sample size planning for a 2 arm, pretest/posttest design.

Usage

sim_2arm_prepost(
  Npg = 5,
  VNames = c("x", "y"),
  R = matrix(data = c(1, 0.5, 0.5, 1), nrow = 2, ncol = 2, byrow = TRUE),
  MV.C = c(x = 0, y = 0),
  MV.T = c(x = 0, y = 1),
  SV.C = c(x = 1, y = 1),
  SV.T = c(x = 1, y = 1)
)

Arguments

Npg

An integer value for the number of subjects per group.

VNames

A character vector with the names of the variables, in the order they will be used in the population matrix row and column names. These will be used as dimnames. It defaults to the list of two variable names (x and y), where x is the pretest data and y is the posttest data.

R

A population correlation matrix. This will be used by mvtnorm::rmvnorm(). The default value is arbitrary.

MV.C

A numeric vector of means for the control group. This must be the same length as VNames and in the same order. This will be used by mvtnorm::rmvnorm(). It defaults to means on 1.

MV.T

A numeric vector of means for the treatment group. This must be the same length as VNames and in the same order. This will be used by mvtnorm::rmvnorm().

SV.C

A numeric vector of standard deviations for the control group. This must be the same length as VNames and in the same order. This will be used by mvtnorm::rmvnorm().

SV.T

A numeric vector of standard deviations for the control group. This must be the same length as VNames and in the same order. This will be used by mvtnorm::rmvnorm().

Details

=============================================================================

This function generates simulated data for use in study sample size planning, based on the supplied inputs. It is strictly designed to work with a two-group, pretest/posttest design where the planned analysis would be a a simple ANCOVA model. The simulation creates separate data frames for the control and treatment groups that each contain pretest data (x) and posttest data (y). The two groups always have equal sample sizes.

PID is a person level identifier, and Arm indicates whether the person belongs to the control or treatment group.

Value

A tibble or a data frame.

Examples

# Load packages.
library(dplyr)
library(mvtnorm)
library(MBESS)
# Default settings.
set.seed(1528)
sim_2arm_prepost()


sjpierce/piercer documentation built on Dec. 30, 2024, 3:28 p.m.