Learn R Programming

campsis

Requirements

  • R package campsismod must be installed beforehand
  • Simulation engine must be installed too (rxode2 or mrgsolve)

Installation

Install the latest stable release using devtools:

devtools::install_github("Calvagone/campsis")

Basic example

Import the campsis package:

library(campsis)

Create your dataset:

ds <- Dataset(50) %>%
  add(Bolus(time=0, amount=1000, ii=12, addl=2)) %>%
  add(Observations(times=seq(0, 36, by=0.5)))

Load your own model or use a built-in model from the library:

model <- model_suite$pk$`2cpt_fo`

Simulate your results with your preferred simulation engine (rxode2 or mrgsolve):

results <- model %>% simulate(dataset=ds, dest="rxode2", seed=1)

Plot your results:

shadedPlot(results, "CONC")

Copy Link

Version

Install

install.packages('campsis')

Monthly Downloads

524

Version

1.7.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Nicolas Luyckx

Last Published

April 4th, 2025

Functions in campsis (1.7.0)

Bolus

Create one or several bolus(es).
Observations

Create an observations list. Please note that the provided 'times' will automatically be sorted. Duplicated times will be removed.
Occasion

Define a new occasion. Occasions are defined by mapping occasion values to dose numbers. A new column will automatically be created in the exported dataset.
Dataset

Create a dataset.
Bootstrap

Create a bootstrap object.
BinomialDistribution

Binomial distribution.
BootstrapDistribution

Create a bootstrap distribution. During function sampling, CAMPSIS will generate values depending on the given data and arguments.
Scenarios

Create a list of scenarios.
ConstantDistribution

Create a constant distribution. Its value will be constant across all generated samples.
DiscreteDistribution

Discrete distribution.
EventCovariate

Create an event covariate. These covariates can be modified further in interruption events.
Covariate

Create a non time-varying (fixed) covariate.
DatasetConfig

Create a dataset configuration. This configuration allows CAMPSIS to know which are the default depot and observed compartments.
EventIteration

Create an event iteration object.
Hardware

Create hardware settings.
Settings

Create advanced simulation settings.
DatasetSummary

Create a dataset summary (internal method).
IOV

Define inter-occasion variability (IOV) into the dataset. A new variable of name 'colname' will be output into the dataset and will vary at each dose number according to the given distribution.
EtaDistribution

Create an ETA distribution. The resulting distribution is a normal distribution, with mean=0 and sd=sqrt(OMEGA).
Event

Create an interruption event.
Declare

Create declare settings.
VPC

Compute the VPC summary. Input data frame must contain the following columns: - replicate: replicate number - low: low percentile value in replicate (and in scenario if present) - med: median value in replicate (and in scenario if present) - up: up percentile value in replicate (and in scenario if present) - any scenario column
CyclicSchedule

Cyclic schedule constructor.
FixedDistribution

Create a fixed distribution. Each sample will be assigned a fixed value coming from vector 'values'.
EventRelatedObservations

Create an event-related observations list. Please note that the provided 'times' will automatically be sorted. Duplicated times will be removed.
applyCompartmentCharacteristics

Apply compartment characteristics from model. In practice, only compartment infusion duration needs to be applied.
NOCB

Create NOCB settings.
Events

Create a list of interruption events.
RepeatAtSchedule

'Repeat at' schedule constructor. Note that the time 0 for the base pattern will be added by default if not provided.
cyclic_schedule-class

Cyclic schedule class.
NormalDistribution

Create a normal distribution.
Outfun

Create a new output function
PI

Compute the prediction interval summary over time.
DoseAdaptation

Create a dose adaptation.
dataset-class

Dataset class.
TimeVaryingCovariate

Create a time-varying covariate. This covariate will be implemented using EVID=2 rows in the exported dataset and will not use interruption events.
ParameterDistribution

Create a parameter distribution. The resulting distribution is a log-normal distribution, with meanlog=log(THETA) and sdlog=sqrt(OMEGA).
fixed_distribution-class

Fixed distribution class.
Infusion

Create one or several infusion(s).
LogNormalDistribution

Create a log normal distribution.
Scenario

Create an scenario.
Progress

Create progress settings.
applyScenario

Apply scenario to the given model or dataset.
arms-class

Arms class.
FunctionDistribution

Create a function distribution. During distribution sampling, the provided function will be responsible for generating values for each sample. If first argument of this function is not the size (n), please tell which argument corresponds to the size 'n' (e.g. list(size="n")).
bootstrap-class

Bootstrap class.
UniformDistribution

Create an uniform distribution.
SimulationProgress

Create a simulation progress object.
bootstrap_distribution-class

Bootstrap distribution class.
arm-class

Arm class.
counterBalanceNocbMode

