{
  "name": "Gap statistic worked example: W(k), log W(k), reference expectation, gap and simulation error for k = 1 to 6",
  "description": "Computed for this page: k-means (best of 10 starts) on 15 two-dimensional points in three groups, squared Euclidean distances, B = 500 uniform reference data sets over the data's bounding box, NumPy seed 42. Gap = E*[log W(k)] - log W(k); s(k) = sqrt(1+1/B) times the standard deviation of the simulated log W(k), following the definitions in the R cluster package documentation.",
  "page": "https://casrai.org/guides/gap-statistic",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-19T17:43:12Z",
  "temporalCoverage": "2026",
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Number of clusters",
      "unit": "",
      "description": ""
    },
    {
      "name": "W(k)",
      "unit": "",
      "description": "Pooled within-cluster sum of squares"
    },
    {
      "name": "log W(k)",
      "unit": "",
      "description": ""
    },
    {
      "name": "E*[log W(k)]",
      "unit": "",
      "description": "Mean over 500 reference sets"
    },
    {
      "name": "Gap(k)",
      "unit": "",
      "description": ""
    },
    {
      "name": "s(k)",
      "unit": "",
      "description": "Simulation error"
    }
  ],
  "rows": [
    {
      "Number of clusters": "k = 1",
      "W(k)": 348.625,
      "log W(k)": 5.854,
      "E*[log W(k)]": 5.2759,
      "Gap(k)": -0.5781,
      "s(k)": 0.2091
    },
    {
      "Number of clusters": "k = 2",
      "W(k)": 120.813,
      "log W(k)": 4.7942,
      "E*[log W(k)]": 4.3477,
      "Gap(k)": -0.4466,
      "s(k)": 0.209
    },
    {
      "Number of clusters": "k = 3",
      "W(k)": 4.652,
      "log W(k)": 1.5373,
      "E*[log W(k)]": 3.824,
      "Gap(k)": 2.2867,
      "s(k)": 0.2401
    },
    {
      "Number of clusters": "k = 4",
      "W(k)": 3.456,
      "log W(k)": 1.24,
      "E*[log W(k)]": 3.3508,
      "Gap(k)": 2.1108,
      "s(k)": 0.2705
    },
    {
      "Number of clusters": "k = 5",
      "W(k)": 2.671,
      "log W(k)": 0.9826,
      "E*[log W(k)]": 2.949,
      "Gap(k)": 1.9664,
      "s(k)": 0.2963
    },
    {
      "Number of clusters": "k = 6",
      "W(k)": 2.402,
      "log W(k)": 0.8762,
      "E*[log W(k)]": 2.5862,
      "Gap(k)": 1.71,
      "s(k)": 0.3223
    }
  ],
  "sources": [
    {
      "title": "R cluster package manual: clusGap and maxSE",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/clusGap.html",
      "accessed": "2026-11-19"
    },
    {
      "title": "Tibshirani, Walther & Hastie (2001), JRSS B 63(2), via RePEc",
      "url": "https://ideas.repec.org/a/bla/jorssb/v63y2001i2p411-423.html",
      "accessed": "2026-11-19"
    }
  ]
}