crossStatR: An Introduction

library(crossStatR)
library(ggplot2)

Development validation

This vignette accompanies development version 0.99.2. The benchmark covers selected configurations, and the validation study uses 100 datasets per metric with 99 resampling draws. These small simulations provide diagnostics; they do not establish general statistical calibration. The local study observed 24% peak false positives, 10% peak detection, 74.9% transfer interval coverage, and 43% drift interval coverage in the tested scenarios. These results limit inferential use of these methods. Report sources are scripts/benchmark.R and scripts/validate.R.

What crossStatR is for

crossStatR is a statistics toolkit for bench scientists who work with quantitative experimental data: enzyme kinetics, dose-response curves, cyclic voltammetry, UV-Vis and Raman spectra, calibration curves, exponential decay experiments. The package collects the methods bench scientists reach for repeatedly, with three commitments that guide its design.

The package is conservative by default. It does not silently remove observations, it does not pick a hypothesis test on the basis of a normality-test p-value, and it distinguishes biological from technical replicates in its variance models. Pre-testing for normality and switching tests on the result inflates Type I error (Rochon, Gondan and Kieser, 2012); pseudo-replication produces confidence intervals that are far too narrow (Vaux, Fidler and Cumming, 2012). crossStatR avoids both by construction.

The package separates biological and technical variation. When the analyst supplies sci_describe() which column identifies biological replicates and which identifies technical replicates, the function averages technical replicates within each biological unit before computing summary statistics. The reported n then refers to biological replicates.

The package documents its own limitations. Every function carries a Limitations section in its help page, and the Category C methods (the advanced uncertainty-attribution tools) are explicit about when their assumptions break.

Installation

The development version can be installed from R-universe:

install.packages(
  "crossStatR",
  repos = c(
    rotsl = "https://rotsl.r-universe.dev",
    CRAN = "https://cloud.r-project.org"
  )
)

Alternatively, GitHub installation uses remotes:

install.packages("remotes")
remotes::install_github("rotsl/crossStatR")

The package depends on stats, MASS, Matrix, lme4, and ggplot2 (all on CRAN). nortest is suggested for Anderson-Darling normality testing but is not required.

A quick example

Suppose the analyst has a small dose-response dataset with biological replicates and two technical replicates per biological unit. The honest analysis averages the technical replicates within each biological unit first.

set.seed(1)
df <- data.frame(
  y = rnorm(60, mean = rep(c(8, 10, 12), each = 20)),
  dose = rep(c("low", "mid", "high"), each = 20),
  bio = rep(1:6, each = 10),
  tech = rep(1:10, times = 6)
)
desc <- sci_describe(df$y, group = df$dose,
                     bio_rep = df$bio, tech_rep = df$tech)
print(desc)
#> <crossStatR::describe> Descriptive statistics (bio-replicate level)
#> Total observations: 60  Biological replicates: 6
#>  group n      mean          sd          var          se    median         mad
#>   high 2 12.138797 0.006590359 4.343284e-05 0.004660088 12.138797 0.006909046
#>    low 2  8.190524 0.082478483 6.802700e-03 0.058321095  8.190524 0.086466855
#>    mid 2  9.993528 0.179890402 3.236056e-02 0.127201723  9.993528 0.188589275
#>           cv         iqr mean_ci_low mean_ci_high median_ci_low median_ci_high
#>  0.000542917 0.004660088   12.079585    12.198009            NA             NA
#>  0.010069989 0.058321095    7.449484     8.931564            NA             NA
#>  0.018000689 0.127201723    8.377277    11.609780            NA             NA
#>  n_missing
#>          0
#>          0
#>          0

The reported n per dose is the number of biological replicates after collapsing the technical replicates. Compare with the naive call that ignores the replicate structure:

naive <- sci_describe(df$y, group = df$dose)
print(naive)
#> <crossStatR::describe> Descriptive statistics
#> Total observations: 60  Biological replicates: n/a
#>  group  n      mean        sd       var        se    median       mad
#>   high 20 12.138797 0.8097234 0.6556520 0.1810597 12.114387 0.7888802
#>    low 20  8.190524 0.9132537 0.8340324 0.2042097  8.359676 0.7751822
#>    mid 20  9.993528 0.8713652 0.7592774 0.1948432  9.945033 0.6786950
#>          cv      iqr mean_ci_low mean_ci_high median_ci_low median_ci_high
#>  0.06670541 1.029953   11.759835     12.51776     11.387974      12.696963
#>  0.11150126 1.143400    7.763108      8.61794      7.378759       8.821221
#>  0.08719295 1.055129    9.585717     10.40134      9.585005      10.763176
#>  n_missing
#>          0
#>          0
#>          0