Counter-balance NOCB mode for occasions & IOV. This function will simply shift all the related occasion & IOV columns to the right (by one).
function_distribution-class

Function distribution class.
assignDoseNumber

Assign dose number to each treatment entry.
getRandomSeedValue

Get random seed value.
Solver

Create solver settings.
convertTime

Convert numeric time vector based on the provided units.
counterBalanceLocfMode

Counter-balance LOCF mode for occasions & IOV. This function will simply shift all the related occasion & IOV columns to the left (by one).
campsis_handler

Suggested Campsis handler for showing the progress bar.
declare_settings-class

Declare settings class.
bolus-class

Bolus class.
getSeed

Get seed value.
getSeedForParametersSampling

Get seed for parameter uncertainty sampling.
distribution-class

Distribution class. See this class as an interface.
covariates-class

Covariates class.
covariate-class

Covariate class.
cutTableForEvent

Cut table according to given iteration.
dosingOnly

Filter CAMPSIS output on dosing rows.
bolus_wrapper-class

Bolus wrapper class.
getSimulationEngineType

Get simulation engine type.
exportTableDelegate

Export table delegate.
factorScenarios

Factor scenarios columns if not done yet.
checkIIandADDL

Check ii and addl arguments in addition to time.
dropOthers

Return the 'DROP_OTHERS' string that may be used in the 'outvars' vector for RxODE/mrgsolve to drop all others variables that are usually output in the resulting data frame.
dataset_config-class

Dataset configuration class.
computeIncrementalProgress

Compute incremental progress.
constant_distribution-class

Constant distribution class.
getFurrrScheduling

Get scheduling mode for furrr (see argument 'scheduling' available in furrr options).
dose_adaptation-class

Dose adaptation class.
getIOVs

Get all IOV objects.
infusion_wrapper-class

Infusion wrapper class.
dose_adaptations-class

Dose adaptations class.
events-class

Events class.
importCampsismodToNamespace

Import the whole campsismod package into NAMESPACE when parsed by 'roxygen'.
getAvailableTimeUnits

Return the list of available time units.
internal_settings-class

Internal settings class (transient object from the simulation settings).
exportDelegate

Export delegate method. This method is common to RxODE and mrgsolve.
getColumn

Get data of given column unless if does not exist (return NULL in that case).
infusion-class

Infusion class.
nhanes

NHANES database (demographics and body measure data combined, from 2017-2018).
generateIIV

Generate IIV matrix for the given Campsis model.
nocb_settings-class

NOCB settings class.
months

Convert pharma months (1 month = 4 weeks) to hours.
days

Convert days to hours.
preprocessIds

Preprocess subjects ID's.
getEventIterations

Get list of event iterations.
getFixedCovariates

Get all fixed covariates.
preprocessNocbvars

Preprocess 'nocbvars' argument.
preprocessSettings

Preprocess the simulation settings.
generateIIV_

Generate IIV matrix for the given OMEGA matrix.
getSplittingConfiguration

Get splitting configuration for parallel export.
event-class

Event class.
event_covariate-class

Event covariate class.
fillIOVOccColumns

Fill IOV/Occasion columns.
preprocessSlices

Preprocess 'slices' argument.
fixed_covariate-class

Fixed covariate class.
getTimeVaryingCovariates

Get all time-varying covariates.
getSeedForDatasetExport

Get seed for dataset export.
sampleTimeVaryingCovariates

Sample time-varying covariates.
length,arm-method

Return the number of subjects contained in this arm.
getCompartmentMapping

Get a mapping table with all possibilities of compartment names and their indexes knowing that compartment names can be provided as character or as integer.
length,cyclic_schedule-method

Return the number of repetition cycles.
getSeedForIteration

Get seed for iteration.
getCovariates

Get all covariates (fixed / time-varying / event covariates).
observations_set-class

Observations set class.
mrgsolve_engine-class

mrgsolve engine class.
getTimeVaryingVariables

Get all time-varying variables. These variables are likely to be influenced by the NOCB mode chosen and by the 'nocbvars' vector.
scatterPlot

Scatter plot (or X vs Y plot).
onCran

Check if the current session is on CRAN. The objective is to potentially suppress long tasks to be run on CRAN (long tests or vignettes).
occasion-class

Occasion class.
getDatasetMaxTime

Get dataset max time.
preprocessArmColumn

Preprocess ARM column. Add ARM equation in model automatically.
mergeTimeVaryingCovariates

Merge time-varying covariates into a single data frame. This last data frame will be merged afterwards with all treatment and observation rows.
simulateScenarios

Simulation scenarios.
preprocessDest

Pre-process destination engine. Throw an error message if the destination engine is not installed.
preprocessReplicates

Preprocess 'replicates' argument.
preprocessScenarios

Pre-process scenarios.
simulation_engine-class

Simulation engine class.
getTimes

