Tests menu, correlation matrix and data tools — build .119
Build .119 fixes what the audits of the Tests ▾ methods found when they compared the page with R 4.3 and with the
Stata and R commands it logs. Code: src/analysis-suite.js (packets, commands, Apply), src/engine/** (the
built-in engine), src/analysis-methods.R (the R specification the engine is checked against), and
src/regression-guide.js and src/correlation-matrix.js.
Groups keep their code order
- A category is sent to the engine with its levels in code order:
- numeric codes 2, 3, 10 stay in that order (before, they sorted as text: 10, 2, 3);
- a labelled code sorts by its code, not its label (1 = Republican comes before 2 = Democrat);
- text keeps byte order, which is what Stata’s
encodeuses.
- This is what R’s
factor()on the codes and Stata’si.give. Several results depended on it:- goodness-of-fit expected shares;
- the sign of two-group differences (proportions, Mann–Whitney);
- Dunnett’s default control;
- Tukey row names;
- every base level in models (Cox, mixed, GLMM, panels, survival, imputation, multinomial).
- The Setup page shows the order next to the boxes that depend on it: expected shares, contrasts and the Dunnett control.
- The goodness-of-fit Counts table has a Category column.
Results that changed
- Degenerate inputs are refused with a plain message instead of P = 0. This covers an outcome with no variation in a two-proportion test, Kruskal–Wallis or Friedman. A NaN chi-square statistic now gives NaN.
- McNemar applies the continuity correction only when the two discordant counts differ, as
mcnemar.testdoes. - Fisher’s exact test on tables larger than 2 × 2 is now exact.
- It uses the network algorithm, as R’s FEXACT does. A 4 × 4 table matches
fisher.testto 1e-9. - Simulation (100,000 tables) is only a fallback for very large tables, and its note no longer claims R would fail.
- Typed (summary) tables may now be larger than 2 × 2.
- It uses the network algorithm, as R’s FEXACT does. A 4 × 4 table matches
- Signed-rank interval: when the requested level cannot be reached with few pairs, the interval uses the level R reaches and shows R’s warning “requested conf.level not achievable”. Before, it showed [min, max] labelled 95%.
- Repeated-measures ANOVA and Friedman:
- Subjects without a value in every condition are left out, with a note. Before, one missing value stopped the whole analysis.
- The F test and the Greenhouse–Geisser and Huynh–Feldt corrections are on the Results tab.
- Kaplan–Meier median (Checks): the lower and upper limits were swapped. A curve sitting exactly at 0.5 now
averages with the next time it drops, not with a censoring time (
quantile.survfit). - Parametric survival (survreg) shows its coefficient table on Results.
- Probit:
- It takes a Yes/No outcome as R’s
glmdoes: the first category is 0, the second 1, and a note says so. - Other outcomes that are not 0/1 get a plain message instead of R’s internal one.
- It takes a Yes/No outcome as R’s
- Mixed logistic / Poisson / negative binomial (GLMM):
- The inner fit now converges tightly, as lme4 2.x does. Ordinary data no longer get a false “did not converge”.
- The log likelihood equals lme4 2.1’s. Before, it fell 1e-5 to 7e-4 short.
- Survey pages with the IF bar / subgroup:
- They work now. Before, they failed with “design variables must be nonmissing”.
- The subgroup is the domain, as in
svy, subpop()andsubset(des, …). The older Settings filter drops rows, askeep ifdoes in the do-file. - The design fields filled from Settings follow later Settings changes.
- Power: the note says what n means for the chosen design (per group, pairs, or neither).
- Display:
- p-values below 2.2e-16 read “< 2e-16”.
- R’s column names read as words (At risk, Difference (contrast)).
- Long DF strings are rounded.
- “two.sided” reads “Two-sided test.”
- The Regression page shows engine warnings, a BIC that does not exist shows “—”, and the interval header follows the level.
The logged Stata and R commands
- Categorical predictors are encoded and entered as
i.in Stata, and asfactor()in R, for every model. This covers probit, mlogit, nbreg, qreg, zinb/zip, mixed, melogit, xtreg, streg, Cox, the penalised models, Tukey, Dunnett and the ANOVAs. - mlogit uses
baseoutcome()with the page’s base category. A text outcome is encoded first. - The subgroup
ifgoes on each estimation line:- before
||in mixed models; - after a prefix (
bootstrap …:,mi estimate:); - never in a comment or on an
encodeline.
The Regression page’s “Copy Stata / R command” now includes the subgroup too.
- before
- The confidence level is carried as
level()/conf.level. - Missing values: the R commands drop incomplete rows the way the page does. This affects proportions,
binomial, PCA, EFA, k-means, trees, splines, GAM, Friedman and repeated measures, and adds
na.rm = TRUEto survey means. - Factorial ANOVA and ANCOVA:
- Type III sets sum contrasts.
- Interactions follow the checkbox.
- Stata’s partial sums of squares are noted.
- Mixed models:
REML = FALSEwhen ML is chosen. - Real commands replace comment lines for:
- glmm (
glmer/glmer.nb); - panels (
plm+coeftestwith HC1 and G − 1 df); - permutation (
coin::independence_test, Statapermute); - repeated measures (
aovwithError()); - spline, GAM, hierarchical clustering and trees;
- Dunnett (
multcomp, Statapwcomparewith the chosen control); - pairwise tests.
- glmm (
- Differences that remain are stated in comment lines:
- quantile regression standard errors (R’s nid vs Stata’s iid);
- nbreg alpha vs theta;
- k-means starts;
- cluster small-sample factors.
- Correlation matrix: Spearman on complete rows uses
na.omit(), becausecorr.test(use = "complete")still counts n pairwise.
Data tools: Merge, Append, Reshape, Duplicates
- Apply builds the new dataset directly instead of round-tripping it through CSV:
- text codes such as “001” stay text;
- variable labels, value labels and types follow their variables;
- the weight and C/N choices of surviving variables are kept;
- the message names what was reset (filter, subgroup, a weight that no longer exists).
- Names are valid in Stata: merge suffixes are
_x/_y, and wide columns arey_2019. - Apply is logged with the real commands:
- merge:
merge 1:1 / m:1 / 1:m(joinbyfor many-to-many), with the renames and thekeep()for the join type; R’smerge(…, suffixes = c("_x", "_y")); - append:
append/rbind; - reshape long and wide:
reshape long … string/reshape wide, and R’sreshape; - duplicates:
duplicates list/tag, and R’sduplicated.
A preview is no longer logged.
- merge:
- Merge reports matched, master-only and using-only rows (Stata’s
_merge). A key that is a number in one file and text in the other is refused, as Stata does, instead of silently matching nothing. - Reshape wide keeps variables that are constant within a subject. Varying ones are left out with a note.
- Pasted rows for Merge and Append may start with a header line, so a pasted second dataset can bring its own variables.
- Holdout predictions number rows as Analysis.row (the row within the complete cases), as clustering does.
Validation
- Engine reference cases: the R outputs were regenerated where the specification changed, and the JS engine
matches all 510 cases.
- Regenerated: proportions, goodness of fit, Kruskal–Wallis, Friedman, repeated measures, power, survival, data management.
- GLMM uses lme4 2.1. Three near-flat fits carry a tolerance; one fit with a correlation of 0.9999998 skips its standard errors.
tests/audit119.test.mjschecks the page against R ontests/data/audit119.csv(tests/r/audit119-reference.R):- the goodness-of-fit statistic with codes 2/3/10;
- the 4 × 4 Fisher p;
- the signed-rank level;
- the KM median limits;
- probit with Yes/No;
- the survey domain mean, SE and t;
ifplacement;- the commands;
- Apply and reshape wide.
