Running ‘basic.R’ [1s/1s]
  Running ‘check_functions.R’ [0s/0s]
  Running ‘domain.R’ [1s/1s]
  Running ‘greg.R’ [1s/1s]
  Running ‘huber2.R’ [1s/1s]
  Running ‘ratio.R’ [1s/1s]
  Running ‘reg.R’ [1s/1s]
Running the tests in ‘tests/reg.R’ failed.
Complete output:
  > suppressPackageStartupMessages(library("survey"))
  > library("robsurvey", quietly = TRUE)
  > attach(workplace)
  > 
  > # design object
  > dn <- svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight,
  +     data = workplace)
  > 
  > source("check_functions.R")
  > 
  > #===============================================================================
  > # 1 Test against MASS::rlm
  > #===============================================================================
  > if (requireNamespace("MASS", quietly = TRUE)) {
  +     library(MASS)
  +     # make a copy of MASS::rlm
  +     rlm_mod <- MASS:::rlm.default
  +     # replace wmad-function with our weighted mad
  +     body(rlm_mod)[[4]] <- substitute(wmad <- function(x, w) weighted_mad(x, w))
  + 
  +     #---------------------------------------------------------------------------
  +     # Huber regression M-estimator
  +     est <- svyreg_huberM(payroll ~ employment, dn, k = 1.345, tol = 1e-9)
  +     ref <- rlm_mod(x = est$model$x, y = est$model$y, weights = est$model$w,
  +         k = 1.345, scale.est = "MAD", method = "M", wt.method = "case",
  +         acc = 1e-9, maxit = 50, test.vec = "coef")
  +     all_equal(coef(est), coef(ref), tolerance = 1e-7,
  +         label = "Huber regression regression: coefficients")
  +     # model-based covariance matrix
  +     all_equal(vcov(est, "model"), vcov(ref), tolerance = 1e-7,
  +         label = "Huber regression M-est: model-based cov")
  +     # design-based covariance matrix (test against fixed values)
  +     ref <- matrix(c(61704317.084028, -3367311.1407500, -3367311.140750,
  +         870905.6027803), ncol = 2)
  +     colnames(ref) <- rownames(ref) <- c("(Intercept)", "employment")
  +     all_equal(vcov(est), ref,
  +         label = "Huber regression M-est: design-based cov")
  + 
  +     #---------------------------------------------------------------------------
  +     # Tukey regression M-estimator
  +     est <- svyreg_tukeyM(payroll ~ employment, dn, k = 4.6, tol = 1e-9)
  +     ref <- rlm_mod(x = est$model$x, y = est$model$y, weights = est$model$w,
  +         c = 4.6, psi = psi.bisquare,  scale.est = "MAD", method = "M",
  +         wt.method = "case", acc = 1e-9, maxit = 50, test.vec = "coef")
  +     all_equal(coef(est), coef(ref), tolerance = 1e-7,
  +         label = "Tukey regression regression: coefficients")
  +     # model-based covariance matrix
  +     all_equal(vcov(est, "model"), vcov(ref), tolerance = 1e-7,
  +         label = "Tukey regression M-est: model-based cov")
  +     # design-based covariance matrix (test against fixed values)
  +     ref <- matrix(c(43513457.824988, -1421272.808406, -1421272.808406,
  +         589121.583227), ncol = 2)
  +     colnames(ref) <- rownames(ref) <- c("(Intercept)", "employment")
  +     all_equal(vcov(est), ref,
  +         label = "Tukey regression M-est: design-based cov")
  + }
  Error: Huber regression M-est: model-based cov: Mean relative difference: 1
  Execution halted