This function computes the local false sign rate (LFSR) for a specific dataset within a fash object using posterior sampling. It estimates the probability that the sign of the effect is positive or negative at each grid point and returns the full probability vectors.

compute_lfsr_sampling(fash_fit, index, smooth_var = NULL, M = 3000, deriv = 0)

Arguments

fash_fit

A fash object containing posterior samples.

index

An integer specifying the dataset index for which to compute the LFSR.

smooth_var

A numeric vector specifying refined x values for prediction. If NULL, defaults to the dataset's original x values.

M

An integer specifying the number of posterior samples to generate.

deriv

An integer specifying the order of the derivative to compute.

Value

A list containing:

lfsr

A numeric vector of LFSR values, where each entry corresponds to a grid point in smooth_var.

pos_prob

A numeric vector of probabilities that the effect is positive at each grid point.

neg_prob

A numeric vector of probabilities that the effect is negative at each grid point.

Examples

# Example fash object (assuming it has been fitted)
set.seed(1)
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.14 seconds.
#> Starting empirical Bayes estimation...
#> Completed empirical Bayes estimation in 0.00 seconds.
#> fash object created successfully.

# Compute LFSR for a single dataset
lfsr_result <- compute_lfsr_sampling(fash_obj, index = 1, smooth_var = seq(0, 5, by = 0.1), M = 3000)
print(lfsr_result$lfsr)  # Print the LFSR values
#>  [1] 1.0000000 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#>  [8] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [15] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [22] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [29] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [36] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [43] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [50] 0.3983333 0.3983333
print(lfsr_result$pos_prob)  # Print the positive probability
#>  [1] 1.0000000 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#>  [8] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [15] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [22] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [29] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [36] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [43] 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667 0.6016667
#> [50] 0.6016667 0.6016667
print(lfsr_result$neg_prob)  # Print the negative probability
#>  [1] 1.0000000 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#>  [8] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [15] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [22] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [29] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [36] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [43] 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333 0.3983333
#> [50] 0.3983333 0.3983333