Computational Provenance & Reproducibility Record

RAISINS - R and AI Solutions for INferential Statistics · Online Statistical Analysis Platform for Agricultural Research

Computational Provenance & Reproducibility Record Scott-Knott Clustering · 1.0.0 · DOI 10.5281/zenodo.24737739

Computational Provenance & Reproducibility Record

RAISINS · Scott-Knott Clustering Module

This Computational Provenance Record documents the statistical computing environment, software dependencies, computational provenance, and bibliographic references associated with the RAISINS Scott-Knott Clustering module. It is intended to support computational reproducibility and software transparency. Detailed statistical methodology, mathematical derivations, and user guidance are provided separately in the official module documentation.

Any issues or updates required please comment here

Go to the App from here

1 Module Metadata

Parameter Specification
Module Scott-Knott Clustering
Module Version 1.0.0
DOI 10.5281/zenodo.24737739
Document Type Computational workflow
Statistical Engine R
R Version 4.5.2
Experimental Designs Completely Randomized Design (CRD) and Randomized Block Design (RBD)
Reproducibility Execution Environment: Posit Connect · GCR · renv-locked

2 Statistical Dependency Manifest

Package Version Repository Core Statistical Functions
stats 4.5.2 Base R lm(), anova(), qchisq(), pchisq(), sd(), shapiro.test()
ScottKnott 1.4-0 CRAN SK(), summary() method for SK objects
gtools 3.9.5 CRAN mixedsort()

3 Statistical Function Registry

Analytical Role Primary Function(s)
ANOVA (CRD) stats::anova(stats::lm(y ~ treatment)), one model per response
ANOVA (RBD) stats::anova(stats::lm(y ~ block + treatment)), one additive model per response
Scott-Knott clustering ScottKnott::SK(y ~ treatment, which = "treatment", sig.level = α) (CRD) or ScottKnott::SK(y ~ block + treatment, which = "treatment", sig.level = α) (RBD)
Group letters Read from the group columns (G1, G2, …) of summary() of the SK object
Partition-step statistics B, σ̂², λ, χ² df, critical value and p-value of every tested cluster, recomputed with the ScottKnott splitting rules; stats::qchisq(), stats::pchisq()
Treatment means and SDs tapply(y, treatment, mean), tapply(y, treatment, stats::sd)
Summary statistics Mean, SD, SE, minimum, maximum, CV(%), skewness (m₃ / m₂1.5) and kurtosis (m₄ / m₂²) by treatment
Residual normality stats::shapiro.test() on residuals of the fitted design model
Equal treatment variances Median-based Levene (Brown–Forsythe): stats::anova(stats::lm(abs(residual − treatment median residual) ~ treatment))
Treatment ordering gtools::mixedsort() where the results table order is unavailable

4 Default Methods & Parameters

Analysis Step / Parameter Default Method / Value
ANOVA Model CRD: y ~ treatment. RBD: y ~ block + treatment (additive; no treatment × block interaction). Treatment and block are taken as factors; one model is fitted per response variable
Design requirement At least two treatments. CRD allows unequal replication. RBD needs at least two blocks, and every treatment must occur exactly once in every block
Missing values Rows with a missing response, treatment or block are omitted for that response only (na.omit); responses that fail the data checks are excluded as whole columns and listed to the user
Error mean square (MSE) Residual mean square of the fitted model; used by the Scott-Knott test and the partition statistics
Coefficient of variation CV(%) = sqrt(MSE) / grand mean × 100
Significance & rounding Significance level (α) 0.05 default (user-selectable: 0.05, 0.01); passed to SK(sig.level =)
Significance stars ** for p ≤ 0.01, * for p ≤ 0.05, NS otherwise (fixed thresholds, independent of the selected α)
P-value display Threshold labels p < 0.001, p < 0.01, p < 0.05, otherwise the rounded value. The Show original numerical p-values option displays the computed p-value to up to 16 significant digits
Rounding 2 decimal places default (user-adjustable, 1–10)
Scott-Knott clustering
(ScottKnott)
Method Scott & Knott (1974): treatment means are ordered and recursively divided into two groups at the split that maximises the between-group sum of squares B; a split is accepted when the likelihood-ratio statistic λ reaches the χ² critical value at α
Inputs to the test The same formula, data and residual error as the ANOVA; which = the treatment factor; sig.level = α
Grouping display Groups are disjoint: each treatment receives exactly one letter. Letters are shown only when the treatment F test has p ≤ α; otherwise no letters are given
Display options Mean ± SD (sample SD within each treatment) on by default; letters shown by default and placed after the SD (option: next to the mean)
Partition steps
(one row per tested cluster)
Split statistic B = n₁ȳ₁² + n₂ȳ₂² − (n₁ + n₂)ȳ², where n₁, n₂ count treatment means; the first maximum of B is used
Variance estimate σ̂² = [Σ(ȳᵢ − ȳ)² + v · s²ȳ] / (k + v), with k means in the cluster, v the error df and s²ȳ the mean of MSE / rᵢ over the cluster
Test λ = π / (2(π − 2)) · B / σ̂², compared with χ² on k / (π − 2) df; p-value pchisq(λ, df, lower.tail = FALSE)
Recursion Depth-first: if λ ≥ critical value both groups are tested again (higher-mean group first); otherwise the cluster is final. Single treatments are not tested
Summary statistics Columns Mean, SD, SE = SD / √n, Min, Max, CV(%) = SD / Mean × 100, Skewness, Kurtosis; by treatment for each response, on finite values
Moments Skewness m₃ / m₂^1.5 and kurtosis m₄ / m₂² (population moments; kurtosis is 3 for a normal distribution). Values that cannot be computed are shown as “-”

