| Title: | Reconstruct Patient-Level Subgroup Membership in Survival Data |
|---|---|
| Description: | Patient-level survival outcomes for a whole clinical trial are frequently available alongside published subgroup hazard ratios, while the subgroup membership of each patient is not. 'retrogroup' reconstructs subgroup membership from these two sources of information. A Bayesian survival model estimates the posterior probability that each patient belongs to each subgroup level, and a sampling method uses these probabilities to impute a subgroup level for each patient. |
| Authors: | William Michael Landau [aut, cre] (ORCID: <https://orcid.org/0000-0003-1878-3253>), Eli Lilly and Company [cph, fnd] |
| Maintainer: | William Michael Landau <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.3 |
| Built: | 2026-12-04 09:19:26 UTC |
| Source: | https://github.com/wlandau/retrogroup |
Estimate the posterior probability that each patient belongs to each level of each subgroup variable, given the patient-level survival data and the assumed subgroup statistics.
group_analysis_probability(patient, summary)group_analysis_probability(patient, summary)
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
group_analysis_probability() computes the estimated posterior
probabilities defined in the "Posterior probability
estimation" section of vignette("model", package = "retrogroup"),
separately for each subgroup variable. See that section for the
formulas, including the error when any probability is numerically
indistinguishable from zero.
The probabilities depend on the estimated prognostic effects
and the estimated baseline cumulative hazard
of
vignette("estimates", package = "retrogroup"). The prognostic
effects come from the event counts, the patient counts, and the
hazard ratios in summary, after clamping each event count to between
1/2 and . The baseline cumulative hazard is a modified
Breslow estimate that uses the prognostic effects.
The total number of patients of every subgroup variable in
summary must equal the number of rows of patient, and the total
number of events of every subgroup variable must equal the number of
events in patient. See the details of group_data_summary() for how
to choose the counts.
A named list with one element per subgroup variable, in the
order the subgroup variables first appear in summary$variable.
Each element is a numeric matrix of the estimated posterior
probabilities of that subgroup variable:
Rows correspond to patients, in the same order as the rows of
patient.
Columns correspond to the levels of the subgroup variable. The
column names are exactly the levels, in the same order as in
summary.
Each row sums to 1.
Other analysis:
group_analysis_summary()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) probability <- group_analysis_probability(patient, summary) names(probability) head(probability$age)patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) probability <- group_analysis_probability(patient, summary) names(probability) head(probability$age)
Compute the number of patients, the number of events, and the hazard ratio of treatment versus control in each level of each subgroup variable of a patient-level dataset.
group_analysis_summary( patient, variables = setdiff(colnames(patient), c("treatment", "time", "event")) )group_analysis_summary( patient, variables = setdiff(colnames(patient), c("treatment", "time", "event")) )
patient |
Patient-level survival data with subgroup columns,
usually the output of |
variables |
Character vector of unique names of subgroup columns
in |
For each level of each subgroup variable,
group_analysis_summary() counts the patients and events in that
level. These are the quantities and of
vignette("framing", package = "retrogroup"), computed from the
subgroup assignments in patient instead of assumed.
group_analysis_summary() also fits a Cox proportional hazards model
by partial likelihood to the patients in each level, with treatment as
the only covariate and the Efron method for ties. The fit uses a
compiled Newton solver specialized to one binary covariate, and its
estimate agrees with survival::coxph(ties = "efron") up to rounding
error whenever the partial likelihood has a finite maximum. The hazard ratio is the exponential of the
estimated coefficient of treatment versus control, the estimate of
of vignette("framing", package = "retrogroup").
The log hazard ratio is the observed statistic of
the "Loss function" section of
vignette("optimization", package = "retrogroup").
If the partial likelihood of some subgroup level has no finite
maximum, for example because one of its arms has no patients or no
events, the hazard_ratio of that level is NA.
In those cases, survival::coxph() instead stops at a large finite
estimate with a warning.
The levels of a factor subgroup column are its factor levels, in order, excluding levels with no patients. The levels of a character subgroup column are its sorted unique values.
A tibble with one row per subgroup level, ordered by subgroup
variable as in variables and then by level, and the following
columns:
variable: character, name of the subgroup variable.
level: character, level of the subgroup variable.
patients: integer, number of patients in the subgroup level.
events: integer, number of events in the subgroup level.
hazard_ratio: numeric, estimated hazard ratio of treatment
versus control in the subgroup level, or NA if the model cannot
be fit.
Other analysis:
group_analysis_probability()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_constrained(patient, summary) group_analysis_summary(sample) summarypatient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_constrained(patient, summary) group_analysis_summary(sample) summary
Approximate the number of events in each subgroup level from the confidence intervals of the hazard ratios, for publications that do not report subgroup event counts.
group_data_events(patient, summary, lower, upper, confidence = 0.95)group_data_events(patient, summary, lower, upper, confidence = 0.95)
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
lower |
Numeric vector with one element per row of |
upper |
Numeric vector with one element per row of |
confidence |
Number strictly between 0 and 1, the confidence level
|
group_data_events() implements
vignette("events", package = "retrogroup"), separately for each
subgroup variable. It assumes the confidence interval of each hazard
ratio is a Wald interval computed on the log scale, so the interval
of the log hazard ratio is symmetric about
with half-width . Equating
with the variance approximation of Schoenfeld (1983),
as in Parmar et al. (1998), the approximate number of events in
subgroup level is
where is lower, is upper, is the
quantile of the standard normal distribution for
confidence , and is the proportion
of patients in patient randomized to treatment. Using
for every level assumes the treatment allocation within each level
matches the overall allocation, which randomization supports.
The approximation does not use the hazard ratios in summary.
The approximate counts do not necessarily add up to the total number
of events in patient, and they may exceed the number of patients
of the level. So group_data_events() rounds each
to the nearest integer and clamps it to between 0
and . Then it makes passes over the levels in the order of
summary, adding 1 to (or subtracting 1 from) each level that has
room, until the counts of each subgroup variable add up to the total
number of events in patient. The result satisfies all the
requirements on event counts of group_data_summary().
This is only one of many possible ways to choose event counts. The choice is a decision about the reconstruction, and it is your responsibility. Please disclose the event counts used and how they were chosen wherever the reconstructed data or downstream results are reported.
summary must satisfy the requirements of
group_analysis_probability(), except that its event counts are
ignored. Usually summary is the output of group_data_summary()
with events = NULL.
A tibble with the same rows and columns as the output of
group_data_summary(), in the same order as summary. The events
column has the reconciled event counts. All other columns are the
same as in summary.
Parmar MKB, Torri V, Stewart L (1998). Extracting summary statistics to perform meta-analyses of the published literature for survival endpoints. Statistics in Medicine, 17(24), 2815-2834. doi:10.1002/(SICI)1097-0258(19981230)17:24<2815::AID-SIM110>3.0.CO;2-8
Schoenfeld DA (1983). Sample-size formula for the proportional-hazards regression model. Biometrics, 39(2), 499-503. doi:10.2307/2531021
Other data:
group_data_patient(),
group_data_summary()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) data <- group_example_summary() summary <- group_data_summary( data, variable = "variable", level = "level", patients = "patients", events = NULL, hazard_ratio = "hazard_ratio" ) summary group_data_events( patient, summary, lower = data$lower, upper = data$upper ) data[, c("variable", "level", "events")]patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) data <- group_example_summary() summary <- group_data_summary( data, variable = "variable", level = "level", patients = "patients", events = NULL, hazard_ratio = "hazard_ratio" ) summary group_data_events( patient, summary, lower = data$lower, upper = data$upper ) data[, c("variable", "level", "events")]
Convert a patient-level right-censored survival dataset
from a randomized 2-arm trial into the standardized format
used by retrogroup.
group_data_patient(data, arm, treatment, time, event)group_data_patient(data, arm, treatment, time, event)
data |
Data frame with one row per patient. Must have the columns
named by |
arm |
Character string, name of the column in |
treatment |
The value of |
time |
Character string, name of the column in |
event |
Character string, name of the column in |
A tibble with one row per patient and the following columns:
treatment: integer, 1 for the treatment arm and 0 for the
control arm.
time: numeric, time since randomization of the event or censoring.
event: integer, 1 if the event occurred and 0 if censored.
Other data:
group_data_events(),
group_data_summary()
data <- group_example_patient() group_data_patient( data, arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" )data <- group_example_patient() group_data_patient( data, arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" )
Convert assumed subgroup statistics into the
standardized format used by retrogroup.
group_data_summary(data, variable, level, patients, events, hazard_ratio)group_data_summary(data, variable, level, patients, events, hazard_ratio)
data |
Data frame with one row per subgroup level. Must have the columns named by the other arguments. Other columns are ignored. |
variable |
Character string, name of the column in |
level |
Character string, name of the column in |
patients |
Character string, name of the column in |
events |
Character string, name of the column in |
hazard_ratio |
Character string, name of the column in |
Each row of data is one level of a subgroup variable, with
the number of patients , the number of events , and
the hazard ratio of treatment versus control
defined in vignette("framing", package = "retrogroup").
A subgroup variable must have at least two levels, the levels must be
unique within the subgroup variable, and every level must have a
strictly positive number of patients.
The patient counts must have the same total for every subgroup variable, because every subgroup variable partitions the same patients. The counts are the sizes of the levels of the reconstructed subgroup variables, so they need not copy the publication verbatim. Published counts are the natural starting point, but they sometimes do not add up to the total number of patients in the study, for example because of missing subgroup data or typographical errors. In that case, choosing counts that add up to the total number of patients is a decision about the reconstruction, not an attempt to recover the true counts from the clinical study. Please disclose that decision transparently wherever the reconstructed data or downstream results are reported.
Likewise, the event counts must have the same total for every
subgroup variable, and each level must satisfy
. retrogroup uses the event counts to
estimate prognostic effects, as in
vignette("estimates", package = "retrogroup"). See the "Event
counts" section of vignette("framing", package = "retrogroup") for
how to choose event counts, and group_data_events() for
approximating them from confidence intervals when the publication
does not report them.
For that purpose, events = NULL skips the checks on event counts
and sets every events value to NA. Such a summary is only valid
input to group_data_events(). Every other function rejects it.
A tibble with one row per subgroup level, in the same order as
data, and the following columns:
variable: character, name of the subgroup variable.
level: character, level of the subgroup variable.
patients: integer, number of patients in the subgroup
level.
events: integer, number of events in the subgroup level,
or NA if events is NULL.
hazard_ratio: numeric, assumed hazard ratio
of treatment versus control in the subgroup
level.
Other data:
group_data_events(),
group_data_patient()
group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" )group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" )
Return example patient-level data in the format expected
by group_data_patient().
group_example_patient()group_example_patient()
The data come from the adjuvant colon cancer trial of
levamisole plus fluorouracil (Moertel et al., 1990), as distributed in
survival::colon. The subset keeps the death endpoint (etype == 2)
and two arms: observation ("Obs", control) and levamisole plus
fluorouracil ("Lev+5FU", treatment). The levamisole-only arm is
excluded. See survival::colon for the full dataset and its
documentation.
A tibble with one row per patient and the following columns:
arm: character, study arm, either "Obs" or "Lev+5FU".
time: numeric, days from randomization to death or censoring.
event: integer, 1 if the patient died and 0 if censored.
Moertel CG, Fleming TR, Macdonald JS, et al. (1990). Levamisole and fluorouracil for adjuvant therapy of resected colon carcinoma. New England Journal of Medicine, 322(6), 352-358.
Other example:
group_example_summary()
group_example_patient()group_example_patient()
Return example summary subgroup statistics in the format
expected by group_data_summary().
group_example_summary()group_example_summary()
The statistics are computed from the same patients as
group_example_patient(): the death endpoint (etype == 2) of the
adjuvant colon cancer trial of levamisole plus fluorouracil
(Moertel et al., 1990), as distributed in survival::colon,
restricted to the observation ("Obs", control) and levamisole plus
fluorouracil ("Lev+5FU", treatment) arms.
There are three subgroup variables:
"age": age at randomization, with levels "under 60"
(younger than 60 years) and "60 or over" (60 years or older).
"node4": more than 4 positive lymph nodes, with levels
"no" and "yes".
"sex": with levels "female" and "male".
Within each subgroup level, group_analysis_summary() counts the
patients and events and fits a Cox proportional hazards model of
survival on treatment ("Lev+5FU" versus "Obs") to get the hazard
ratio. The columns lower and upper are the bounds of the 95%
Wald confidence interval of the hazard ratio from the same model, as
a publication would report them. group_data_summary() ignores
these columns, but group_data_events() can use them to approximate
the event counts.
A tibble with one row per subgroup level and the following columns:
variable: character, name of the subgroup variable.
level: character, level of the subgroup variable.
patients: integer, number of patients in the subgroup level.
events: integer, number of events in the subgroup level.
hazard_ratio: numeric, estimated hazard ratio of treatment
versus control in the subgroup level.
lower: numeric, lower bound of the 95% confidence interval of the
hazard ratio.
upper: numeric, upper bound of the 95% confidence interval of the
hazard ratio.
Moertel CG, Fleming TR, Macdonald JS, et al. (1990). Levamisole and fluorouracil for adjuvant therapy of resected colon carcinoma. New England Journal of Medicine, 322(6), 352-358.
Other example:
group_example_patient()
group_example_summary()group_example_summary()
Refine sampled subgroup levels so that the subgroup
statistics observed in the data match the assumed subgroup
statistics in summary, while preserving the assumed number of
patients in each subgroup level.
group_optimize_constrained( patient, summary, iterations = 10000L, tolerance = 0.001 )group_optimize_constrained( patient, summary, iterations = 10000L, tolerance = 0.001 )
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
iterations |
Non-negative integer, the maximum number of iterations for each subgroup variable. Each iteration draws one pair of patients and fits two Cox models. |
tolerance |
Non-negative number on the linear (natural) scale of
the hazard ratio, not the log scale. The search for each subgroup
variable stops when the loss |
group_optimize_constrained() implements the
"Optimization for constrained sampling" section of
vignette("optimization", package = "retrogroup"), separately for each
subgroup variable. The loss is the same as in
group_optimize_unconstrained(): the Euclidean distance between the
observed and assumed hazard ratios. The observed hazard ratios come
from a Cox proportional hazards model of each
subgroup level with treatment as the only covariate, as in
survival::coxph(). If the model cannot be fit for some subgroup
level, for example because one of its arms has no events, the loss is
infinite.
Each iteration takes a swap step, as defined in the "Moves" section of
the vignette. A swap step draws a pair of patients
uniformly at random from the pairs with and
exchanges their subgroup levels if the exchange reduces the loss.
Otherwise, the subgroup levels stay the same, so the loss never
increases. If no such pair exists,
no swap is possible and the subgroup levels are returned unchanged.
The search for each subgroup variable stops when the loss falls below
tolerance or after iterations iterations,
whichever comes first. If the loss of any subgroup variable is still
at least tolerance after iterations iterations,
group_optimize_constrained() throws a warning of class
"retrogroup_warning" that lists those subgroup variables and their
final losses.
The search is greedy, so it may settle in a local minimum. Swaps
preserve the number of patients in each subgroup level, so the
optimized counts equal summary$patients.
Use group_optimize_unconstrained() on the output of
group_sample_unconstrained() to optimize without the count
constraint.
The loss targets hazard ratios only, so the number of events in each
subgroup level is not guaranteed to equal summary$events.
vignette("prognostic", package = "retrogroup") examines the
prognostic information of reconstructed subgroups. The statistician
who uses the optimized data in an analysis, for example for covariate
adjustment, is responsible for the consequences.
In addition to the requirements of group_analysis_probability(),
patient must have one column per subgroup variable in summary,
named after the subgroup variable, with no missing values and only the
levels of that subgroup variable in summary. The number of patients
in each subgroup level of these columns must equal
summary$patients. The output of
group_sample_constrained() satisfies these requirements. These
columns are the starting subgroup levels, and all other columns of
patient are returned unchanged.
Optimization uses R's random number generator. Call set.seed()
beforehand for reproducible results.
A tibble with the same rows and columns as patient, in the
same order. Each subgroup column is a factor of the optimized
levels whose levels are those of the subgroup variable in
summary$level, in the same order. The number of patients in each
level equals summary$patients. All other columns are unchanged.
Other optimization:
group_optimize_unconstrained()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) summary <- summary[summary$variable == "age", ] set.seed(0) sample <- group_sample_constrained(patient, summary) optimized <- group_optimize_constrained( sample, summary, tolerance = 1e-2, iterations = 500L ) summary group_analysis_summary(sample, "age") group_analysis_summary(optimized, "age")patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) summary <- summary[summary$variable == "age", ] set.seed(0) sample <- group_sample_constrained(patient, summary) optimized <- group_optimize_constrained( sample, summary, tolerance = 1e-2, iterations = 500L ) summary group_analysis_summary(sample, "age") group_analysis_summary(optimized, "age")
Refine sampled subgroup levels so that the subgroup
statistics observed in the data match the assumed subgroup
statistics in summary. Patient counts are not preserved.
group_optimize_unconstrained( patient, summary, iterations = 10000L, tolerance = 0.001 )group_optimize_unconstrained( patient, summary, iterations = 10000L, tolerance = 0.001 )
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
iterations |
Non-negative integer, the maximum number of iterations for each subgroup variable. A flip step fits one Cox model per subgroup level, and a swap step fits two Cox models. |
tolerance |
Non-negative number on the linear (natural) scale of
the hazard ratio, not the log scale. The search for each subgroup
variable stops when the loss |
group_optimize_unconstrained() implements the
"Optimization for unconstrained sampling" section of
vignette("optimization", package = "retrogroup"), separately for each
subgroup variable. The loss is the Euclidean
distance between the observed and assumed hazard ratios of the levels
of the subgroup variable, as defined in the "Loss function" section of
that vignette. The loss does not steer the number of patients or the
number of events in each level. The observed hazard ratios come from a Cox proportional hazards
model of each subgroup level with treatment as the only
covariate, as in survival::coxph(). If the model cannot be fit for
some subgroup level, for example because the level is empty or one of
its arms has no events, the loss is infinite.
Each iteration takes a flip step with probability 1/2 and a swap step
otherwise, as defined in the "Moves" section of the vignette. If no
swap is possible, the iteration takes a flip step instead. A flip step
draws a patient uniformly at random and moves that patient to
the subgroup level that minimizes ,
or leaves the patient in place if the current level ties for the
minimum. A swap step draws a pair of patients uniformly
at random from the pairs with and exchanges their
subgroup levels if the exchange reduces the loss. Neither step ever
increases the loss. The search
for each subgroup variable stops when the loss falls below tolerance
or after iterations iterations,
whichever comes first. If the loss of any subgroup variable is still
at least tolerance after iterations iterations,
group_optimize_unconstrained() throws a warning of class
"retrogroup_warning" that lists those subgroup variables and their
final losses.
The search is greedy, so it may settle in a local minimum. The number
of patients and the number of events in each subgroup level are not
guaranteed to equal the assumed counts in summary. Use
group_optimize_constrained() on the output of
group_sample_constrained() to preserve the assumed number of
patients.
vignette("prognostic", package = "retrogroup") examines the
prognostic information of reconstructed subgroups. The statistician
who uses the optimized data in an analysis, for example for covariate
adjustment, is responsible for the consequences.
In addition to the requirements of group_analysis_probability(), patient
must have one column per subgroup variable in summary, named after
the subgroup variable, with no missing values and only the levels of
that subgroup variable in summary. The output of
group_sample_unconstrained() satisfies these requirements. These
columns are the starting subgroup levels, and all other columns of
patient are returned unchanged.
Optimization uses R's random number generator. Call set.seed()
beforehand for reproducible results.
A tibble with the same rows and columns as patient, in the
same order. Each subgroup column is a factor of the optimized
levels whose levels are those of the subgroup variable in
summary$level, in the same order. All other columns are unchanged.
Other optimization:
group_optimize_constrained()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) summary <- summary[summary$variable == "age", ] set.seed(0) sample <- group_sample_unconstrained(patient, summary) optimized <- group_optimize_unconstrained( sample, summary, tolerance = 1e-2, iterations = 100L ) summary group_analysis_summary(sample, "age") group_analysis_summary(optimized, "age")patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) summary <- summary[summary$variable == "age", ] set.seed(0) sample <- group_sample_unconstrained(patient, summary) optimized <- group_optimize_unconstrained( sample, summary, tolerance = 1e-2, iterations = 100L ) summary group_analysis_summary(sample, "age") group_analysis_summary(optimized, "age")
Sample a level of each subgroup variable for each patient
from the posterior probabilities estimated by group_analysis_probability(),
such that the number of patients in each subgroup level equals the
assumed number of patients in summary.
group_sample_constrained(patient, summary)group_sample_constrained(patient, summary)
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
group_sample_constrained() implements the
"Constrained sampling" section of
vignette("sampling", package = "retrogroup"). For each subgroup
variable, it iterates through a random permutation of patients and
draws the level of each patient from a categorical distribution with
probabilities proportional to the from
group_analysis_probability(), restricted to the subgroup levels that
have not yet reached their assumed counts. All the requirements of
group_analysis_probability() on patient and summary apply. In addition,
no subgroup variable in summary may have the same name as a column
of patient.
The sampled number of patients in each subgroup level always equals
summary$patients. However, the result is only an approximate draw from independent categorical
distributions conditional on those counts. Use
group_sample_unconstrained() for independent draws without the
count constraint.
The sampled number of events in each subgroup level is not guaranteed
to equal summary$events. The event counts enter only through the
estimated prognostic effects of group_analysis_probability(), and
the loss functions of group_optimize_constrained() and
group_optimize_unconstrained() target hazard ratios only.
vignette("prognostic", package = "retrogroup") examines the
prognostic information of reconstructed subgroups.
The statistician who uses the sampled data in an analysis is
responsible for the consequences.
Sampling uses R's random number generator. Call set.seed()
beforehand for reproducible results.
A tibble with one row per patient, in the same order as the
rows of patient. The columns are all the columns of patient,
followed by one column per subgroup variable, in the order the
subgroup variables first appear in summary$variable. Each subgroup
column is a factor of the sampled levels whose levels are those of the
subgroup variable in summary$level, in the same order.
Other sampling:
group_sample_unconstrained()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_constrained(patient, summary) sample table(sample$age) summary[summary$variable == "age", c("level", "patients")]patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_constrained(patient, summary) sample table(sample$age) summary[summary$variable == "age", c("level", "patients")]
Sample a level of each subgroup variable for each patient,
independently across patients, from the posterior probabilities
estimated by group_analysis_probability().
group_sample_unconstrained(patient, summary)group_sample_unconstrained(patient, summary)
patient |
Patient-level survival data, the output of
|
summary |
Summary subgroup statistics, the output of
|
group_sample_unconstrained() implements the
"Unconstrained sampling" section of
vignette("sampling", package = "retrogroup"). For each subgroup
variable and each patient , it draws
independently, where the come from group_analysis_probability().
All the requirements of group_analysis_probability() on patient and
summary apply. In addition, no subgroup variable in summary
may have the same name as a column of patient.
The sampled number of patients in each subgroup level is not
guaranteed to equal the assumed number of patients in summary.
Use group_sample_constrained() to preserve the assumed counts.
vignette("prognostic", package = "retrogroup") examines the
prognostic information of reconstructed subgroups.
Sampling uses R's random number generator. Call set.seed()
beforehand for reproducible results.
A tibble with one row per patient, in the same order as the
rows of patient. The columns are all the columns of patient,
followed by one column per subgroup variable, in the order the
subgroup variables first appear in summary$variable. Each subgroup
column is a factor of the sampled levels whose levels are those of the
subgroup variable in summary$level, in the same order.
Other sampling:
group_sample_constrained()
patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_unconstrained(patient, summary) sample table(sample$age)patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) summary <- group_data_summary( group_example_summary(), variable = "variable", level = "level", patients = "patients", events = "events", hazard_ratio = "hazard_ratio" ) set.seed(0) sample <- group_sample_unconstrained(patient, summary) sample table(sample$age)