Skip to contents

This function simulates a baseline dataset of trial patients with demographic information and site/country assignments. Each patient is assigned to a site (nested within country) and given baseline characteristics such as age and sex.

Usage

simulate_patients(
  n,
  countries = 1,
  sites_per_country = 1,
  mean_age = 50,
  sd_age = 10,
  prop_female = 0.5
)

Arguments

n

Integer, number of patients to simulate.

countries

Integer, number of countries in the trial (default = 1).

sites_per_country

Integer, number of sites per country (default = 1). Total sites = countries * sites_per_country.

mean_age

Numeric, mean age of patients (default = 50).

sd_age

Numeric, standard deviation of age (default = 10).

prop_female

Numeric, proportion of patients who are female (default = 0.5).

Value

A data frame with n rows, each representing a patient. Columns include:

  • ID: Patient identifier (integer).

  • Country: Factor indicating country (e.g., "Country1", "Country2", ...).

  • Site: Factor indicating site (e.g., "Site1", "Site2", ...).

  • Age: Patient age (years).

  • Sex: Patient sex (factor with levels "Female","Male").

Details

The site assignments are distributed roughly equally among the sites. Age is drawn from a normal distribution and then bounded between 18 and 90. Sex is assigned according to the specified proportion of females. This function is typically the first step in the simulation workflow.

Examples

# Simulate 5 patients in 2 countries with 2 sites each
df <- simulate_patients(n = 5, countries = 2, sites_per_country = 2)
head(df)
#>   ID  Country  Site Age    Sex
#> 1  1 Country2 Site3  62 Female
#> 2  2 Country1 Site1  71 Female
#> 3  3 Country2 Site4  57 Female
#> 4  4 Country2 Site4  57   Male
#> 5  5 Country1 Site2  39 Female