This function applies a user-specified functional to posterior samples from a fash object, calculates the local false sign rate (LFSR) for each dataset, and returns a ranked data frame. The computation can be parallelized if num_cores > 1.

testing_functional(
  functional,
  lfsr_cal = function(x) {
     min(mean(x <= 0), mean(x >= 0))
 },
  fash,
  indices,
  smooth_var = NULL,
  num_cores = 1
)

Arguments

functional

A function applied to each posterior sample to extract a scalar statistic.

lfsr_cal

A function used to compute the local false sign rate (lfsr).

fash

A fash object.

indices

A numeric vector specifying the dataset indices to evaluate.

smooth_var

A numeric vector specifying refined x values for prediction.

num_cores

An integer specifying the number of cores to use for parallel processing.

Value

A data frame containing:

indices

The dataset indices corresponding to indices.

lfsr

The computed local false sign rate (LFSR) for each dataset.

cfsr

The cumulative false sign rate (CFSR), calculated as the cumulative mean of lfsr.

Examples

set.seed(1)

# Define a functional (e.g., mean of posterior samples)
functional_example <- function(x) { mean(x) }

# Example fash object (assuming it has been fitted)
data_list <- list(
  data.frame(y = rpois(5, lambda = 5), x = 1:5, offset = 0),
  data.frame(y = rpois(5, lambda = 5), x = 1:5, offset = 0)
)
grid <- seq(0, 2, length.out = 10)
fash_obj <- fash(data_list = data_list, Y = "y", smooth_var = "x", grid = grid, likelihood = "poisson", verbose = TRUE)
#> Starting data setup...
#> Completed data setup in 0.00 seconds.
#> Starting likelihood computation...
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%
#> Completed likelihood computation in 0.15 seconds.
#> Starting empirical Bayes estimation...
#> Completed empirical Bayes estimation in 0.00 seconds.
#> fash object created successfully.

# Perform functional hypothesis testing with parallel execution
result <- testing_functional(functional = functional_example, fash = fash_obj, indices = 1:2, num_cores = 2)
print(result)
#>   indices lfsr cfsr
#> 1       1    0    0
#> 2       2    0    0