5 Assumptions Tables

Checks use the residuals of the model fitted by the ANOVA: response ~ treatment (CRD) or response ~ block + treatment (RBD). Compare test p-values with the selected significance level. A nonsignificant result does not establish that an assumption holds; independence depends on the experimental design and randomisation.

Table or check Calculation and reported fields Interpretation and limits
Data for diagnostics Finite numeric responses with complete treatment (and block) labels Excluded observations are counted and disclosed. Both checks are marked unavailable, with a reason, when there are fewer than two treatments (or blocks for RBD) or no residual degrees of freedom.
Residual normality Shapiro–Wilk on the model residuals; response, n, W, p-value and finding Requires 3–5000 residuals with non-negligible variation; unavailable or failed checks show a reason.
Equal treatment variances Brown–Forsythe (median-based Levene): one-way ANOVA of abs(residual - median(residual within treatment)) across treatments; response, n, F, p-value and finding For CRD this equals the median-centred Levene test on the responses. For RBD the deviations are formed from block-adjusted residuals, so the p-value is an approximate screen. Insufficient variation is reported rather than interpreted as a pass.
Suggested next steps One response-specific guidance row based on the findings and the response type No transformation is applied automatically; the module has no transformation option. Rerun the full analysis after any whole-response change.
Numerical p-value option Threshold display by default; original computed p-values can be displayed to up to 16 significant digits Display changes do not alter the hypothesis tests.
Report contents HTML, PDF and Word contain the test table, notes and suggested next steps Residual Q–Q and residuals-versus-fitted plots have their own download controls and are excluded from the table report.

These diagnostics do not test treatment × block interaction. Residual plots support interpretation but do not certify normality, variance equality or independence.

6 R Code for Key Analytical Steps

The code blocks below demonstrate the computation behind each reported result using two datasets that ship with R: chickwts (from datasets), a completely randomized design in which chicks were fed 6 feed supplements with unequal replication (10–14 chicks per feed), and immer (from the MASS package), Immer’s barley trial, a randomized block design with 5 varieties grown at 6 locations acting as blocks.

6.1 ANOVA and Scott-Knott Clustering (CRD)

d   <- datasets::chickwts                        # 6 feeds, unequal replication
dfm <- data.frame(y = d$weight, x = factor(d$feed))
alpha <- 0.05                                    # default significance level

# One-way model; the module fits one model per response variable
fit   <- lm(y ~ x, data = dfm)
anova <- anova(fit)
anova                                            # treatment F = 15.36, p = 5.94e-10
MSE   <- anova["Residuals", "Mean Sq"]           # 3008.55
dferr <- anova["Residuals", "Df"]                # 65
sqrt(MSE) / mean(dfm$y) * 100                    # CV(%) = 20.99

# Scott-Knott clustering on the same model
sk <- ScottKnott::SK(y ~ x, data = dfm, which = "x", sig.level = alpha)
summary(sk)
# sunflower 328.92 a | casein 323.58 a | meatmeal 276.91 b
# soybean 246.43 c   | linseed 218.75 c | horsebean 160.20 d

# Letters are reported only when the treatment F test is significant:
anova["x", "Pr(>F)"] <= alpha                    # TRUE

6.2 Partition-Step Statistics (first split)

The module reports B, σ̂², λ and the χ² decision for every cluster tested. The first split of the example is reproduced below; the same λ is stored by ScottKnott in sk$stat[1, 1].

means <- sort(tapply(dfm$y, dfm$x, mean), decreasing = TRUE)
reps  <- as.numeric(table(dfm$x)[names(means)])
k     <- length(means)

