tboot (version 0.2.0)

tweights_bmr: Function tweights_bmr

Description

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.

Usage

tweights_bmr(
  dataset,
  marginal,
  distance = "klqp",
  maxit = 1000,
  tol = 1e-08,
  warningcut = 0.05,
  silent = FALSE,
  Nindependent = 1
)

Arguments

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.

Value

An object of type tweights. This object conains the following components:

Csqrt

Matrix square root of the covariance.

tweights

Result from the call to tweigths.

marginal

Input marginal simulations.

dataset

Formatted dataset.

target

Attempted target.

distance,maxit,tol, Nindependent, warningcut

Inputed values to 'tweights_bmr'.

Nindependent

Inputed 'Nindependent' option.

augmentWeights

Used for 'Nindependent' option weights for each variable.

weights

tilted weights for resampling

originalTarget

Will be null if target was not changed.

marginal_sd

Standard deviation of the marginals.

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.

See Also

tweights

Examples

Run this code
# NOT RUN {
#Use winsorized marginal to keep marginal simulation within feasible bootstrap region
winsor=function(marginalSims,y)  {
  l=min(y)
  u=max(y)
  ifelse(marginalSims<l,l,ifelse(marginalSims>u,u, marginalSims))
}
#Create an example marginal posterior
marginal = list(Sepal.Length=winsor(rnorm(10000,mean=5.8, sd=.2),iris$Sepal.Length),
               Sepal.Width=winsor(rnorm(10000,mean=3,sd=.2), iris$Sepal.Width),
               Petal.Length=winsor(rnorm(10000,mean=3.7,sd=.2), iris$Petal.Length)
)

#simulate
w = tweights_bmr(dataset = iris, marginal = marginal, silent = TRUE)
post1 = post_bmr(1000, weights = w)
# }

Run the code above in your browser using DataCamp Workspace