general.fi.samplesize: Sample size calculator, taking into account power and...

Description Usage Arguments Value Examples

View source: R/front.R

Description

This function takes in a function to compute a p value and a function to simulate data. Using these, it finds the smallest sample size which produces a power and fragility index larger than the input thresholds.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
general.fi.samplesize(
  min.fi = 10,
  min.power = 0.8,
  sample_size_init_power = 100L,
  sample_size_init_fi = NULL,
  get.p.val,
  get.replacements,
  get.sample,
  gamma = 0.6,
  niters = 50,
  cl = NULL,
  verbose = FALSE,
  alpha = 0.05,
  tau = 1/2,
  nsim = 30,
  eps = 0.1,
  algorithm = "walsh"
)

Arguments

min.fi

the smallest acceptable QUANTILE fragility index. When NULL, the FI calculation is skipped and sample_size_init_fi is taken to produce the desired FI.

min.power

the smallest acceptable power. When NULL, the power calculation is skipped and sample_size_init_power is taken to produce the desired power.

sample_size_init_power

a sample size to initialize the algorithm (not necessary, defaults to 10) to find the sample size for power

sample_size_init_fi

a sample size to initialize the algorithm (not necessary, defaults to the sample size for power) to find the sample size for fi

get.p.val

a fucntion that inputs a matrix and returns a p value, otherwise a function that inputs X and Y and returns a p value when alg='greedy'.

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. This gets used in the greedy algorithm.

get.sample

a function which inputs a sample size and outputs a sample, with the covariates in a dataframe X and the response in a dataframe Y

gamma

the power of n^-1 in the gradient descent in the Polyak-Ruppert averaging. The default is 0.60.

niters

The number of times to repeat the sample size calculations. The median of the repitions is then reported.

cl

a cluster from the parallel package, used for the loop over 1:niters

verbose

boolean to indicate whether to print out algorithmic information for the sample size calculation

alpha

a number for the size of test

tau

the quantile of FI to bound, default 1/2

nsim

the number of simulated draws to consider when estimating the power and fragility index quantile

eps

a parameter to control the error. The smaller is it, the more precise the output but the longer the function will take to run.

algorithm

A string specifying the algorithm to use to calculate fragility indices. The default is "walsh". Alternatives include "greedy" for using greedy.fi

Value

the length two numeric vector of the calculated sample sizes for the desired power and fragility index

Examples

1
2
3
4
5
6
7
8
9
ss <- general.fi.samplesize(min.fi = 10, min.power = .8, alpha = .05, tau=.5,
get.p.val = function(m)fisher.test(m)$p.value, get.sample = function(ss) draw.binom(ss, matrix=TRUE),
nsim = 10, niters = 2, verbose = TRUE)

ss <- general.fi.samplesize(min.fi = 10, min.power = .8, alpha = .05, tau=.5,
get.p.val = function(X,Y) fisher.test(table(X[,1], Y[,1]))$p.value,
get.sample = function(ss) draw.binom(ss, matrix=FALSE),
alg='greedy', niters=1, verbose = TRUE,
get.replacements=function(y, x, rn, Y, X) data.frame(setdiff(c("event", "nonevent"), y)))

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