Title: | TBF Methodology Extension for Multinomial Outcomes |
---|---|
Description: | Extends the test-based Bayes factor (TBF) methodology to multinomial regression models and discrete time-to-event models with competing risks. The TBF methodology has been well developed and implemented for the generalised linear model [Held et al. (2015) <doi:10.1214/14-STS510>] and for the Cox model [Held et al. (2016) <doi:10.1002/sim.7089>]. |
Authors: | Rachel Heyard [aut, cre] |
Maintainer: | Rachel Heyard <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.3 |
Built: | 2025-02-26 03:29:44 UTC |
Source: | https://github.com/cran/TBFmultinomial |
Extension of the TBF methdology introduced by Held et al. (2015) <doi:10.1214/14-STS510> to discrete time-to-event models with competing risks (also applicable to the multinomial regression model)
Rachel Heyard [email protected]
This function computes the marginal likelihoods based on the AIC or on the BIC, that will later be used to calculate the TBF.
AIC_BIC_based_marginalLikelihood(fullModel = NULL, candidateModels = NULL, data, discreteSurv = TRUE, AIC = TRUE, package = "nnet", maxit = 150, numberCores = 1)
AIC_BIC_based_marginalLikelihood(fullModel = NULL, candidateModels = NULL, data, discreteSurv = TRUE, AIC = TRUE, package = "nnet", maxit = 150, numberCores = 1)
fullModel |
formula of the model including all potential variables |
candidateModels |
Instead of defining the full model we can also specify the candidate models whose deviance statistic and d.o.f should be computed |
data |
the data |
discreteSurv |
Boolean variable telling us whether a ‘simple’ multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
AIC |
if |
package |
Which package should be used to fit the models; by default
the |
maxit |
Only needs to be specified with package |
numberCores |
How many cores should be used in parallel? |
a vector with the marginal likelihoods of all candidate models
Rachel Heyard
# data extraction: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here the define time as a spline with 3 knots # now we can compute the marginal likelihoods based on the AIC f.ex: mL_AIC <- AIC_BIC_based_marginalLikelihood(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, AIC = TRUE)
# data extraction: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here the define time as a spline with 3 knots # now we can compute the marginal likelihoods based on the AIC f.ex: mL_AIC <- AIC_BIC_based_marginalLikelihood(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, AIC = TRUE)
This function retrieves the formulas of all the candidate models if the reference model is the null / baseline model.
all_formulas(fullModel, discreteSurv = TRUE)
all_formulas(fullModel, discreteSurv = TRUE)
fullModel |
formula of the model including all potential variables |
discreteSurv |
Boolean variable telling us whether a ‘simple’ multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
character vector with all the formulas; the first one will be the reference model; the last element will be the full model.
Rachel Heyard
data("VAP_data") FULL <- outcome ~ ns(day, df = 4) + male + type + SOFA models <- TBFmultinomial:::all_formulas(fullModel = FULL, discreteSurv = TRUE) # models
data("VAP_data") FULL <- outcome ~ ns(day, df = 4) + male + type + SOFA models <- TBFmultinomial:::all_formulas(fullModel = FULL, discreteSurv = TRUE) # models
This function takes a PMP object an returns a data.frame
summarising
the information.
## S3 method for class 'PMP' as.data.frame(x, ...)
## S3 method for class 'PMP' as.data.frame(x, ...)
x |
valid |
... |
arguments to be passed to |
a data.frame
with the posterior and prior probabilities as
well as the definition of the models
Rachel Heyard
This function performs CSVS given a model fitted using the multinom()
function of the nnet
package or the vglm()
function of the
VGAM
package.
CSVS(g, model, discreteSurv = TRUE, nbIntercepts = NULL, package = "nnet")
CSVS(g, model, discreteSurv = TRUE, nbIntercepts = NULL, package = "nnet")
g |
the estimated g, must be fixed to one value |
model |
the model fitted using either |
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
nbIntercepts |
how many cause-specific intercepts are there? they |
package |
Which package has been used to fit the model, |
Rachel Heyard
# data extraction: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here the define time as a spline with 3 knots # we first need to fit the multinomial model: model_full <- multinom(formula = FULL, data = VAP_data, maxit = 150, trace = FALSE) G <- 9 # let's suppose g equals to nine # then we proceed to CSVS CSVS_nnet <- CSVS(g = G, model = model_full, discreteSurv = TRUE, package = 'nnet')
# data extraction: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here the define time as a spline with 3 knots # we first need to fit the multinomial model: model_full <- multinom(formula = FULL, data = VAP_data, maxit = 150, trace = FALSE) G <- 9 # let's suppose g equals to nine # then we proceed to CSVS CSVS_nnet <- CSVS(g = G, model = model_full, discreteSurv = TRUE, package = 'nnet')
This function computes the prior model probabilities of the candidate models
model_priors(fullModel, discreteSurv = TRUE, modelPrior = "flat")
model_priors(fullModel, discreteSurv = TRUE, modelPrior = "flat")
fullModel |
formula of the model including all potential variables |
discreteSurv |
Boolean var telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
modelPrior |
what prior should be used on the model space?
|
a numerical vector with the prior model probabilities
Rachel Heyard
# the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots priors <- model_priors(fullModel = FULL, discreteSurv = TRUE, modelPrior = 'dependent')
# the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots priors <- model_priors(fullModel = FULL, discreteSurv = TRUE, modelPrior = 'dependent')
This function gives us the PIPs for each landmark.
PIPs_by_landmarking(fullModel, data, discreteSurv = TRUE, numberCores = 1, package = "nnet", maxit = 150, prior = "flat", method = "LEB", landmarkLength = 1, lastlandmark, timeVariableName)
PIPs_by_landmarking(fullModel, data, discreteSurv = TRUE, numberCores = 1, package = "nnet", maxit = 150, prior = "flat", method = "LEB", landmarkLength = 1, lastlandmark, timeVariableName)
fullModel |
formula of the model including all potential variables |
data |
the data frame with all the information |
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
numberCores |
How many cores should be used in parallel? |
package |
Which package should be used to fit the models; by default
the |
maxit |
Only needs to be specified with package |
prior |
Prior on the model space |
method |
Method for the g definition |
landmarkLength |
Length of the landmark, by default we use each day |
lastlandmark |
Where will be the last landmark? |
timeVariableName |
What is the name of the variable indicating time? |
a list with the PIPs for each landmark
Rachel Heyard
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots PIPs_landmark <- PIPs_by_landmarking(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, numberCores = 1, package = 'nnet', maxit = 150, prior = 'flat', method = 'LEB', landmarkLength = 7, lastlandmark = 21, timeVariableName = 'day')
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots PIPs_landmark <- PIPs_by_landmarking(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, numberCores = 1, package = 'nnet', maxit = 150, prior = 'flat', method = 'LEB', landmarkLength = 7, lastlandmark = 21, timeVariableName = 'day')
Plot a CSVS object
plot_CSVS(CSVSobject, namesVar = NULL, shrunken = FALSE, standardized = FALSE, numberIntercepts, ...)
plot_CSVS(CSVSobject, namesVar = NULL, shrunken = FALSE, standardized = FALSE, numberIntercepts, ...)
CSVSobject |
valid |
namesVar |
names of the variables |
shrunken |
should the coefficients be shrunken? |
standardized |
should the coefficients be standardized? |
numberIntercepts |
how many cause-specific intercepts are in the model for each outcome |
... |
parameters for plot |
Rachel Heyard
This function computes the posterior probability of all candidate models
PMP(fullModel = NULL, candidateModels = NULL, data = NULL, discreteSurv = TRUE, modelPrior = NULL, method = "LEB", prior = "flat", package = "nnet", maxit = 150, numberCores = 1)
PMP(fullModel = NULL, candidateModels = NULL, data = NULL, discreteSurv = TRUE, modelPrior = NULL, method = "LEB", prior = "flat", package = "nnet", maxit = 150, numberCores = 1)
fullModel |
formula of the model including all potential variables |
candidateModels |
Instead of defining the full model we can also specify the candidate models whose deviance statistic and d.o.f should be computed |
data |
the data frame with all the information |
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
modelPrior |
optionaly the model priors can be computed before if candidateModels is different from NULL. |
method |
tells us which method for the definition of g should be
used. Possibilities are: |
prior |
should a dependent or a flat prior be used on the model space?
Only needed if |
package |
Which package should be used to fit the models; by default
the |
maxit |
Only needs to be specified with package |
numberCores |
How many cores should be used in parallel? |
an object of class TBF.ingredients
Rachel Heyard
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots # computation of the posterior model probabilities: test <- PMP(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, maxit = 150) class(test)
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots # computation of the posterior model probabilities: test <- PMP(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, maxit = 150) class(test)
This function computes the PIPs of all potential predictors
postInclusionProb(object)
postInclusionProb(object)
object |
An object of class |
an named vector with all PIPs
Rachel Heyard
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots # computation of the posterior model probabilities: test <- PMP(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, maxit = 150) class(test) #computation of the posterior inclusion probabilities: postInclusionProb(test)
# extract the data: data("VAP_data") # the definition of the full model with three potential predictors: FULL <- outcome ~ ns(day, df = 4) + gender + type + SOFA # here we define time as a spline with 3 knots # computation of the posterior model probabilities: test <- PMP(fullModel = FULL, data = VAP_data, discreteSurv = TRUE, maxit = 150) class(test) #computation of the posterior inclusion probabilities: postInclusionProb(test)
This function samples from a specific model inside a PMP
object.
sample_multinomial(PMP_object, shrink = TRUE, data, which = "MPM", discreteSurv = TRUE)
sample_multinomial(PMP_object, shrink = TRUE, data, which = "MPM", discreteSurv = TRUE)
PMP_object |
formula of the model including all potential variables |
shrink |
should the coefficients be shrunken towards their prior mean? |
data |
the (training) data frame with all the information |
which |
which model should be sampled from? either an integer, 'MPM' or 'MAP' |
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
returns an object with the model coefficients and supplementary information
Rachel Heyard
This function computes the TBF as well as g
TBF(ingredients = NULL, fullModel = NULL, method = "LEB", data = NULL, discreteSurv = TRUE, prior = NULL, package = "nnet", maxit = 150)
TBF(ingredients = NULL, fullModel = NULL, method = "LEB", data = NULL, discreteSurv = TRUE, prior = NULL, package = "nnet", maxit = 150)
ingredients |
|
fullModel |
if |
method |
tells us which method for the definition of g should be
used. Possibilities are: |
data |
the data frame with all the information. Only needed if
|
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
prior |
should a dependent or a flat prior be used on the model space?
Only needed if |
package |
Which package should be used to fit the models; by default
the |
maxit |
Only needs to be specified with package |
A list with the TBF and the g (if it is fixed) for all the candidate models.
Rachel Heyard
This function calculates the ingredients needed to compute the TBFs: like the deviances with their degrees of freedom of the relevant candidate models.
TBF_ingredients(fullModel = NULL, data, discreteSurv = FALSE, numberCores = 1, candidateModels = NULL, package = "nnet", maxit = 150)
TBF_ingredients(fullModel = NULL, data, discreteSurv = FALSE, numberCores = 1, candidateModels = NULL, package = "nnet", maxit = 150)
fullModel |
formula of the model including all potential variables |
data |
the data frame with all the information |
discreteSurv |
Boolean variable telling us whether a 'simple' multinomial regression is looked for or if the goal is a discrete survival-time model for multiple modes of failure is needed. |
numberCores |
How many cores should be used in parallel? |
candidateModels |
Instead of defining the full model we can also specify the candidate models whose deviance statistic and d.o.f should be computed |
package |
Which package should be used to fit the models; by default
the |
maxit |
Only needs to be specified with package |
an object of class TBF.ingredients
Rachel Heyard
It is a tiny subset of the OUTCOMEREA database whose only perhaps will be to test an illustrate the functions of this package.
data(VAP_data)
data(VAP_data)
A data frame with 1640 rows and 7 variables on 90 distinct patients:
distinct ID for each patient
day of ventilation, day = 1 is the first day of ventilation
is it a medical or a surgical patient
gender of the patient, 1 = male, 0 = female
the SAPS 2 score at admission to the ICU
the daily SOFA score
final outcome after the first observation period