Get all distinct times for the specified object.
repeatSchedule

Repeat schedule.
getEventCovariates

Get all event-related covariates.
minutes

Convert minutes to hours.
output_function-class

Output function class.
updateADDL

Update the number of additional doses (ADDL).
obsOnly

Filter CAMPSIS output on observation rows.
preprocessTSLDAndTDOSColumn

Preprocess TSLD and TDOS columns according to given dataset configuration.
observations-class

Observations class.
updateAmount

Update amount.
length,dataset-method

Return the number of subjects contained in this dataset.
repeat_at_schedule-class

'Repeat at' schedule class.
preprocessDosing

Preprocess 'dosing' argument.
preprocessEvents

Pre-process events.
length,repeat_at_schedule-method

Return the number of repetition cycles.
getInitialConditions

Get initial conditions at simulation start-up.
setSeed

Set the seed. The goal of this method is to centralize all calls to the R method 'set.seed'.
processAllTimeColumns

Process time-related columns according to given dataset configuration.
processArmLabels

Process arm labels. Arm identifiers in ARM column are replaced by arm labels as soon as one arm label is provided.
setSubjects

Set the number of subjects.
rxode_engine-class

RxODE/rxode2 engine class.
sample

Sample generic object.
preprocessTablefun

Pre-process tablefun argument.
progress_settings-class

Progress settings class.
protocol-class

Protocol class.
getOccasions

Get all occasions.
simulation_progress-class

Simulation progress class.
scenario-class

Scenario class.
occasions-class

Occasions class.
scenarios-class

Scenarios class.
hardware_settings-class

Hardware settings class.
onCI

Check if the current session is on CI (e.g. GitHub actions).
simulation_settings-class

Simulation settings class.
toExplicitDistribution

Convert user-given distribution to an explicit CAMPSIS distribution. Passed distribution can be: - a NULL value. In that case, it will be converted into an 'UndefinedDistribution'. - a single numeric value. In that case, it will be converted into a 'ConstantDistribution'. - a numeric vector. In that case, it will be converted into a 'FixedDistribution'. - all available types of distribution. In this case, no conversion is applied.
setupPlanDefault

Setup default plan for the given simulation or hardware settings. This plan will prioritise the distribution of workers in the following order: 1) Replicates (if 'replicate_parallel' is enabled) 2) Scenarios (if 'scenario_parallel' is enabled) 3) Dataset export / slices (if 'dataset_export' or 'slice_parallel' is enabled)
setupPlanSequential

Setup plan as sequential (i.e. no parallelisation).
preprocessOutfun

Pre-process outfun argument.
hours

Convert hours to hours (do nothing).
treatment-class

Treatment class.
treatment_iov-class

Treatment IOV class.
treatment_iovs-class

Treatment IOV's class.
isEmptyBootstrap

Is the given bootstrap empty.
preprocessOutvars

Preprocess 'outvars' argument. 'Outvars' is a character vector which tells CAMPSIS the mandatory columns to keep in the output dataframe.
splitDataset

Split dataset according to config.
standardiseTime

Standardise time to hours.
updateII

Update the inter-dose interval (II).
undefined_distribution-class

Undefined distribution class. This type of object is automatically created in method toExplicitDistribution() when the user does not provide a concrete distribution. This is because S4 objects do not accept NULL values.
leftJoinIIV

Left-join IIV matrix.
removeInitialConditions

Remove initial conditions.
undefined_schedule-class

Undefined schedule class.
reorderColumns

Reorder output columns.
updateRepeat

Update the repeat field (argument 'rep' in Bolus and Infusion constructors).
seconds

Convert seconds to hours.
processDropOthers

Process 'DROP_OTHERS'.
setLabel

Set the label.
processSimulateArguments

Preprocess arguments of the simulate method.
uniteColumns

Unite the given column names.
unwrapTreatment

Unwrap treatment.
simulateDelegate

Simulation delegate (several replicates).
repeated_schedule-class

Repeated schedule class. See this class as an interface.
retrieveParameterValue

Retrieve the parameter value (standardized) for the specified parameter name.
sampleCovariatesList

Sample covariates list.
sampleDistributionAsTibble

Sample a distribution and return a tibble.
shadedPlot

Shaded plot (or prediction interval plot).
simulate

Simulate function.
simulateDelegateCore

Simulation delegate core (single replicate).
time_varying_covariate-class

Time-varying covariate class.
solver_settings-class

Solver settings class. See ?mrgsolve::update. See ?rxode2::rxSolve.
toDatasetSummary

Convert dataset to dataset summary (internal method).
vpcPlot

VPC plot.
spaghettiPlot

Spaghetti plot.
years

Convert pharma years (1 year = 12*4 weeks) to hours.
weeks

Convert weeks to hours.
Arm

Create a treatment arm.