Running ‘fixest_tests.R’ [10s/11s]
Running the tests in ‘tests/fixest_tests.R’ failed.
Complete output:
  > #----------------------------------------------#
  > # Author: Laurent Berge
  > # Date creation: Fri Jul 10 09:03:06 2020
  > # ~: package sniff tests
  > #----------------------------------------------#
  > 
  > # Not everything is currently covered, but I'll improve it over time
  > 
  > # Some functions are not trivial to test properly though
  > 
  > library(fixest)
  > 
  > test = fixest:::test ; chunk = fixest:::chunk
  > vcovClust = fixest:::vcovClust
  > stvec = stringmagic::string_vec_alias()
  > 
  > setFixest_notes(FALSE)
  > 
  > if(fixest:::is_r_check()){
  +   if(requireNamespace("data.table", quietly = TRUE)){
  +     library(data.table)
  +     data.table::setDTthreads(1)
  +   }
  +   setFixest_nthreads(1)
  + }
  > 
  > ####
  > #### ESTIMATIONS ####
  > ####
  > 
  > ####
  > #### ... Main ####
  > ####
  > 
  > 
  > chunk("ESTIMATION")
  ESTIMATION
  
  > 
  > set.seed(0)
  > 
  > base = iris
  > names(base) = c("y", "x1", "x2", "x3", "species")
  > base$fe_2 = rep(1:5, 30)
  > base$fe_3 = sample(15, 150, TRUE)
  > base$constant = 5
  > base$y_int = as.integer(base$y)
  > base$w = as.vector(unclass(base$species) - 0.95)
  > base$offset_value = unclass(base$species) - 0.95
  > base$y_01 = 1 * ((scale(base$x1) + rnorm(150)) > 0)
  > # what follows to avoid removal of fixed-effects (logit is pain in the neck)
  > base$y_01[1:5 + rep(c(0, 50, 100), each = 5)] = 1
  > base$y_01[6:10 + rep(c(0, 50, 100), each = 5)] = 0
  > # We enforce the removal of observations
  > base$y_int_null = base$y_int
  > base$y_int_null[base$fe_3 %in% 1:5] = 0
  > 
  > for(model in c("ols", "pois", "logit", "negbin", "Gamma")){
  +   cat("Model: ", format(model, width = 6), sep = "")
  +   for(use_weights in c(FALSE, TRUE)){
  +     my_weight = NULL
  +     if(use_weights) my_weight = base$w
  + 
  +     for(use_offset in c(FALSE, TRUE)){
  +       my_offset = NULL
  +       if(use_offset) my_offset = base$offset_value
  + 
  +       for(id_fe in 0:9){
  + 
  +         cat(".")
  + 
  +         tol = switch(model, "negbin" = 1e-2, "logit" = 3e-5, 1e-5)
  + 
  +         # Setting up the formula to accommodate FEs
  +         if(id_fe == 0){
  +           fml_fixest = fml_stats = y ~ x1
  +         } else if(id_fe == 1){
  +           fml_fixest = y ~ x1 | species
  +           fml_stats = y ~ x1 + factor(species)
  +         } else if(id_fe == 2){
  +           fml_fixest = y ~ x1 | species + fe_2
  +           fml_stats = y ~ x1 + factor(species) + factor(fe_2)
  +         } else if(id_fe == 3){
  +           # varying slope
  +           fml_fixest = y ~ x1 | species[[x2]]
  +           fml_stats = y ~ x1 + x2:species
  +         } else if(id_fe == 4){
  +           # varying slope -- 1 VS, 1 FE
  +           fml_fixest = y ~ x1 | species[[x2]] + fe_2
  +           fml_stats = y ~ x1 + x2:species + factor(fe_2)
  +         } else if(id_fe == 5){
  +           # varying slope -- 2 VS
  +           fml_fixest = y ~ x1 | species[x2]
  +           fml_stats = y ~ x1 + x2:species + species
  +         } else if(id_fe == 6){
  +           # varying slope -- 2 VS bis
  +           fml_fixest = y ~ x1 | species[[x2]] + fe_2[[x3]]
  +           fml_stats = y ~ x1 + x2:species + x3:factor(fe_2)
  +         } else if(id_fe == 7){
  +           # Combined clusters
  +           fml_fixest = y ~ x1 + x2 | species^fe_2
  +           fml_stats = y ~ x1 + x2 + paste(species, fe_2)
  +         } else if(id_fe == 8){
  +           fml_fixest = y ~ x1 | species[x2] + fe_2[x3] + fe_3
  +           fml_stats = y ~ x1 + species + i(species, x2) + factor(fe_2) + i(fe_2, x3) + factor(fe_3)
  +         } else if(id_fe == 9){
  +           fml_fixest = y ~ x1 | species + fe_2[x2,x3] + fe_3
  +           fml_stats = y ~ x1 + species + factor(fe_2) + i(fe_2, x2) + i(fe_2, x3) + factor(fe_3)
  +         }
  + 
  +         # ad hoc modifications of the formula
  +         if(model == "logit"){
  +           fml_fixest = xpd(y_01 ~ ..rhs, ..rhs = fml_fixest[[3]])
  +           fml_stats = xpd(y_01 ~ ..rhs, ..rhs = fml_stats[[3]])
  + 
  +           # The estimations are OK, conv differences out of my control
  +           if(id_fe %in% 8:9) tol = 0.5
  + 
  +         } else if(model == "pois"){
  +           fml_fixest = xpd(y_int_null ~ ..rhs, ..rhs = fml_fixest[[3]])
  +           fml_stats = xpd(y_int_null ~ ..rhs, ..rhs = fml_stats[[3]])
  + 
  +         } else if(model %in% c("negbin", "Gamma")){
  +           fml_fixest = xpd(y_int ~ ..rhs, ..rhs = fml_fixest[[3]])
  +           fml_stats = xpd(y_int ~ ..rhs, ..rhs = fml_stats[[3]])
  +         }
  + 
  +         adj = 1
  +         if(model == "ols"){
  +           res = feols(fml_fixest, base, weights = my_weight, offset = my_offset)
  +           res_bis = lm(fml_stats, base, weights = my_weight, offset = my_offset)
  + 
  +         } else if(model %in% c("pois", "logit", "Gamma")){
  +           adj = 0
  +           if(model == "Gamma" && use_offset) next
  + 
  +           my_family = switch(model, pois = poisson(), logit = binomial(), Gamma = Gamma())
  + 
  +           res = feglm(fml_fixest, base, family = my_family, weights = my_weight, offset = my_offset)
  + 
  +           if(!is.null(res$obs_selection$obsRemoved)){
  +             qui = res$obs_selection$obsRemoved
  + 
  +             # I MUST do that.... => subset does not work...
  +             base_tmp = base[qui, ]
  +             base_tmp$my_offset = my_offset[qui]
  +             base_tmp$my_weight = my_weight[qui]
  +             res_bis = glm(fml_stats, base_tmp, family = my_family, weights = my_weight, offset = my_offset)
  +           } else {
  +             res_bis = glm(fml_stats, data = base, family = my_family, weights = my_weight, offset = my_offset)
  +           }
  + 
  +         } else if(model == "negbin"){
  +           # no offset in glm.nb + no VS in fenegbin + no weights in fenegbin
  +           if(use_weights || use_offset || id_fe > 2) next
  + 
  +           res = fenegbin(fml_fixest, base, notes = FALSE)
  +           res_bis = MASS::glm.nb(fml_stats, base)
  + 
  +         }
  + 
  +         test(coef(res)["x1"], coef(res_bis)["x1"], "~", tol)
  +         test(se(res, se = "st", ssc = ssc(adj = adj))["x1"], se(res_bis)["x1"], "~", tol)
  +         test(pvalue(res, se = "st", ssc = ssc(adj = adj))["x1"], pvalue(res_bis)["x1"], "~", tol*10**(model == "negbin"))
  +         # cat("Model: ", model, ", FE: ", id_fe, ", weight: ", use_weights,  ", offset: ", use_offset, "\n", sep="")
  + 
  +       }
  +       cat("|")
  +     }
  +   }
  +   cat("\n")
  + }
  Model: ols   ..........|..........|..........|..........|
  Model: pois  ..........|..........|..........|..........|
  Model: logit ..........|..........|..........|..........|
  Model: negbin..........|..........|..........|..........|
  Model: Gamma ..........|..........|..........|..........|
  There were 36 warnings (use warnings() to see them)
  > 
  > ####
  > #### ... Corner cases ####
  > ####
  > 
  > chunk("Corner cases")
  CORNER CASES
  
  > 
  > 
  > # We test the absence of bugs
  > 
  > base = iris
  > names(base) = c("y", "x1", "x2", "x3", "fe1")
  > base$fe2 = rep(1:5, 30)
  > base$y[1:5] = NA
  > base$x1[4:8] = NA
  > base$x2[4:21] = NA
  > base$x3[110:111] = NA
  > base$fe1[110:118] = NA
  > base$fe2[base$fe2 == 1] = 0
  > base$fe3 = sample(letters[1:5], 150, TRUE)
  > base$period = rep(1:50, 3)
  > base$x_cst = 1
  > 
  > res = feols(y ~ 1 | csw(fe1, fe1^fe2), base)
  > 
  > res = feols(y ~ 1 + csw(x1, i(fe1)) | fe2, base)
  > 
  > res = feols(y ~ csw(f(x1, 1:2), x2) | sw0(fe2, fe2^fe3), base, panel.id = ~ fe1 + period)
  > 
  > res = feols(d(y) ~ -1 + d(x2), base, panel.id = ~ fe1 + period)
  > test(length(coef(res)), 1)
  > 
  > res = feols(c(y, x1) ~ 1 | fe1 | x2 ~ x3, base)
  
   *** caught segfault ***
  address 0x1, cause 'memory not mapped'
  
  Traceback:
   1: cpp_iv_products(X = X_demean, y = y_demean, Z = iv.mat_demean,     u = iv_lhs_demean, w = weights, nthreads = nthreads)
   2: feols(c(y, x1) ~ 1 | fe1 | x2 ~ x3, base)
  An irrecoverable exception occurred. R is aborting now ...
  Segmentation fault