aalfons / robmed

Perform mediation analysis via a fast-and-robust bootstrap test, as well as various other methods
GNU General Public License v3.0
6 stars 0 forks source link

Error with bootstrap samples less than sample size #38

Closed VLDrenth closed 1 year ago

VLDrenth commented 1 year ago

When the selected number of bootstrap samples is less than or equal to the sample size of the data, the GUI stops when either OLS or robmed is run. The warning given in the R console is Error in bca.ci: estimated adjustment 'a' is NA.

aalfons commented 1 year ago

The problem is in the default estimation of the acceleration constant a for the BCa confidence interval in package boot. By default, this is estimated based on a regression of the bootstrap replicates on the frequency array. The latter is an R x n matrix that indicates how often each observation occurs in each bootstrap sample. Hence, if the number of bootstrap samples R is smaller than the number of observations n, we have too many variables in this regression.

This could potentially be solved in the robmed package by:

  1. Using a different way to compute the acceleration constant if R is not larger than n, see the type argument in function boot::empinf(). But I don't think that we can pass this argument along, as function boot::boot.ci() also has a type argument (which specifies the type of confidence interval). This seems like poor design of the boot package.
  2. In robmed::test_mediation(), we can change the default for the type of confidence intervals to be "bca" (for BCa intervals) when R > n, and "perc" (for simple percentile intervals) otherwise.