Skip to content

Commit

Permalink
Fix wrong variance calculation in BiasReduced estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-imbi committed May 9, 2023
1 parent 3af1f1b commit f9fb284
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/estimators.R
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ setMethod("get_stagewise_estimators", signature("BiasReduced", "Normal"),
diff <- Vectorize(\(design, mu_plugin, sigma, two_armed, ...) {
int_kv(design = design,
g1 = \(smean1, n1, sigma, two_armed, ...) {
se1sq <- sigma^2 / ((1L + two_armed) * n1)
se1sq <- sigma^2 * (1L + two_armed) / n1
(smean1 - mu_plugin) * ( (smean1 - mu_plugin) /se1sq) - 1
},
g2 = \(smean1, smean2, n1, n2, sigma, two_armed, ...) {
se1sq <- sigma^2 / ((1L + two_armed) * n1)
se2sq <- sigma^2 / ((1L + two_armed) * n2)
se1sq <- sigma^2 * (1L + two_armed) / n1
se2sq <- sigma^2 * (1L + two_armed) / n2
((n1 * smean1 + n2 * smean2) / (n1 + n2) - mu_plugin) * ( (smean1 - mu_plugin) /se1sq + (smean2 - mu_plugin) /se2sq ) - 1
},
mu = mu_plugin,
Expand Down
29 changes: 29 additions & 0 deletions tests/misc/bias_reduced_unknown_variance_is_correct.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Set tolerances for unit testing
options(
list(
# Root finding inside estimators
adestr_tol_roots = 1e-3,
adestr_maxiter_roots = 1e3,
# Integrals used inside estimators
adestr_tol_inner = 5e-3,
adestr_maxEval_inner = 1e3,
adestr_absError_inner = 1e-5,
# Integrals to evaluate estimators
adestr_tol_outer = 5e-6,
adestr_maxEval_outer = 3e4,
adestr_absError_outer = 1e-8
)
)

evaluate_estimator(MSE(), SampleMean(), Normal(FALSE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), MedianUnbiasedMLEOrdering(), Normal(FALSE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), BiasReduced(), Normal(FALSE), design = designad, mu=0.3, sigma = 1)

evaluate_estimator(MSE(), SampleMean(), Normal(TRUE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), MedianUnbiasedMLEOrdering(), Normal(TRUE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), BiasReduced(), Normal(TRUE), design = designad, mu=0.3, sigma = 1)


evaluate_estimator(MSE(), SampleMean(), Student(FALSE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), MedianUnbiasedMLEOrdering(), Student(FALSE), design = designad, mu=0.3, sigma = 1)
evaluate_estimator(MSE(), BiasReduced(), Student(FALSE), design = designad, mu=0.3, sigma = 1)

0 comments on commit f9fb284

Please sign in to comment.