The naive call reports n = 20 per group, which is misleading. The standard errors are too small by roughly a factor of \sqrt{2} because the within-bio correlation has been ignored. This is the standard pseudo-replication failure mode and the reason sci_describe() asks for the bio_rep argument.

A two-group comparison uses sci_compare() with the test the analyst can defend a priori. The default is Welch’s t; the documentation recommends Welch over Student in essentially all experimental settings because Student’s pooled-variance assumption rarely holds for real measurements and the Welch loss of power is small (Ruxton, 2006).

x <- rnorm(12, mean = 10)
y <- rnorm(12, mean = 11)
sci_compare(x, y, test = "welch")
#> <crossStatR::compare> Comparison: welch
#> statistic = -0.8885,  p = 0.385555
#> effect (mean(x) - mean(y)) = -0.3692
#> Effect sizes:
#>      name   estimate        se    ci_low   ci_high
#>   Cohen_d -0.3627359 0.4212777 -1.188425 0.4629532
#>  Hedges_g -0.3502278 0.4210466        NA        NA

Function catalogue

crossStatR ships 32 functions across three categories. See the individual help pages for the mathematical details.

Category Function Purpose
A sci_describe Descriptive stats with bio/tech replicate separation
A sci_normality Shapiro-Wilk or Anderson-Darling with caveats
A sci_outliers IQR / MAD / z-score / robust-z flagging (no removal)
A sci_compare Welch / Student / permutation / Wilcoxon two-sample tests
A sci_anova ANOVA with effect sizes, Welch option, Tukey HSD
A sci_regression OLS / WLS / robust / nonlinear with measurement weights
A sci_correlation Pearson / Spearman / Kendall with Fisher-z CIs
A sci_bootstrap Nonparametric / parametric / cluster / stratified bootstrap
A sci_power Power and sample size with optional simulation check
A sci_effect_size Cohen’s d, Hedges’ g, paired d_z, r, partial eta-squared
B adaptive_baseline Asymmetric least squares or lowess baseline
B weighted_peak_fit Multi-peak NLS with Gaussian / Lorentzian / pseudo-Voigt
B adaptive_smoothing Savitzky-Golay / spline / lowess with PRESS window choice
B replicate_decompose Variance components via lme4::lmer REML
B drift_correct_stat Linear / polynomial / exponential drift with delta-method SE
B robust_lod Currie / blank-SD / Hubaux-Vos LOD with Monte Carlo CI
B calibration_compare ANCOVA comparison of two calibration curves
B curve_similarity L2 / L1 / DTW / correlation curve distance with CI
B kinetic_model_compare AIC/BIC comparison of candidate kinetic models
B spectral_change_test Hotelling T^2 / PERMANOVA / pointwise t for spectra
B noise_characterize Noise SD, ACF, heteroscedasticity, PSD, signal-dependence
B parameter_uncertainty Delta method / Monte Carlo / bootstrap propagation
B timepoint_optimize D / A / C / discrimination-optimal sampling times
B batch_effect_quantify LMM or fixed-effect batch variance decomposition
C signal_difference_regions Simultaneous confidence bands for curve differences
C peak_evidence Likelihood-ratio peak evidence with permutation null
C calibration_transfer_risk Transfer prediction error and OOD detection
C kinetic_discrimination Pre-experimental model discrimination probability
C experiment_fragility Sensitivity of results to analysis decisions
C drift_uncertainty Variance attribution to drift via bootstrap
C detection_reliability Concentration-dependent PD / FPR / FNR curves
C uncertainty_origin Shapley-style stage-wise uncertainty attribution

Category A covers standard inferential and descriptive statistics, wrapped with conservative defaults, effect-size reporting, and bio/tech replicate handling. Category B contains domain-specific signal-processing and calibration tools that overlap with packages like signal, pracma, chemCal, and driftR but are unified under the crossStatR calling convention. Category C contains eight diagnostic methods for signal comparison, calibration transfer, kinetic discrimination, fragility, detection, and uncertainty attribution. Their underlying statistical concepts overlap with established methods; no general claim of originality is made.

Where to go next

Domain vignettes: Biological Experiment Statistics, Electrochemical Measurement Statistics, Optical Spectroscopy Statistics, Experimental Physics Statistics, Advanced Uncertainty Attribution.

References

  • Rochon, J., Gondan, M. and Kieser, M. (2012). To test or not to test: Preliminary assessment of normality when comparing two independent samples. BMC Medical Research Methodology, 12, 81. Source.

  • Ruxton, G. D. (2006). The unequal variance t-test is an underused alternative to Student’s t-test and the Mann–Whitney U test. Behavioral Ecology, 17, 688-690. Source.

  • Vaux, D. L., Fidler, F. and Cumming, G. (2012). Replicates and repeats—what is the difference and is it significant? The EMBO Reports, 13, 291-296. Source.