Title: | Tilted Bootstrap |
---|---|
Description: | The tilted bootstrap as implemented in the 'tboot' package is an approach to resampling where samples are drawn from the observed data with some samples appearing more frequently than others. Tilted bootstraping may be used to create simulated clinical trail data with realistic correlation structures and assumed efficacy levels. The 'tboot' package may also be used for simulating a joint Bayesian distribution along along with clinical trials based on the Bayesian distribution. |
Authors: | Nathan Morris [aut, cre], William Michael Landau [aut], Eli Lilly and Company [cph] |
Maintainer: | Nathan Morris <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2025-03-04 05:51:16 UTC |
Source: | https://github.com/njm18/tboot |
tboot: tilted bootstrapping and Bayesian marginal reconstruction.
Nathan Morris [email protected]
William Michael Landau [email protected]
https://github.com/wlandau-lilly/tboot
Simulates the joint posterior based upon a dataset and specified marginal posterior distribution of the mean of selected variables.
post_bmr(nsims, weights_bmr)
post_bmr(nsims, weights_bmr)
nsims |
The number of posterior simulations to draw. |
weights_bmr |
An object of class 'tweights_bmr' created using the 'tweights_bmr' function. |
A matrix of simulations from the posterior.
Bootstrap nrow
rows of dataset
using
the given row-level weights.
tboot(nrow, weights, dataset = weights$dataset, fillMissingAug = TRUE)
tboot(nrow, weights, dataset = weights$dataset, fillMissingAug = TRUE)
nrow |
number of rows in the new bootstrapped dataset. |
weights |
an object of class 'tweights' output from the 'tweights' function. |
dataset |
Data frame or matrix to bootstrap. Rows of the dataset must be in the same order as was used for the 'tweights' call. However the dataset may include additional columns not included in the 'tweights' calll. |
fillMissingAug |
fill in missing augmentation with primary weights resampling. |
Bootstrap simulates a dataset using the tilted weights. Details a further documented in the vignette.
A simulated dataset with 'nrow' rows.
Bootstrap nrow
rows of dataset
using
the given row-level weights.
tboot_bmr(nrow, weights_bmr, tol_rel_sd = 0.01)
tboot_bmr(nrow, weights_bmr, tol_rel_sd = 0.01)
nrow |
number of rows in the new bootstrapped dataset. |
weights_bmr |
an object of class 'tweights' output from the 'tweights' function. |
tol_rel_sd |
An error will be called if for some simulation if the target is not achievable with the data. However, the error will only be called if max absolute difference releative to the marginal standard is greater than specified. |
Simulates a dataset by first simulating from the posterior distribution of the column means and then simulating a dataset with that underlying mean. Details a further documented in the vignette.
A simulated dataset with 'nrow' rows. The underlying 'true' posterior parameter value is an attribute which can be extracted useing attr(ret, "post_bmr")
where 'ret' is the matrix.
tweights
Returns a vector p
of resampling probabilities
such that the column means of tboot(dataset = dataset, p = p)
equals target
on average.
tweights( dataset, target = apply(dataset, 2, mean), distance = "klqp", maxit = 1000, tol = 1e-08, warningcut = 0.05, silent = FALSE, Nindependent = 0 )
tweights( dataset, target = apply(dataset, 2, mean), distance = "klqp", maxit = 1000, tol = 1e-08, warningcut = 0.05, silent = FALSE, Nindependent = 0 )
dataset |
Data frame or matrix to use to find row weights. |
target |
Numeric vector of target column means. If the 'target' is named, then all elements of names(target) should be in the dataset. |
distance |
The distance to minimize. Must be either 'euchlidean,' 'klqp' or 'klpq' (i.e. Kullback-Leibler). 'klqp' which is expontential tilting is recomneded. |
maxit |
Defines the maximum number of iterations for optimizing 'kl' distance. |
tol |
Tolerance. If the achieved mean is to far from the target (i.e. as defined by tol) an error will be thrown. |
warningcut |
Sets the cutoff for determining when a large weight will trigger a warnint. |
silent |
Allows silencing some messages. |
Nindependent |
Assumes the input also includes 'Nindependent'samples with independent columns. See details. |
Let be probability of sampling subject
from a dataset with
individuals (i.e. rows of the dataset) in the classic resampling with replacement scheme.
Also, let
be the probability of sampling subject
from a dataset with
individuals in our new resampling scheme. Let
represent a distance between the two resampling schemes. The
tweights
function seeks to solve the problem:
Subject to the constraint that:
and
where dataset is a n x K matrix of variables input to the function.
Optimization for euclidean distance is a quadratic program and utilizes the ipop function in kernLab. The euclidean based solution helps form a starting value which is used along with the constOptim function and lagrange multipliers to solve the Kullback-Leibler distance optimization. Output is the optimal porbability (p)
The 'Nindependent' option augments the dataset by assuming some additional specified number of patients. These pateints are assumed to made up of a random bootstrapped sample from the dataset for each variable marginaly leading to indepenent variables.
An object of type tweights
. This object conains the following components:
tilted weights for resampling
Will be null if target was not changed.
Actual target that was attempted.
Achieved mean from tilting.
Inputed dataset.
Reformated dataset.
Inputed 'Nindependent' option.
Setup the needed pre-requisites in order to prepare for bayesian marginal reconstruction (including a call to tweights). Takes as input simulations from the posterior marginal distribution of variables in a dataset.
tweights_bmr( dataset, marginal, distance = "klqp", maxit = 1000, tol = 1e-08, warningcut = 0.05, silent = FALSE, Nindependent = 1 )
tweights_bmr( dataset, marginal, distance = "klqp", maxit = 1000, tol = 1e-08, warningcut = 0.05, silent = FALSE, Nindependent = 1 )
dataset |
Data frame or matrix to use to find row weights. |
marginal |
Must be a named list with each element a vector of simulations of the marginal distribution of the posterior mean of data in the dataset. |
distance |
The distance measure to minimize. Must be either 'euchlidean' or 'kl' (i.e. Kullback-Leibler). 'klqp' is recomneded. |
maxit |
Defines the maximum number of iterations for optimizing 'kl' distance. |
tol |
Tolerance. If the achieved mean is to far from the target (i.e. as defined by tol) an error will be thrown. |
warningcut |
Sets the cutoff for determining when a large weight will trigger a warnint. |
silent |
Allows silencing some messages. |
Nindependent |
Assumes the input also includes 'Nindependent'samples with independent columns. See details. |
Reconstructs a correlated joint posterior from simulations from a marginal posterior. Algorythm is summarized more fully in the vignettes. The 'Nindependent' option augments the dataset by assuming some additional specified number of patients. These pateints are assumed to made up of a random bootstrapped sample from the dataset for each variable marginaly leading to indepenent variables.
An object of type tweights
. This object conains the following components:
Matrix square root of the covariance.
Result from the call to tweigths.
Input marginal simulations.
Formatted dataset.
Attempted target.
Inputed values to 'tweights_bmr'.
Inputed 'Nindependent' option.
Used for 'Nindependent' option weights for each variable.
tilted weights for resampling
Will be null if target was not changed.
Standard deviation of the marginals.