NEWS
RChiSquare 1.1.0
User interface (closer to base R)
- Results print as a compact report like
chisq.test(); the reject
column is no longer shown (it remains in the object). summary() adds
fitted parameters and the cells.
- New
chi_cells() returns the final cells of any test with observed and
expected counts, Pearson residuals and each cell's contribution to the
statistic, with the same columns for every data type and dimension.
- New
as_htest() converts a result to a standard htest object.
- A null distribution can be given by name, as in
ks.test():
chi_test(x, "pnorm", mean = 0, sd = 2). Estimated parameters are named
in phat (phat = c("mean", "sd")) or by a named pstart; moment-based
starting values are supplied for the common families. For distributions
with a lambda parameter ("ppois"), lambda is that parameter.
The same works in chi_power(), chi_sample_size() and compare_power().
chi_test(x, p = ...) tests categorical data (character, factor or a
table) against category probabilities, as chisq.test() does; merged
categories are labelled by their members.
- Formula interface for two-sample tests:
chi_test(cbind(long, lat, depth) ~ mag >= 4.6, data = quakes).
- New
partition = c("both", "ES", "EP") in chi_test() and
chi_power() reports one partition only. The documentation warns against
choosing the partition after seeing both p-values.
- Missing values are removed with a message.
- Snake-case argument names. The former names are still accepted:
range replaces Range and Ranges (a length-2 vector applies to every
coordinate of multidimensional data);
p_method replaces p.method, B_permutation replaces B.permutation;
cores replaces maxProcessor, parallel_threshold replaces
parallel.threshold;
- in
chi_sample_size(), power replaces target_power and partition
replaces bin_type.
- Power results, power curves and sample sizes print compactly, in the style
of
power.t.test().
Parametric bootstrap p-values for goodness-of-fit
chi_test(..., p_method = "bootstrap") computes goodness-of-fit p-values
by a parametric bootstrap: B samples (default 999) of the observed size
are drawn from the fitted null, and the complete test (estimation, cell
construction, merging, minimum-divergence fit) is repeated on each. This
avoids the chi-square approximation and the question of its degrees of
freedom with estimated parameters and data-dependent cells. For a fully
specified null it is a Monte Carlo test. The ES and EP tests are each
calibrated under their own fitted null. The asymptotic p-values are kept
in attr(result, "asymptotic_p").
- Null samples are generated automatically for a null given by name
(
"pnorm" uses rnorm), a PMF with support or p, one-dimensional
continuous data (inverse transform via qnull or pnull) and
one-dimensional integer data with a CDF; otherwise supply
rnull(n) or rnull(n, theta). cores parallelizes the bootstrap.
chi_power(..., method = "simulation", p_method = "bootstrap") estimates
the power of the bootstrap test with 2B instead of B^2 complete tests: the
null distribution of the statistic is simulated once (for a composite
null, from the member closest to the alternative, separately for ES and
EP), and each test under the alternative rejects when its bootstrap
p-value against these null statistics is at most alpha. The result
includes the estimated critical_value.
Analytic power: automatic reference data
B now sets only the number of simulation replications. Analytic power
without an alternative CDF/PMF estimates the alternative cell
probabilities from reference data whose size is chosen automatically in
every routine, by the rule already used for continuous 1D goodness-of-fit:
a pilot of 10,000 observations gives the largest cell variance v, and the
reference is enlarged to max(10,000, 1.25 v / 0.001^2) observations (per
sample for two-sample problems, at most 500,000), so each cell probability
has a standard error of about 0.001.
- Where the test's partition depends on the data (two-sample and
multidimensional tests), power is averaged over the partitions of
successive reference data sets, from 20 until the Monte Carlo standard
error of the average is below 0.002 (at most 200).
- Before, these routines used
B reference data sets (the default 1,000,
or fewer if B was reduced to save time) and up to 200 or B
partitions. Analytic power values therefore change slightly; with a
small B they could be noticeably off (for example 0.655 instead of
about 0.70 for a discrete two-sample example with B = 200, simulated
power 0.697).
- Reference data sets are drawn from indexed random-number streams, so the
results are reproducible with
seed and independent of how many data
sets are drawn.
Changes that can break existing code
- Analytic power no longer depends on
B (see above); values differ
slightly from earlier versions.
- Discrete multidimensional goodness-of-fit tests now return a named vector,
like the other discrete tests, instead of a one-row matrix. Code such as
res[1, "p.value"] must become res[["p.value"]] or res["p.value"].
- Printing a result no longer shows its attributes; use
attributes(),
summary() or chi_cells().
RChiSquare 1.0.5
Bug fixes
- Analytic power for multidimensional discrete goodness-of-fit tests with a
composite null now uses the population minimum-Pearson projection on each
reference partition. Before, it used each reference sample's own fitted
parameters, which added estimation noise to the noncentrality: under the
null it gave about 0.12 instead of 0.05, and it overstated power under
alternatives. It now also reports
power_scaled_ncx2 and uses the same
fixed-alternative approximation as the other routines.
- In GOF power curves, alternative functions (
alt_cdf, alt_pdf, pmalt)
receive the scenario parameters by name when their formals match the
generator's (e.g. generator function(size, mu) with alt_cdf(z, mu)).
A parameter received by the generator's n is never passed to the
alternative function. Otherwise parameters are still appended by position.
compare_power() plots the recommended analytic power, which is always
available, instead of the scaled noncentral chi-square, which is missing
when moment matching is infeasible. The plot data contain both.
- Duplicated and contradictory
B documentation was corrected in the
discrete power routines.
summary() of a test result no longer prints an empty "Final fitted
parameters" section for a fully specified null. Summaries round values to
four significant digits and print fitted parameters under their names.
- A null CDF/PMF with parameter arguments that have no default values now
requires
phat or pstart, with a clear message. pstart is accepted by
every goodness-of-fit test and power routine.
chi_power() uses the same default number of bins as chi_test().
chi_sample_size() has no fixed default seed (seed = NULL draws one from
the current stream), and requires rxy to take the sample size as an
argument (n, or its first argument without a default).
chi_test() has a seed argument for permutation p-values.
- Seeded scalar two-sample power is now fully reproducible: the first
generated dataset was drawn from the unseeded stream.
- Estimated alternative cell probabilities are corrected for their
first-order bias in all analytic power routines.
Consistency across routines
chi_power(bins = ...) now works for all continuous routines (it was
documented but always failed).
- All two-sample power routines support
method = "both" and permutation
calibration (p.method, B.permutation) for simulated tests.
maxbins is available in the continuous 1D two-sample test and power, and
is accepted as the name of nbins in discrete 1D two-sample power.
pdf/pmnull and alt_pdf/pmalt are accepted under either name.
- Discrete goodness-of-fit analytic power no longer requires
alt_cdf or
alt_pdf: as for continuous data, alternative probabilities are estimated
from reference samples.
- All power routines report
valid_fraction, n_invalid and power_valid;
continuous MD two-sample power also reports K and df.
- Removed the unused duplicates
make_bins_cont_gof() and
make_bins_cont_2sample().
Noted, not changed
- Discrete two-sample tests merge cells until the pooled count reaches
minexpcount (the documented R2sample convention). Continuous two-sample
tests require the smaller sample's expected count to reach minexpcount.
RChiSquare 1.0.4
Bug fixes
- Continuous 1D two-sample power now passes
n and m to generators that
declare them (function(n, m)). Before this, such generators failed, and
generators with default sizes silently ignored the requested n and m.
- Unnamed scenario parameters (
par1/par2) are no longer matched by
position to the sample-size arguments n and m of a two-sample
generator. A parameter with no argument to receive it is now an error;
before, it was silently dropped.
- Analytic power for continuous MD two-sample tests now takes the alternative
cell probabilities from the pooled reference data. Before, it plugged each
reference dataset's own observed proportions into the noncentrality, which
inflated power: under the null it gave about 0.5–0.65 instead of 0.05.
- Analytic continuous 1D two-sample power now merges cells with the same rule
as the test (smaller-sample expected count). Before, it evaluated a finer
partition than the test uses.
- Analytic MD goodness-of-fit power:
- no longer depends on a single random sample;
- uses the population minimum-Pearson projection for composite nulls;
- averages over the data-dependent partitions of the reference samples;
- uses the same fixed-alternative approximation as the 1D routines.
- Analytic 1D goodness-of-fit power with a known
alt_cdf and a composite
null now estimates the starting parameters from a large reference sample,
not from a single sample of size n.
- When the scaled noncentral chi-square cannot match the two moments, the
recommended analytic power now uses a Satterthwaite scaled central
chi-square instead of the normal approximation. The normal approximation
was badly calibrated near the null (for example 0.030 instead of 0.05).
- Seeded simulations no longer leave the global RNG in L'Ecuyer-CMRG with a
changed
.Random.seed. Without seed, a seed is drawn from the caller's
RNG, so results are reproducible after set.seed() and do not depend on
the number of workers. The pilot replication is no longer discarded.
- Scalar GOF power infers
n correctly from frequency-table generators
(cbind(vals, x), data frames, tables).
pmnull alone now selects a goodness-of-fit problem in chi_power() and
chi_sample_size().
chi_power():
- without
method, uses simulation for non-Pearson families instead of
failing;
- infers
n and m from two-sample generators with default sizes.
- GOF power curves with fewer alternatives than workers now parallelize
replications, as the scheduler intended.
chi_sample_size(method = "simulation"):
- searches outward from the analytic estimate;
- still runs when analytic power is unavailable.
- Custom
bins accept Range = NULL, as documented.
- Repeated identical MD grids (for example
nbins = c(5, 5)) are evaluated
once instead of producing duplicate rows.
- Nelder–Mead parameter fits restart once if they hit the iteration limit.
Other changes
- Multidimensional GOF cell probabilities evaluate each grid vertex once;
results are unchanged and MD tests and simulations are several times
faster.
graphics, utils and parallel are declared in Imports.
- Documentation corrections for
test_cont_MD_2sample() (merging rule,
supported dimensions), test_cont_MD_gof() and power_cont_1D_2sample().