Creating synthetic clinical tables"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The omock package provides functionality to quickly create a cdm reference containing synthetic data based on population settings specified by the user.

First, let's load packages required for this vignette.

library(omock)
library(dplyr)
library(ggplot2)

Now, in three lines of code, we can create a cdm reference with a person and observation period table for 1000 people.

cdm <- emptyCdmReference(cdmName = "synthetic cdm") |>
  mockPerson(nPerson = 1000) |>
  mockObservationPeriod()

cdm

cdm$person |> glimpse()

cdm$observation_period |> glimpse()

We can add further requirements around the population we create. For example we can require that they were born between 1960 and 1980 like so.

cdm <- emptyCdmReference(cdmName = "synthetic cdm") |>
  mockPerson(
    nPerson = 1000,
    birthRange = as.Date(c("1960-01-01", "1980-12-31"))
  ) |>
  mockObservationPeriod()
cdm$person |>
  collect() |>
  ggplot() +
  geom_histogram(aes(as.integer(year_of_birth)),
    binwidth = 1, colour = "grey"
  ) +
  theme_minimal() +
  xlab("Year of birth")


Try the omock package in your browser

Any scripts or data that you put into this service are public.

omock documentation built on Nov. 5, 2025, 6:31 p.m.