# Between-group sum of squares for every split into two contiguous groups
B <- sapply(1:(k - 1), function(k1) {
  t1 <- sum(means[1:k1]); t2 <- sum(means[(k1 + 1):k])
  t1^2 / k1 + t2^2 / (k - k1) - (t1 + t2)^2 / k
})
best   <- which.max(B)                           # split after "meatmeal"
sigma2 <- (sum((means - mean(means))^2) + dferr * mean(MSE / reps)) / (k + dferr)
lambda <- pi / (2 * (pi - 2)) * B[best] / sigma2
df_chi <- k / (pi - 2)
crit   <- qchisq(alpha, df_chi, lower.tail = FALSE)
c(B = B[best], sigma2 = sigma2, lambda = lambda, df = df_chi, critical = crit)
# B = 15405.76, sigma2 = 529.83, lambda = 40.01, df = 5.26, critical = 11.46
pchisq(lambda, df_chi, lower.tail = FALSE)       # 2.0e-07 -> split; both groups tested again

6.3 ANOVA and Scott-Knott Clustering (RBD)

r   <- MASS::immer                               # 5 varieties x 6 locations (blocks)
dfr <- data.frame(y = r$Y1, x = factor(r$Var), blk = factor(r$Loc))

# Additive blocked model; every variety occurs once in every block
fit_r <- lm(y ~ blk + x, data = dfr)
anova(fit_r)                                     # treatment F = 4.23, p = 0.0121
                                                 # block     F = 21.89, p = 1.75e-07
sk_r <- ScottKnott::SK(y ~ blk + x, data = dfr, which = "x", sig.level = alpha)
summary(sk_r)
# T 127.40 a | P 109.75 b | V 103.47 b | M 102.58 b | S 102.03 b

6.4 Summary Statistics

x  <- dfm$y[dfm$x == "casein"]                   # one treatment of one response
n  <- length(x)
m2 <- mean((x - mean(x))^2)
c(Mean = mean(x), SD = sd(x), SE = sd(x) / sqrt(n), Min = min(x), Max = max(x),
  CV = sd(x) / mean(x) * 100,
  Skewness = mean((x - mean(x))^3) / m2^1.5,
  Kurtosis = mean((x - mean(x))^4) / m2^2)
# Mean 323.58, SD 64.43, SE 18.60, CV 19.91, Skewness -0.525, Kurtosis 1.935

6.5 Assumptions Checks: Residual Normality and Equal Treatment Variances

# CRD: residuals of the one-way model
res <- residuals(fit)
shapiro.test(res)                                # W = 0.9862, p = 0.6272
dfm$deviation <- abs(res - ave(res, dfm$x, FUN = median))
anova(lm(deviation ~ x, data = dfm))             # Brown-Forsythe F = 0.7493, p = 0.5896

# RBD: residuals of the additive block + treatment model
res_r <- residuals(fit_r)
shapiro.test(res_r)                              # W = 0.9624, p = 0.3568
dfr$deviation <- abs(res_r - ave(res_r, dfr$x, FUN = median))
anova(lm(deviation ~ x, data = dfr))             # Brown-Forsythe F = 0.6502, p = 0.6321

# Finding: "Review normality" / "Review variances" when p < alpha,
# otherwise "No issue detected".

Shapiro–Wilk needs 3–5000 residuals with non-negligible variation. A larger p-value does not prove that an assumption holds; independence must be assessed from the experimental design.

Explore the entire Scott-Knott Clustering module in preview mode using our demo datasets. To submit suggestions or report a workflow issue, visit the official RAISINS website.

Scope note. This record covers the statistical computations: ANOVA, Scott-Knott clustering and partition statistics, summary statistics and assumption checks. Plots (Basic Plots, Ranked Means, Dendrogram and Circle Packing), the written interpretation and the RA-One AI assistant present these results and are not covered here.

7 RAISINS Native Statistical Framework

RAISINS uses R for all its statistical computations. Principal statistical functions are listed with illustrative examples. Exact reproduction also requires the release source, input data, analysis settings and runtime environment. These results are then organized and formatted on the RAISINS website along with visualisation to make them easier to use and interpret. RAISINS also has its own custom-built statistical tools for managing workflows, validating results, and generating reports. Details of these are not fully covered here, they’re shared with outside researchers only on request, and are subject to licensing terms.

8 Package References

R Core Team. (2025). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/

Jelihovschi, E., Faria, J. C., & Allaman, I. B. (2014). ScottKnott: A package for performing the Scott-Knott clustering algorithm in R. Trends in Applied and Computational Mathematics, 15(1), 3–17. (R package version 1.4-0). https://doi.org/10.32614/CRAN.package.ScottKnott

Scott, A. J., & Knott, M. (1974). A cluster analysis method for grouping means in the analysis of variance. Biometrics, 30(3), 507–512. https://doi.org/10.2307/2529204

Warnes, G. R., Bolker, B., & Lumley, T. (2023). gtools: Various R Programming Tools (R package version 3.9.5). https://doi.org/10.32614/CRAN.package.gtools

Venables, W. N., & Ripley, B. D. (2002). Modern Applied Statistics with S (4th ed.). Springer. (MASS R package version 7.3-65). https://doi.org/10.32614/CRAN.package.MASS

Feedback & Discussion