R/04_fash.R
testing_functional.Rd
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
.
A function applied to each posterior sample to extract a scalar statistic.
A function used to compute the local false sign rate (lfsr).
A fash
object.
A numeric vector specifying the dataset indices to evaluate.
A numeric vector specifying refined x values for prediction.
An integer specifying the number of cores to use for parallel processing.
A data frame containing:
The dataset indices corresponding to indices
.
The computed local false sign rate (LFSR) for each dataset.
The cumulative false sign rate (CFSR), calculated as the cumulative mean of lfsr
.
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