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

    Function vcovHC

    • Heteroskedasticity-consistent covariance matrix of the coefficients of an lm or glm fit. Equivalent to R's sandwich::vcovHC().

      The sandwich A (X' diag(omega) X) A (Zeileis 2006), A = (X'WX)^-1, with omega_i = res_i^2 (HC0, White 1980), times n / (n - k) (HC1), divided by 1 - h_i (HC2) or (1 - h_i)^2 (HC3, MacKinnon and White 1985), by (1 - h_i)^delta_i (HC4, Cribari-Neto 2004; HC4m, Cribari-Neto and da Silva 2011) or by its square root (HC5, Cribari-Neto et al. 2007), with HC4m's gamma = (1, 1.5) and HC5's k = 0.7 fixed as in sandwich; res_i is w_i e_i for an lm and W_i z_i / phi_s for a glm (working weights and residuals). "const" is the model-based covariance of the fit (R's vcov(fit): sigma^2 A, or the dispersion times A for a glm); sandwich's "const" equals it only for an unweighted lm.

      Rows of prior weight 0 are left out (R counts them in n and returns different values); a hat value of 1 gives R's warning, and with HC2 to HC5, whose value is then undefined (R's NaN), an error, as is HC1 with as many observations as coefficients. Aliased coefficients are left out of the matrix. Data far from 1 (weights, responses) are handled in units of powers of 2: entries that are not representable are Infinity or 0, and coeftest still gives their standard errors, from a record kept with the matrix object returned (a copy of the matrix loses it: pass the result or its original matrix). See docs/differences-from-r.md.

      Parameters

      Returns VcovResult

      const fit = lm([1, 2, 3, 4, 5, 6], [1.1, 2.3, 2.8, 4.5, 4.9, 6.4]);
      vcovHC(fit).vcov; // [[0.043766, -0.01134], [-0.01134, 0.0045125]] (HC3)
      vcovHC(fit, { type: "HC0" }).names; // ["(Intercept)", "x1"]