tweights_bmr {tboot} | R Documentation |
Set up the needed prerequisites 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)
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 to minimize. Must be either 'euchlidean,' 'klqp' or 'klpq' (i.e. Kullback-Leibler). 'klqp' which is exponential tilting is recommended. |
maxit |
Defines the maximum number of iterations for optimizing 'kl' distance. |
tol |
Tolerance. If the achieved mean is too 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 warning. |
silent |
Allows silencing of 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. The algorithm is summarized more fully in the vignettes. The 'Nindependent' option augments the dataset by assuming some additional specified number of patients. These patients are assumed to made up of a random bootstrapped sample from the dataset for each variable marginally leading to independent 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.
#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)