This function updates the prior and posterior weights in a fitted fash object using Bayes Factor (BF) control. It automatically computes the Bayes Factor (BF), estimates the proportion of null datasets (\(\pi_0\)), and updates the model accordingly.

BF_update(fash, plot = FALSE)

Arguments

fash

A fash object containing the fitted model and likelihood matrix.

plot

A logical value. If TRUE, generates diagnostic plots for BF control.

Value

The updated fash object with the following components updated:

prior_weights

Updated prior mixture weights reflecting the estimated \(\pi_0\).

posterior_weights

Updated posterior mixture weights for each dataset.

BF

Computed Bayes Factors for each dataset.

lfdr

Local False Discovery Rate (LFDR), extracted as the first column of `posterior_weights`.

Details

This function performs the following steps:

  1. Computes Bayes Factors (BF): The BF is calculated as the ratio of likelihood under the alternative hypothesis to the likelihood under the null hypothesis.

  2. Estimates \(\pi_0\): The function applies BF-based control to estimate the proportion of null datasets.

  3. Updates prior weights: The function updates the prior mixture weights to reflect the estimated null proportion.

  4. Updates posterior weights: The posterior weights are updated based on the reweighted prior and likelihood matrix.

  5. Stores the computed Bayes Factors and LFDR: The function now saves the computed BF and LFDR in the fash object for further analysis.

Examples


# Example usage:
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.15 seconds.
#> Starting empirical Bayes estimation...
#> Completed empirical Bayes estimation in 0.00 seconds.
#> fash object created successfully.

# Update prior and posterior weights using BF control
fash_updated <- BF_update(fash_obj, plot = TRUE)
#> Warning: Bayes Factors contain only NA or NaN values. BF-based correction cannot be applied. Returning the original fash object without updates. Please consider refitting the model or checking the data if you wish to use the BF-based correction for prior.

# Access updated components
print(fash_updated$prior_weights)
#>   psd prior_weight
#> 1   0            1
print(fash_updated$posterior_weights)
#>      0
#> [1,] 1
#> [2,] 1
print(fash_updated$BF)
#> NULL
print(fash_updated$lfdr)
#> [1] 1 1