greedy.fi: Calculate a fragility index using a greedy algorithm

Description Usage Arguments Details Value Examples

View source: R/front.R

Description

This is a very general function which approximately calculates a fragility index using covariates, response(s), and any p value function. It's described in detail in the article Generalized fragility index.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
greedy.fi(
  X,
  Y,
  get.replacements,
  get.p.val,
  alpha = 0.05,
  verbose = FALSE,
  cl = NULL,
  only.consider = NULL,
  dont.consider = c()
)

Arguments

X

a data frame of covariates which are not subject to modification.

Y

a data frame of responses which are subject to modification.

get.replacements

a function which outputs a data frame containing all possible row replacements for Y which are to be considered. The functions inputs the row of Y under consideration, the row of X under consideration, the row name, and the full original data frames X and Y.

get.p.val

a function that inputs X and Y and returns a p value

alpha

a numeric for the significance cutoff

verbose

a logical value for whether to print status updates while running

cl

a cluster from the parallel package, used to compute fragility index over each modified observation at each stage of the greedy algorithm

only.consider

a vector of row names to only consider, by default NULL which considers all patients

dont.consider

a vector of row names to not consider

Details

This is a general function which uses a greedy algorithm to compute a fragility index.The function arguments accept data from two sources: covariates in X and responses in Y. Covariates are unchanged by the algorithm, while responses are iteratively changed. The type of each response is specified to determine which substitute outcomes to consider.

Value

a list containing a fragility index and related information

FI

A fragility index, positive if the initial $p$-value was < alpha and negative otherwise

p_val_sequence

An atomic vectors of the p-values at each step of the iteratative algorithm, where the first is the starting p value and the last is the p value which crossed the alpha threshold

reverse

A boolean indicating whether the original p value is larger than alpha

num_patients

The number of patients whose responses were subject to change

patients

An atomic vector with the rownames of the rows which had their responses changed

old_responses

A list of dataframes of the original responses of each changed patient

new_responses

A list of dataframes of the new responses of each changed patient

Zmod

A data frame of the modified cbind(X,Y)

Examples

1
2
3
4
5
6
n <- 100
X <- data.frame("tr_group" = sample(c("treated", "not treated"), n, TRUE))
Y <- data.frame("outcome" = sample(c("sick", "healthy"), n, TRUE))
get.p.val <- function(X, Y) fisher.test(table(X[[1]], Y[[1]]))$p.value
get.replacements <- function(y, x, rn, Y, X) data.frame(Y=setdiff(unique(Y[[1]]), y))
greedy.fi(X, Y, get.p.val = get.p.val, get.replacements = get.replacements)$FI

brb225/FragilityTools documentation built on Jan. 21, 2022, 1:26 a.m.