rStats.js v1.3.0
    Preparing search index...

    Function vcovCL

    • Clustered covariance matrix of the coefficients of an lm or glm fit. Equivalent to R's sandwich::vcovCL().

      The meat sums the estimating functions within each cluster (Zeileis, Köll and Graham 2020), times G / (G - 1) with cadjust; HC1 multiplies by (n - 1) / (n - k). Several clustering dimensions are combined by inclusion and exclusion over all their intersections, each term with its own G (Cameron, Gelbach and Miller 2011); multi0 uses clusters of one observation for the full intersection. HC2 and HC3 adjust each cluster's residuals by (I - H_gg)^-1/2 or (I - H_gg)^-1 in the symmetric form of Bell and McCaffrey (2002) (for HC3 the leave-one-cluster-out jackknife), which is sandwich's for an unweighted lm; sandwich transposes the adjustment for a weighted lm or a glm. A singular block (cluster fixed effects) is an error. fix sets negative eigenvalues to 0.

      The default type is HC1 for an lm and HC0 for a glm, as sandwich. Without cluster each observation is its own cluster. G is the number of distinct labels among the rows used (labels are compared as text, numbers with 15 significant digits as R's as.character: 1 and 1 + 2^-52, or 0.1 + 0.2 and 0.3, are one label); intersections of dimensions are tuples of labels; at least two clusters are needed. Rows of prior weight 0 are left out. HC1 needs more observations than coefficients. Data far from 1 as vcovHC (the same record of the units, lost by a copy of the matrix); with fix, a negative eigenvalue is set to 0 in the units of the largest coefficient's variance, so that coefficients whose scale is about 2^537 or more below it then get variance 0. See docs/differences-from-r.md.

      Parameters

      Returns VcovResult

      const fit = lm([1, 2, 3, 4, 5, 6, 7, 8], [1.2, 1.9, 3.2, 3.8, 5.3, 5.9, 7.1, 8.2]);
      vcovCL(fit, { cluster: ["a", "a", "b", "b", "c", "c", "d", "d"] }).vcov;
      // [[0.002257, -0.00053463], [-0.00053463, 0.00016363]] (HC1)