Population: Manage a patient population
Population.RdThe Population class stores subject-level data and manages enrollment and
dropout times for each subject.
Use set_enrolled() and set_dropped() to assign enrollment and dropout
times to random subsets of subjects.
Public fields
namecharacterUnique identifier for the population.datadata.frameSubject-level data frame with columns:idintegerarmcharacterreadout_timenumericdatanumericmay contain more columns
enrollednumericVector of enrollment times for each subject.droppednumericVector of dropout times for each subject.nintegerNumber of unique subjects in the population.n_readoutsintegerNumber of readout_times in the population.
Methods
Method new()
Create a new Population instance.
Usage
Population$new(
name,
data = NULL,
enrolled = NULL,
dropped = NULL,
n = NULL,
n_readouts = NULL
)Arguments
namecharacterUnique identifier for the population.datadata.framewith columns:id,arm,readout_time,data, and optionally more columns.enrollednumericOptional enrollment times (auto-initialized ifNULL).droppednumericOptional dropout times (auto-initialized ifNULL).nintegerAuto-computed from data (optional).n_readoutsintegerAuto-computed from data (optional).
Examples
Population$new(name = "Intervention", data = vector_to_dataframe(rnorm(5)))Method set_enrolled()
Mark subjects as enrolled at a given time.
Enrollment applies only to unenrolled subjects (NA).
Examples
pop <- Population$new("Test", vector_to_dataframe(rnorm(10)))
pop$set_enrolled(n = 4, time = 2)Method set_dropped()
Mark subjects as dropped at a given time.
Dropout applies only to enrolled, not-yet-dropped subjects.
Examples
pop <- Population$new("Test", vector_to_dataframe(rnorm(10)))
pop$set_enrolled(n = 5, time = 1)
pop$set_dropped(n = 2, time = 3)Method set_data()
Replace underlying subject data and reset enrollment/dropout status.
Examples
pop <- Population$new("ResetDemo", vector_to_dataframe(rnorm(5)))
pop$set_data(
data.frame(
id = 1:8,
data = rnorm(8),
arm = "ResetDemo",
readout_time = 0
)
)Examples
# Basic example: vector input
pop <- Population$new(name = "Control", data = vector_to_dataframe(rnorm(10)))
pop$n # number of subjects
#> [1] 10
head(pop$data) # generated subject-level data
#> id data readout_time arm
#> 1 1 -1.400043517 0 Control
#> 2 2 0.255317055 0 Control
#> 3 3 -2.437263611 0 Control
#> 4 4 -0.005571287 0 Control
#> 5 5 0.621552721 0 Control
#> 6 6 1.148411606 0 Control
# Set enrollment for 5 subjects at time = 1
pop$set_enrolled(n = 5, time = 1)
# Drop 2 subjects at time = 3
pop$set_dropped(n = 2, time = 3)
# Reset underlying data
pop$set_data(vector_to_dataframe(rnorm(8)))
## ------------------------------------------------
## Method `Population$new`
## ------------------------------------------------
Population$new(name = "Intervention", data = vector_to_dataframe(rnorm(5)))
#> <Population>
#> Public:
#> clone: function (deep = FALSE)
#> data: data.frame
#> dropped: NA NA NA NA NA
#> enrolled: NA NA NA NA NA
#> initialize: function (name, data = NULL, enrolled = NULL, dropped = NULL,
#> n: 5
#> n_readouts: 1
#> name: Intervention
#> set_data: function (data)
#> set_dropped: function (n, time)
#> set_enrolled: function (n, time)
## ------------------------------------------------
## Method `Population$set_enrolled`
## ------------------------------------------------
pop <- Population$new("Test", vector_to_dataframe(rnorm(10)))
pop$set_enrolled(n = 4, time = 2)
## ------------------------------------------------
## Method `Population$set_dropped`
## ------------------------------------------------
pop <- Population$new("Test", vector_to_dataframe(rnorm(10)))
pop$set_enrolled(n = 5, time = 1)
pop$set_dropped(n = 2, time = 3)
## ------------------------------------------------
## Method `Population$set_data`
## ------------------------------------------------
pop <- Population$new("ResetDemo", vector_to_dataframe(rnorm(5)))
pop$set_data(
data.frame(
id = 1:8,
data = rnorm(8),
arm = "ResetDemo",
readout_time = 0
)
)