* using log directory ‘/data/localhost/ripley/R/packages/tests-MKL/fixest.Rcheck’ * using R Under development (unstable) (2026-10-28 r90786) * using platform: x86_64-pc-linux-gnu * R was compiled by gcc (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2) GNU Fortran (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2) * running under: Fedora Linux 44 (Server Edition) * using session charset: UTF-8 * current time: 2026-10-29 23:56:12 UTC * using option ‘--no-stop-on-test-error’ * checking for file ‘fixest/DESCRIPTION’ ... OK * checking extension type ... Package * this is package ‘fixest’ version ‘0.14.2’ * package encoding: UTF-8 * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for executable files ... OK * checking for hidden files and directories ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package ‘fixest’ can be installed ... [82s/62s] OK * used C++ compiler: ‘g++ (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2)’ * checking package directory ... OK * checking ‘build’ directory ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking code files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK * checking whether startup messages can be suppressed ... OK * checking use of S3 registration ... OK * checking dependencies in R code ... OK * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... [67s/75s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking Rd contents ... OK * checking for unstated dependencies in examples ... OK * checking contents of ‘data’ directory ... OK * checking data for non-ASCII characters ... OK * checking LazyData ... OK * checking data for ASCII and uncompressed saves ... OK * checking line endings in shell scripts ... OK * checking line endings in C/C++/Fortran sources/headers ... OK * checking line endings in Makefiles ... OK * checking compilation flags in Makevars ... OK * checking for GNU extensions in Makefiles ... OK * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking use of PKG_*FLAGS in Makefiles ... OK * checking use of SHLIB_OPENMP_*FLAGS in Makefiles ... OK * checking pragmas in C/C++ headers and code ... OK * checking compilation flags used ... OK * checking compiled code ... OK * checking installed files from ‘inst/doc’ ... OK * checking files in ‘vignettes’ ... OK * checking examples ... [18s/19s] OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... Running ‘fixest_tests.R’ [12s/13s] [12s/13s] ERROR 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) + } Attaching package: 'data.table' The following object is masked from 'package:base': %notin% > > #### > #### 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(K.adj = adj))["x1"], se(res_bis)["x1"], "~", tol) + test(pvalue(res, se = "st", ssc = ssc(K.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) > > res = feols(y ~ x1 | fe1[x2] + fe2[x2], base) > > # > # singletons > # > > # all variables removed bc of singleton > base$singletons = 1:nrow(base) > test(feols(y ~ x1 | singletons, base, fixef.rm = "singleton"), "err") > > # in multiple estimations => no error > res = feols(y ~ x1 | sw0(singletons), base, fixef.rm = "singleton") > res_bis = feols(y ~ x1, base) > test(coef(res[[1]]), coef(res_bis)) > test(is.null(coef(res[[2]])), TRUE) > > # > # NA models (ie all variables are collinear with the FEs) > # > > # Should work when warn = FALSE or multiple est > for(i in 1:2){ + fun = switch(i, "1" = feols, "2" = feglm) + + res = feols(y ~ x_cst | fe1, base, warn = FALSE) + res # => no error + etable(res) # => no error + + # error when warn = TRUE + test(feols(y ~ x_cst | fe1, base), "err") + + # multiple est => no error + res = feols(c(y, x1) ~ x_cst | fe1, base) + res # => no error + etable(res) # => no error + } > > > # Removing the intercept!!! > > res = feols(y ~ -1 + x1 + i(fe1), base) > test("(Intercept)" %in% names(res$coefficients), FALSE) > > res = feols(y ~ -1 + x1 + factor(fe1), base) > test("(Intercept)" %in% names(res$coefficients), FALSE) > > res = feols(y ~ -1 + x1 + i(fe1) + i(fe2), base) > test("(Intercept)" %in% names(res$coefficients), FALSE) > test(is.null(res$collin.var), TRUE) > > > # IV + interacted FEs > res = feols(y ~ x1 | fe1^fe2 | x2 ~ x3, base) > > # IVs no exo var > res = feols(y ~ 0 | x2 ~ x3, base) > # Same in stepwise > res = feols(y ~ 0 | sw0(fe1) | x2 ~ x3, base) > > # IVs + lags > res = feols(y ~ x1 | fe1^fe2 | l(x2, -1:1) ~ l(x3, -1:1), base, panel.id = ~ fe1 + period) > > # functions in interactions > res = feols(y ~ x1 | factor(fe1)^factor(fe2), base) > res = feols(y ~ x1 | round(x2^2), base) > test(feols(y ~ x1 | factor(fe1^fe2), base), "err") > > res = feols(y ~ x1 | bin(x2, "bin::1")^fe1 + fe1^fe2, base) > > # 1 obs (after FE removal) estimation > base_1obs = data.frame(y = c(1, 0), fe = c(1, 2), x = c(1, 0)) > test(fepois(y ~ x | fe, base_1obs, fixef.rm = "infinite"), "err") > # no error > res = fepois(y ~ 1 | fe, base_1obs, fixef.rm = "infinite") > > # warning when demeaning algo reaches max iterations > data(trade) > test(feols(Euros ~ log(dist_km) | Destination + Origin + Product, + trade, fixef.iter = 1), "warn") > > # IV with ill defined instrument or endogenous regressors > df_poor_endo = data.frame(y = runif(10), endog = 1, inst = rnorm(10), exo = rnorm(10)) > test(feols(y ~ 1 | endog ~ inst, df_poor_endo), "err") [IV error] Problematic 1st stage results: OLS estimation, Dep. Var.: endog Observations: 10 Standard-errors: IID Estimate Std. Error t value Pr(>|t|) (Intercept) 1.00e+00 8.14e-17 1.228783e+16 < 2.2e-16 *** inst 4.37e-17 6.80e-17 6.419310e-01 0.53887 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 RMSE: 2.22e-16 Adj. R2: NaNe+Inf > # we just check no error: > feols(y ~ sw0(exo) | endog ~ inst, df_poor_endo) x.1 x.2 Dependent Var.: y y Constant NA (NA) NA (NA) exo NA (NA) _______________ ________ ________ S.E. type Void Void --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > df_poor_inst = data.frame(y = runif(10), endog = rnorm(10), inst = 0, exo = rnorm(10)) > test(feols(y ~ 1 | endog ~ inst, df_poor_inst), "err") [IV error] Problematic 1st stage results: OLS estimation, Dep. Var.: endog Observations: 10 Standard-errors: IID Estimate Std. Error t value Pr(>|t|) (Intercept) 0.15218 0.278945 0.545557 0.59863 ... 1 variable was removed because of collinearity (inst) --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 RMSE: 0.836834 > # we just check no error: > feols(y ~ sw0(exo) | endog ~ inst, df_poor_inst) x.1 x.2 Dependent Var.: y y Constant NA (NA) NA (NA) exo NA (NA) _______________ ________ ________ S.E. type Void Void --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # > # Only 0s > > df = mtcars > df$mpg = 0 > df$disp[1:5] = NA > df$hp[1:5] = NA > # here we have NAs only in the SW part, which means that select_obs will be later activated > no_error = feols(cyl ~ mpg + sw0(disp), df) > no_error = feols(cyl ~ sw0(disp) + mpg, df) > > # NAs at the beginning > no_error = feols(cyl ~ hp + sw0(disp) + mpg, df) Warning message: In feols(cyl ~ hp + sw0(disp) + mpg, df): After removing NAs, one explanatory variable is only 0s (`mpg`). > > # only 0s in the SW part > no_error = feols(cyl ~ disp + sw0(mpg), df) Warning message: In feols(cyl ~ disp + sw0(mpg), df): After removing NAs, one explanatory variable *in the step-wise part* is only 0s (`mpg`). => The step-wise part is ignored. > > > #### > #### ... depvar removal #### > #### > > chunk("depvar removal") DEPVAR REMOVAL > > # we remove the depvar when it is in the RHS > base = setNames(iris, c("y", "x1", "x2", "x3", "species")) > > fml_equiv = c( + "y" = "1", + "y + x1" = "x1", + "x1 + y + x2 + I(x1)" = "x1 + x2 + I(x1)" + ) > > all_funs = list(feols, feglm, femlm) > > id_fml = 3 > id_fun = 2 > > fun = all_funs[[id_fun]] > > for(id_fun in seq_along(all_funs)){ + fun = all_funs[[id_fun]] + cat("|") + for(id_fml in seq_along(fml_equiv)){ + + if(id_fun == 3 && id_fml == 3) next + + cat(".") + rhs_0 = names(fml_equiv)[id_fml] + rhs_1 = fml_equiv[id_fml] + + # simple estimation + est_0 = fun(y ~ .[rhs_0], base) + est_1 = fun(y ~ .[rhs_1], base) + test(coef(est_0), coef(est_1)) + test(se(est_0), se(est_1)) + + # multiple samples + est_0 = fun(y ~ .[rhs_0], base, split = "species") + est_1 = fun(y ~ .[rhs_1], base, split = "species") + test(coef(est_0[[1]]), coef(est_1[[1]])) + test(se(est_0[[1]]), se(est_1[[1]])) + + # multiple lhs + est_0 = fun(c(y, x3) ~ .[rhs_0] + x3, base) + est_1a = fun(y ~ .[rhs_1] + x3, base) + est_1b = fun(x3 ~ .[rhs_0], base) + test(coef(est_0[[1]]), coef(est_1a)) + test(coef(est_0[[2]]), coef(est_1b)) + test(se(est_0[[1]]), se(est_1a)) + test(se(est_0[[2]]), se(est_1b)) + + # multiple rhs + fixef + est_0 = fun(y ~ csw(.[rhs_0], x3) | sw0(species), base) + est_1 = fun(y ~ csw(.[rhs_1], x3) | sw0(species), base) + for(id_mult in n_models(est_0)){ + test(coef(est_0[[id_mult]]), coef(est_1[[id_mult]])) + test(se(est_0[[id_mult]]), se(est_1[[id_mult]])) + } + + # in IVs + if(id_fun == 1){ + base$inst = rnorm(nrow(base)) + base$endo = rnorm(nrow(base)) + est_0 = feols(y ~ csw(.[rhs_0], x3) | sw0(species) | endo ~ inst, base) + est_1 = feols(y ~ csw(.[rhs_1], x3) | sw0(species) | endo ~ inst, base) + for(id_mult in n_models(est_0)){ + test(coef(est_0[[id_mult]]), coef(est_1[[id_mult]])) + } + } + } + } |...|...|..> cat("\n") > > > # model.matrix > est = feols(y ~ x1 + y, base) > test(ncol(model.matrix(est)), 2) > > #### > #### ... obs removal #### > #### > > base_rm = base_did > base_rm$y = abs(base_rm$y) > # we add 0-values > is_only_0 = base_rm$id <= 10 > base_rm$y[is_only_0] = 0 > # we add singletons > is_single = base_rm$id %in% 50:55 > base_rm$period[is_single] = runif(sum(is_single)) > > est_none = fepois(y ~ x1 | id + period, base_rm, fixef.rm = "none") > est_single = fepois(y ~ x1 | id + period, base_rm, fixef.rm = "singletons") > est_inf = fepois(y ~ x1 | id + period, base_rm, fixef.rm = "infinite") > est_perfect = fepois(y ~ x1 | id + period, base_rm, fixef.rm = "perfect") > > n = nrow(base_rm) > test(nobs(est_none), n) > test(nobs(est_single), n - sum(is_single)) > test(nobs(est_inf), n - sum(is_only_0)) > test(nobs(est_perfect), n - sum(is_single) - sum(is_only_0)) > > #### > #### ... Fit methods #### > #### > > chunk("Fit methods") FIT METHODS > > base = setNames(iris, c("y", "x1", "x2", "x3", "species")) > base$y_int = as.integer(base$y) > base$y_log = sample(c(TRUE, FALSE), 150, TRUE) > > res = feglm.fit(base$y, base[, 2:4]) > res_bis = feglm(y ~ -1 + x1 + x2 + x3, base) > test(coef(res), coef(res_bis)) > > res = feglm.fit(base$y_int, base[, 2:4]) > res_bis = feglm(y_int ~ -1 + x1 + x2 + x3, base) > test(coef(res), coef(res_bis)) > > res = feglm.fit(base$y_log, base[, 2:4]) > res_bis = feglm(y_log ~ -1 + x1 + x2 + x3, base) > test(coef(res), coef(res_bis)) > > > > res = feglm.fit(base$y, base[, 2:4], family = "poisson") > res_bis = feglm(y ~ -1 + x1 + x2 + x3, base, family = "poisson") > test(coef(res), coef(res_bis)) > > res = feglm.fit(base$y_int, base[, 2:4], family = "poisson") > res_bis = feglm(y_int ~ -1 + x1 + x2 + x3, base, family = "poisson") > test(coef(res), coef(res_bis)) > > res = feglm.fit(base$y_log, base[, 2:4], family = "poisson") > res_bis = feglm(y_log ~ -1 + x1 + x2 + x3, base, family = "poisson") > test(coef(res), coef(res_bis)) > > #### > #### global variables #### > #### > > chunk("globals") GLOBALS > > est_reg = function(df, yvar, xvar, refgrp) { + feols(.[yvar] ~ i(.[xvar], ref = refgrp), data = df) + } > > est = est_reg(iris, "Sepal.Length", "Species", refgrp = "setosa") > > # checking when it should not work > base = setNames(iris, c("y", "x1", "x2", "x3", "species")) > > z = base$x1 > test(feols(y ~ z, base), "err") > > > > #### > #### ... Collinearity #### > #### > > chunk("COLLINEARITY") COLLINEARITY > > base = iris > names(base) = c("y", "x1", "x2", "x3", "species") > base$constant = 5 > base$y_int = as.integer(base$y) > base$w = as.vector(unclass(base$species) - 0.95) > > for(useWeights in c(FALSE, TRUE)){ + for(model in c("ols", "pois")){ + for(use_fe in c(FALSE, TRUE)){ + cat(".") + + my_weight = NULL + if(useWeights) my_weight = base$w + + adj = 1 + if(model == "ols"){ + if(!use_fe){ + res = feols(y ~ x1 + constant, base, weights = my_weight) + res_bis = lm(y ~ x1 + constant, base, weights = my_weight) + } else { + res = feols(y ~ x1 + constant | species, base, weights = my_weight) + res_bis = lm(y ~ x1 + constant + species, base, weights = my_weight) + } + } else { + if(!use_fe){ + res = fepois(y_int ~ x1 + constant, base, weights = my_weight) + res_bis = glm(y_int ~ x1 + constant, base, weights = my_weight, family = poisson) + } else { + res = fepois(y_int ~ x1 + constant | species, base, weights = my_weight) + res_bis = glm(y_int ~ x1 + constant + species, base, weights = my_weight, family = poisson) + } + adj = 0 + } + + test(coef(res)["x1"], coef(res_bis)["x1"], "~") + test(se(res, se = "st", ssc = ssc(K.adj=adj))["x1"], se(res_bis)["x1"], "~") + # cat("Weight: ", useWeights, ", model: ", model, ", FE: ", use_fe, "\n", sep="") + + } + } + } ........> cat("\n") > > > #### > #### ... Non linear tests #### > #### > > chunk("NON LINEAR") NON LINEAR > > base = iris > names(base) = c("y", "x1", "x2", "x3", "species") > > tab = c("versicolor" = 5, "setosa" = 0, "virginica" = -5) > > fun_nl = function(a, b, spec){ + res = as.numeric(tab[spec]) + a*res + b*res^2 + } > > est_nl = feNmlm(y ~ x1, base, NL.fml = ~fun_nl(a, b, species), NL.start = 1, family = "gaussian") > > base$var_spec = as.numeric(tab[base$species]) > > est_lin = feols(y ~ x1 + var_spec + I(var_spec^2), base) > > test(coef(est_nl), coef(est_lin)[c(3, 4, 1, 2)], "~") > > #### > #### ... Lagging #### > #### > > # Different types of lag > # 1) check no error in wide variety of situations > # 2) check consistency > > chunk("LAGGING") LAGGING > > data(base_did) > base = base_did > > n = nrow(base) > > set.seed(0) > base$y_na = base$y ; base$y_na[sample(n, 50)] = NA > base$period_txt = letters[base$period] > ten_dates = c("1960-01-15", "1960-01-16", "1960-03-31", "1960-04-05", "1960-05-12", "1960-05-25", "1960-06-20", "1960-07-30", "1965-01-02", "2002-12-05") > base$period_date = as.Date(ten_dates, "%Y-%m-%d")[base$period] > base$y_0 = base$y**2 ; base$y_0[base$id == 1] = 0 > > # We compute the lags "by hand" > base = base[order(base$id, base$period), ] > base$x1_lag = c(NA, base$x1[-n]) ; base$x1_lag[base$period == 1] = NA > base$x1_lead = c(base$x1[-1], NA) ; base$x1_lead[base$period == 10] = NA > base$x1_diff = base$x1 - base$x1_lag > > # we create holes > base$period_bis = base$period ; base$period_bis[base$period_bis == 5] = 50 > base$x1_lag_hole = base$x1_lag ; base$x1_lag_hole[base$period %in% c(5, 6)] = NA > base$x1_lead_hole = base$x1_lead ; base$x1_lead_hole[base$period %in% c(4, 5)] = NA > > # we reshuffle the base > base = base[sample(n), ] > > # > # Checks consistency > # > > cat("consistentcy...") consistentcy...> > test(lag(x1 ~ id + period, data = base), base$x1_lag) > test(lag(x1 ~ id + period, -1, data = base), base$x1_lead) > > test(lag(x1 ~ id + period_bis, data = base), base$x1_lag_hole) > test(lag(x1 ~ id + period_bis, -1, data = base), base$x1_lead_hole) > > test(lag(x1 ~ id + period_txt, data = base), base$x1_lag) > test(lag(x1 ~ id + period_txt, -1, data = base), base$x1_lead) > > test(lag(x1 ~ id + period_date, data = base), base$x1_lag) > test(lag(x1 ~ id + period_date, -1, data = base), base$x1_lead) > > cat("done.\nEstimations...") done. Estimations...> > # > # Estimations > # > > # Poisson > > for(depvar in c("y", "y_na", "y_0")){ + for(p in c("period", "period_txt", "period_date")){ + + base$per = base[[p]] + + cat(".") + + base$y_dep = base[[depvar]] + pdat = panel(base, ~ id + period) + + if(depvar == "y_0"){ + estfun = fepois + } else { + estfun = feols + } + + est_raw = estfun(y_dep ~ x1 + x1_lag + x1_lead, base) + est = estfun(y_dep ~ x1 + l(x1) + f(x1), base, panel.id = "id,per") + est_pdat = estfun(y_dep ~ x1 + l(x1, 1) + f(x1, 1), pdat) + test(coef(est_raw), coef(est)) + test(coef(est_raw), coef(est_pdat)) + + # Now diff + est_raw = estfun(y_dep ~ x1 + x1_diff, base) + est = estfun(y_dep ~ x1 + d(x1), base, panel.id = "id,per") + est_pdat = estfun(y_dep ~ x1 + d(x1, 1), pdat) + test(coef(est_raw), coef(est)) + test(coef(est_raw), coef(est_pdat)) + + # Now we just check that calls to l/f works without checking coefs + + est = estfun(y_dep ~ x1 + l(x1) + f(x1), base, panel.id = "id,per") + est = estfun(y_dep ~ l(x1, -1:1) + f(x1, 2), base, panel.id = c("id", "per")) + est = estfun(y_dep ~ l(x1, -1:1, fill = 1), base, panel.id = ~ id + per) + if(depvar == "y") test(est$nobs, n) + est = estfun(f(y_dep) ~ f(x1, -1:1), base, panel.id = ~ id + per) + } + } .........> > cat("done.\n\n") done. > > # > # Data table > # > > cat("data.table...") data.table...> # We just check there is no bug (consistency should be OK) > > suppressPackageStartupMessages(library(data.table)) > > base_dt = data.table(id = c("A", "A", "B", "B"), + time = c(1, 2, 1, 3), + x = c(5, 6, 7, 8)) > > base_dt = panel(base_dt, ~id + time) > > base_dt[, x_l := l(x)] > test(base_dt$x_l, c(NA, 5, NA, NA)) > > lag_creator = function(dt) { + dt2 = panel(dt, ~id + time) + dt2[, x_l := l(x)] + return(dt2) + } > > base_bis = lag_creator(base_dt) > > base_bis[, x_d := d(x)] > > cat("done.\n\n") done. > > # > # Panel > # > > # We ensure we get the right SEs whether we use the panel() or the panel.id method > data(base_did) > > # Setting a data set as a panel... > pdat = panel(base_did, ~id+period) > pdat$fe = sample(15, nrow(pdat), replace = TRUE) > > base_panel = unpanel(pdat) > > est_pdat = feols(y ~ x1 | fe, pdat) > est_panel = feols(y ~ x1 | fe, base_panel, panel.id = ~id+period) > > test(attr(vcov(est_pdat, attr = TRUE), "vcov_type"), + attr(vcov(est_panel, attr = TRUE), "vcov_type")) > > # > # testing irregularities > # > > base_panel = data.frame( + id = rep(letters[1:3], each = 4), + time = c(1, 2, 3, 3, + 1, 2, 4, 6, + 2, 4, 6, 8) + ) > base_panel$x = rnorm(nrow(base_panel)) > base_panel$y = base_panel$x * 0.5 + rnorm(nrow(base_panel)) > > est_panel_irr = feols(y ~ l(x), base_panel, panel.id = "id,time", + panel.duplicate.method = "first") > > x_lag = model.matrix(est_panel_irr)[, 2] > test(x_lag, base_panel$x[c(1, 2, 2, 5)]) > > est_panel_irr_cons = feols(y ~ l(x), base_panel, panel.id = "id,time", + panel.time.step = "cons", + panel.duplicate.method = "first") > > x_lag = model.matrix(est_panel_irr_cons)[, 2] > test(x_lag, base_panel$x[c(NULL, 1, 2, 2, + NULL, 5, NULL, 7, + NULL, NULL, 10, 11)]) > > est_panel_irr_with = feols(y ~ l(x), base_panel, panel.id = "id,time", + panel.time.step = "within", + panel.duplicate.method = "first") > > x_lag = model.matrix(est_panel_irr_with)[, 2] > test(x_lag, base_panel$x[c(NULL, 1, 2, 3, + NULL, 5, 6, 7, + NULL, 9, 10, 11)]) > > #### > #### ... subset #### > #### > > chunk("SUBSET") SUBSET > > set.seed(5) > base = iris > names(base) = c("y", "x1", "x2", "x3", "species") > base$fe_bis = sample(letters, 150, TRUE) > base$x4 = rnorm(150) > base$x1[sample(150, 5)] = NA > > fml = y ~ x1 + x2 > > # Errors > test(feols(fml, base, subset = ~species), "err") > test(feols(fml, base, subset = -1:15), "err") > test(feols(fml, base, subset = integer(0)), "err") > test(feols(fml, base, subset = c(TRUE, TRUE, FALSE)), "err") > > # Valid use > for(id_fun in 1:6){ + estfun = switch(as.character(id_fun), + "1" = feols, + "2" = feglm, + "3" = fepois, + "4" = femlm, + "5" = fenegbin, + "6" = feNmlm) + + for(id_fe in 1:5){ + + cat(".") + + fml = switch(as.character(id_fe), + "1" = y ~ x1 + x2, + "2" = y ~ x1 + x2 | species, + "3" = y ~ x1 + x2 | fe_bis, + "4" = y ~ x1 + x2 + i(fe_bis), + "5" = y ~ x1 + x2 | fe_bis[x3]) + + if(id_fe == 5 && id_fun %in% 4:6) next + + if(id_fun == 6){ + res_sub_a = estfun(fml, base, subset = ~species == "setosa", NL.fml = ~ a*x4, NL.start = 0) + res_sub_b = estfun(fml, base, subset = base$species == "setosa", NL.fml = ~ a*x4, NL.start = 0) + res_sub_c = estfun(fml, base, subset = which(base$species == "setosa"), NL.fml = ~ a*x4, NL.start = 0) + res = estfun(fml, base[base$species == "setosa", ], NL.fml = ~ a*x4, NL.start = 0) + } else { + res_sub_a = estfun(fml, base, subset = ~species == "setosa") + res_sub_b = estfun(fml, base, subset = base$species == "setosa") + res_sub_c = estfun(fml, base, subset = which(base$species == "setosa")) + res = estfun(fml, base[base$species == "setosa", ]) + } + + test(coef(res_sub_a), coef(res)) + test(coef(res_sub_b), coef(res)) + test(coef(res_sub_c), coef(res)) + test(se(res_sub_c, cluster = "fe_bis"), se(res, cluster = "fe_bis")) + } + cat("|") + } .....|.....|.....|.....|.....|....Error: in test(coef(res_sub_a), coef(res)): All values differ. actual: -0.02831163 1.05488 0.1282873 0.08151059 [23 others] expected: -0.02831163 1.05488 0.1282873 0.08151059 [23 others] Max absolute difference: 1.77307899473789e-08 Execution halted * checking for unstated dependencies in vignettes ... OK * checking package vignettes ... OK * checking re-building of vignette outputs ... [35s/45s] OK * checking PDF version of manual ... [11s/13s] OK * checking HTML version of manual ... OK * checking for non-standard things in the check directory ... OK * checking for detritus in the temp directory ... OK * DONE Status: 1 ERROR See ‘/data/localhost/ripley/R/packages/tests-MKL/fixest.Rcheck/00check.log’ for details. Command exited with non-zero status 1 Time 5:05.49, 270.07 + 18.22