Preparation of the first CRAN release; the fits and their numbers are those of 0.4.2.
R/constants.R records the checksums of the final tables
of the study; the stored values are unchanged.DESCRIPTION names the copyright holder; README shows the CRAN
installation.The numbers of the simulation study stored in the package (shown in
vignette("simulation-study")) now come from the final tables of the study
with its current rules: the refit of the convergence check of the
marginalized model counts only if it converges (the rule implemented in
0.4.1), and datasets with separation stay results. Only the rows of the
marginalized model changed: its mean share of usable datasets is lower
(overall and with short series and few clusters), it is clearly below 2.5%
at more design points (also with 10 clusters), its unconditional power is
slightly lower, and its distances from 5% in the head-to-head map with GEE
AR(1) and Fay-Graubard change (two cells change class: 15-25 clusters with
3 occasions is now about the margin, more than 25 clusters with 2 occasions
is now similar). It is still never clearly above 7.5%. The values are in
the vignette; the list of changes, old and new, is in
dev/checks_0.4.2/out/constants_diff.csv of the source repository. Every stored value now names, in R/constants.R, its source
table and the identifier of the study's registry of numbers. The
statements of the vignette that depend on these numbers are computed from
them. Fitting functions and their results are unchanged.
The convergence check now follows the rule adopted by the simulation study
behind the package (decision of 3 November 2026). A fit with the time
trend of the latent standard deviation that is at the boundary (nlm()
code other than 1 or 2, a slope of the latent standard deviation below
check_threshold, or, with check_coherence = TRUE, a log-likelihood
below that of the fit without the trend) is replaced by the fit without
the trend only if nlm() reports convergence of that refit (code 1 or
2) and its estimates and standard errors are finite. Otherwise the
marginalized model gives no result for the dataset: with
method = "auto" fit_fewclust() falls back to GEE (AR(1) working
correlation, Fay-Graubard correction, as for any other failure of the
marginalized model) with a message, and with method = "mmm" it stops with
an error of class "fewclust_error". The message says why: the refit did
not converge (with its nlm() code), or it gave no finite estimate.
Earlier behaviour (0.3.x, 0.4.0): the refit was used whenever its estimates
and standard errors were finite, whatever its nlm() code, and when it was
not finite the fit at the boundary was reported. The study judged that a
fallback fit must pass the same convergence test as the fit it replaces.
Results change only for the datasets on which the check intervenes and the
refit does not converge or is not finite; on every other dataset estimates,
standard errors, statistics, degrees of freedom and p-values are identical
to 0.4.0.
fit$convergence) has the new path
"no result" and a field refit_status ("converged",
"not converged", "not finite"). The path
"constant fit failed, trend fit kept" no longer exists, and
"constant fit used" now always means a converged refit. When GEE is
reported because the marginalized model gave no result,
fit$convergence keeps the record of its check and summary() prints
it; the error of method = "mmm" carries it as convergence.vignette("simulation-study") are unchanged in this version.On 240 datasets of the study (scenario M3, the model the package fits)
where the study's rule gives no result, the package gives none on 238
(191 by the convergence check, 47 because fit_fewclust() refuses the
design); on the other 2 its optimiser converges where MMLB::mm does not,
so the check does not intervene. On 240 datasets where the study uses a
converged refit, the package reports the same estimate and standard error
on 224; the 16 others are design refusals (7), refits with a non-finite
standard error in the package (3), trend fits that converge in the package
(3) and standard errors that differ (3). Details in
dev/aggiornamento_0.4.1.md of the source repository.
fewclust is now a classic R package in the style of the tidyverse: one
fitting function with the data first, standard methods, broom verbs that
return tibbles, and short messages that say what happens and what to do.
The numbers do not change: for every method, the estimates, standard
errors, statistics, degrees of freedom and p-values are identical to those
of version 0.3.1, and so are gee_vcov() and flip_test().
auto_cluster_fit(formula, data, group, time, strategy, reference, alpha)
is replaced by
fit_fewclust(data, formula, id, time, method, corstr, correction, conf_level).
The correspondence:
| 0.3.1 | 0.4.0 |
|-----------------------------------------|----------------------------------------------------|
| auto_cluster_fit(f, d, group = id) | fit_fewclust(d, f, id = id) |
| strategy = "auto" | method = "auto" (default) |
| strategy = "mmm" | method = "mmm" |
| strategy = "gee_ar1_fg" | method = "gee" (defaults corstr = "ar1", correction = "fg") |
| strategy = "gee_exch_md" | method = "gee", corstr = "exchangeable", correction = "md" |
| strategy = "gee_ind_unc" | method = "gee", corstr = "independence", correction = "none" |
| reference = "t" | always (t on N - p degrees of freedom) |
| alpha = 0.05 | conf_level = 0.95 |
| fewclust_control(corstr = ) | corstr = of fit_fewclust() |
| fit$coefficients (data frame) | tidy(fit) (tibble); coef(fit) is now a named vector |
| fit$strategy | fit$method ("mmm" or "gee") and fit$fallback |
| fit$model | fit$engine |
| fit$model$check | fit$convergence |
| flip_test(f, d, group = id, B = 1999) | flip_test(d, f, id = id, reps = 1999) |
A design that cannot give an estimate is now an error of class
"fewclust_error" (it was a "fewclust_refusal" object). Fewer than 10
groups is a warning, no longer a refusal.
Removed: cluster_strategies(), cluster_diagnose(),
compare_strategies(), plot() methods, the mixed-model strategies
("glmm_wald", "glmm_lrt"), the normal reference (reference = "z")
and fewclust_control(nAGQ = ). The package no longer depends on lme4,
reformulas or graphics.
simulate_clustered_binary() returns a tibble.
id and time accept bare column names or strings (tidyselect), also
through {{ }} inside your own functions.predict() (log odds or probability, also on newdata),
nobs(), formula(), and broom's augment(); tidy() takes
conf.int and conf.level; glance() gives one row per fit;
tidy() also works on flip_test().flip_test() warns, with the reason, when the test is not computable."fewclust_error", "fewclust_warning" and "fewclust_message".vignette("simulation-study").The automatic choice now follows the corrected simulation study (manuscript
v7). In the study a dataset whose outcome is constant (all 0 or all 1)
gives no usable result for any method; GEE with an AR(1) working
correlation and the Fay-Graubard correction had counted 9,646 such datasets
as usable. Without them GEE with an AR(1) working
correlation, the Fay-Graubard correction and a t reference is clearly above
a 7.5% type I error at 2 design points (10 clusters, 2 occasions), and the
rule of the study selects the marginalized multilevel model with the
convergence check. The numbers the paper took from the package do not
change: gee_vcov() and the engine of the marginalized model compute
exactly what version 0.3.0 computed.
"mmm"), at every number of clusters and occasions. GEE with an AR(1)
working correlation, the Fay-Graubard correction and a t reference
("gee_ar1_fg") is the alternative: the plan names it in
$alternative, and auto_cluster_fit() fits it, and records it, when
the marginalized model returns no usable estimate. Version 0.3.0
recommended the GEE strategy first and fell back to the marginalized
model. With 2-3 occasions and at most 25 clusters flip_test() remains
the complement.flip_test()."gee_ar1_fg" (chosen by the user, or used by the fallback) with fewer
than 15 groups and 2 occasions carries a caution with the 2 design points
of the study where it was clearly above 7.5% (scenario M2, 10 clusters,
2 occasions; GLMM-native and GLMM-AR1 mechanisms), with their rejections,
usable datasets and usable share."gee_ar1_fg", 138
for "gee_ar1_kc", 20 for "gee_ar1_md"); they are generated from the
tables of the study by dev/make_constants.R.flip_test() returns no p-value on a dataset whose outcome is constant,
with the reason "constant outcome" (0.3.0 said "score numerically zero").
The signs are drawn first, so the random stream is unchanged.
auto_cluster_fit() and cluster_strategies() already refused such a
dataset for every strategy (rule D2).check_coherence = TRUE the package
reports the fit without the trend there.check_coherence = TRUE (default) treats as not converged a fit with a
trend of the latent standard deviation whose log-likelihood is below that
of the fit without the trend. This condition is not part of the rule of
the study; on the 127 datasets it changed the reported fit in 4. Set
fewclust_control(check_coherence = FALSE) to apply the rule of the
study exactly.fewclust_control(check_coherence = TRUE) remains the default. The
coherence condition is an addition of the package to the convergence
check of the study; check_coherence = FALSE gives the rule of the study
exactly. Since the marginalized model is now the automatic choice, this
default concerns the recommended strategy; the decision on it is open.The package now follows the final version of the simulation study
(manuscript v5: 2,376 design points, four data-generating mechanisms
including a purely serial one). The numbers of the paper do not change:
the sandwich corrections of gee_vcov() and the engine of the
marginalized multilevel model compute exactly what version 0.2.0 computed.
"gee_ar1_fg"), at every number of clusters and occasions (Figure 1 of
the study). The marginalized multilevel model with the convergence
check and a t reference ("mmm") is the alternative: the plan names it,
and auto_cluster_fit() fits it, and records it, when the GEE fit returns
no usable estimate. Version 0.2.0 recommended the marginalized model
first and fell back to Fay-Graubard.fewclust_control(corstr = ) defaults to "ar1" (was "exchangeable")."gee_ar1_fg", "gee_exch_md", "gee_ind_kc" and so on.
The names of 0.2.0 ("gee_fg", ...) are still accepted and use the
working correlation of fewclust_control(); the qualified names choose
it directly.geepack::geeglm() with the scale
parameter fixed at 1 (scale.fix = TRUE), on rows ordered by group and,
within a group, by time. With an AR(1) working correlation the order
defines the lags; the estimated scale changed the estimate of the
correlation parameter. Estimates and standard errors of the GEE
strategies can therefore differ from those of 0.2.0.flip_test(): the sign-flip score test of the study (Hemerik, Goeman and
Finos 2020) for one coefficient, with its rules of computability. It
returns a p-value only; the interval obtained by inverting it is not
offered, as in the study. On study datasets regenerated from their seeds
it reproduces the p-values of the paper (dev/aggiornamento_0.3.0.md).flip_test() as a
complement ($complement), and the caution quotes the usable shares of
Table 4 (46% for the GEE strategy, 39% for the marginalized model, 72% for
the sign-flip test).cluster_diagnose()$groups_with_gaps), or
the values of time are not equally spaced.$model$check$path, $reason) and both fits, with and without
the time trend ($trend, $constant), so that how often the check
intervened can be reported. Tests on six study datasets reproduce the
branch, the estimate and the p-value of the study.check_coherence) is documented as an
addition of the package, not part of the rule of the study.The package now encodes the decision rule of the revised simulation study (manuscript v4, 1,896 design points).
"mmm"), with a t reference on N - p degrees of
freedom, at every number of clusters and occasions. The crossover rule
between the mixed-model likelihood-ratio test and the Fay-Graubard
sandwich (45/55 clusters) and the between-within degrees of freedom of
0.1.0 are gone.auto_cluster_fit(), cluster_strategies() and cluster_diagnose()
take (formula, data, group, time, ...); the estimand argument is
removed (the estimand follows from the strategy).fewclust_control() has new arguments (q, check, check_threshold)
and no longer has time_limit, process_guard, ci_method or
thresholds.prepare_manuscript(), the gee_custom strategy, the
process-level time limit, the profile confidence intervals of the mixed
model (Wald intervals are reported).gee_vcov(fit, "fg") is now the correction of Fay and Graubard (2001)
as published and as implemented in geesmv: the multiplier
(1 - min(b, Q_jj))^(-1/2) is applied also where Q_jj is negative.
Version 0.1.0 truncated Q_jj at 0, which inflated Fay-Graubard
standard errors by up to about a quarter with 10 clusters.R/mmm.R: the marginalized multilevel model (latent variable with a
linear trend of its standard deviation in the occasion index, first-order
transition term, Gauss-Hermite quadrature) with the convergence check of
the study. On the fixture datasets it reaches the optimum of MMLB::mm
along the same path: estimates agree to 1.6e-10 (relative), standard
errors to 2.4e-7 and log-likelihoods to 7.4e-12 (tests/testthat/fixtures).fewclust_control(check_coherence = TRUE), the default): a trend fit
whose log-likelihood lies below that of its own sub-model without the
trend is a false optimum and is treated as not converged.
check_coherence = FALSE gives the published two-condition rule.time among its
distinct values), so the threshold of the check is per occasion whatever
the unit of time; the mean model uses time as given. A mean-model
column whose standard deviation lies outside [0.1, 10) is rescaled by a
power of ten for the optimiser and mapped back.NA statistic, p-value and interval, with a note; a fit
with no usable coefficient fails, and the automatic path then falls back
to Fay-Graubard and records it.time must be distinct within a group (error otherwise); the number of
occasions is the longest series (the design maximum of the study); a
caution says when the distinct values of time are not equally spaced
and when incomplete rows were dropped; a single observation per group,
and an outcome that varies in a single group, are refused.Initial release.