In Small Area Estimation (SAE), model-based estimators borrow strength across domains and time to improve estimation precision over direct survey estimators. However, introducing model assumptions carries the risk of model misspecification, bias, and inappropriate shrinkage.
To address these challenges, fastsae provides a
unified diagnostic framework centered on the diagnose()
function and its dedicated S3 autoplot() visualization
method. It evaluates both frequentist C++ EBLUP models
(eblup_fh, eblup_sfh, eblup_stfh,
eblup_bhf) and Bayesian INLA HB models
(hb_area).
The diagnostic workflow evaluates four fundamental dimensions of SAE model quality:
emdi). The statistic ignores the positive
correlation between \(y_d\) and \(\hat{\theta}_d\), so it is conservative:
under a correct model \(W\) is usually
well below \(D\).autoplot(type = "calibration")) to look for systematic
deviations. It is not used as a formal test of \(\alpha = 0, \beta = 1\): for shrinkage
estimators such as the EBLUP the slope exceeds 1 even when the model is
correct (about \(1/\gamma_d\) for the
variation not explained by the covariates), so such a test would reject
correct models.We demonstrate the diagnostic workflow using the built-in
mys dataset (Mean Years of Schooling in 42 regencies):
diagnose()library(fastsae)
library(ggplot2)
data("mys")
data("mys_proxmat")
# Fit Area-Level Fay-Herriot model
fit_fh <- eblup_fh(
formula = y ~ x1 + x2 + x3,
vardir = ~vardir,
data = na.omit(mys),
method = "REML",
print_result = FALSE
)
# Run comprehensive diagnostic checks
diag_fh <- diagnose(fit_fh, W = mys_proxmat[!is.na(mys$y), !is.na(mys$y)])
print(diag_fh)The resulting fastsae_diagnose object provides
structured access to each diagnostic domain:
# Efficiency gains
diag_fh$precision
#> $rse_threshold
#> [1] 25
#>
#> $prop_reliable
#> [1] 68.75
#>
#> $mean_direct_rse
#> [1] 29.49003
#>
#> $median_direct_rse
#> [1] 19.72062
#>
#> $mean_sae_rse
#> [1] 21.63848
#>
#> $median_sae_rse
#> [1] 17.03635
#>
#> $eff_ratio_summary
#> Min Q1.25% Median Mean Q3.75% Max
#> 1.017672 1.194006 1.291102 1.529910 1.491337 3.907487
#>
#> $prop_gain
#> [1] 100
# Calibration test results
diag_fh$brown_test
#> $bias_regression
#> $bias_regression$alpha
#> [1] -0.7316943
#>
#> $bias_regression$beta
#> [1] 1.155679
#>
#> $bias_regression$se_alpha
#> [1] 0.363461
#>
#> $bias_regression$se_beta
#> [1] 0.0652052
#>
#> $bias_regression$r_squared
#> [1] 0.9128237
#>
#> $bias_regression$n
#> [1] 32
#>
#>
#> $goodness_of_fit
#> $goodness_of_fit$w_stat
#> [1] 4.525856
#>
#> $goodness_of_fit$df
#> [1] 32
#>
#> $goodness_of_fit$crit
#> [1] 46.19426
#>
#> $goodness_of_fit$p_value
#> [1] 1
#>
#> $goodness_of_fit$is_good_fit
#> [1] TRUE
# Moran's I spatial test on residuals
diag_fh$spatial_test
#> $moran_I
#> [1] -0.03722123
#>
#> $expected_I
#> [1] -0.03225806
#>
#> $sd_I
#> [1] 0.007601702
#>
#> $z_stat
#> [1] -0.6529014
#>
#> $p_value
#> [1] 0.5138198
#>
#> $no_residual_autocorrelation
#> [1] TRUEautoplot()fastsae implements dedicated ggplot2 visualization types
for fastsae_diagnose objects:
type = "calibration")Plots direct survey estimates against model predictions along with the 1:1 identity line and the fitted calibration regression:
type = "rse")Visualizes the domain-by-domain reduction in Relative Standard Error:
type = "residuals" &
type = "qq")Inspect standardized residuals against fitted values to detect heteroscedasticity, non-linearities, or outliers:
The exact same diagnose() function applies directly to
Bayesian models fitted with hb_area():
data("sim_area", package = "fastsae")
# Fit Spatial EBP model with BYM2 prior
fit_hb <- hb_area(
formula = y_gaussian ~ x1 + x2,
data = sim_area,
vardir = "vardir",
spatial = "bym2",
W = mys_proxmat,
print_result = FALSE
)
# Diagnose Bayesian model
diag_hb <- diagnose(fit_hb)
diag_hb$precision
#> $rse_threshold
#> [1] 25
#>
#> $prop_reliable
#> [1] 64.28571
#>
#> $mean_direct_rse
#> [1] 103.231
#>
#> $median_direct_rse
#> [1] 17.64954
#>
#> $mean_sae_rse
#> [1] 106.2269
#>
#> $median_sae_rse
#> [1] 18.65578
#>
#> $eff_ratio_summary
#> Min Q1.25% Median Mean Q3.75% Max
#> 1.137447 1.273252 1.319821 1.326845 1.411247 1.501026
#>
#> $prop_gain
#> [1] 100
diag_hb$status
#> [1] "WARNING: High proportions of domains with RSE >= threshold."