Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R Session Aborted #283

Closed
da-zar opened this issue Mar 15, 2022 · 5 comments
Closed

R Session Aborted #283

da-zar opened this issue Mar 15, 2022 · 5 comments

Comments

@da-zar
Copy link

da-zar commented Mar 15, 2022

Hi,

I've noticed that for some data sets, small once where the data is not sufficient to estimate the parameters, an error is thrown but for others the R session simply crashes. Below an example.

library(fixest)
packageVersion('fixest') # 0.10.3’

# gives an error that can be handled
df <- data.frame(id = 1, time = 2, y = 1, x = 1)
model <- fepois(
  y ~ x | id + time,
  df
)

# crashes the session
df <- data.frame(id = c(1, 1), time = c(1, 2), y = c(1, 0), x = c(1, 0))
model <- fepois(
  y ~ x | id + time,
  df
)
@etiennebacher
Copy link

I narrowed it down to this but then it happens in C++ (which I don't know). I'm putting this here if someone wants to explore:

y = 0.004401089
X = matrix(1, dimnames = list(NULL, "x"))
weights = 1.1
iterMax = 10000
diffMax = 1e-05
r_nb_id_Q = c(1L, 1L)
fe_id_list = list(1L, 1L)
table_id_I = c(1L, 1L)
slope_flag_Q = c(0L, 0L)
slope_vars_list = list(0)
r_init = 1
nthreads = 4

fixest:::cpp_demean(y, X, weights, iterMax, diffMax, r_nb_id_Q, fe_id_list, table_id_I,
           slope_flag_Q, slope_vars_list, r_init, nthreads)

@lrberge lrberge closed this as completed in dc40b58 Feb 9, 2024
@lrberge
Copy link
Owner

lrberge commented Feb 9, 2024

Hi, and sorry for the longuiish delay!
Thanks a lot @da-zar for reporting and providing a simple reproducible example, and to @etiennebacher for making my life so easy!

Now fixed.

@etiennebacher
Copy link

etiennebacher commented Feb 9, 2024

I confirm, thanks! One small mistake in the error message though, in the example below I suppose it should be "Some variables" instead of "All variables"?

library(fixest)
df <- data.frame(id = c(1, 1), time = c(1, 2), y = c(1, 0), x = c(1, 0), x2 = c(2, 1), x3 = c(0, 0))
model <- fepois(
  y ~ x + x2 + x3 | id + time,
  df
)
#> NOTE: 0/1 fixed-effect (1 observation) removed because of only 0 outcomes.
#> Error in fepois(y ~ x + x2 + x3 | id + time, df): All variables, 'x' and 'x2', are collinear with the fixed effects. In such
#> circumstances, the estimation is void.

@lrberge
Copy link
Owner

lrberge commented Feb 9, 2024

No, it's all , the three should be there...
:-/ brb

@lrberge
Copy link
Owner

lrberge commented Feb 9, 2024

Ah, it's because x3 is an edge case and was removed before because equal to a constant 0.
Works OK with non constants:

df <- data.frame(id = c(1, 1), time = c(1, 2), y = c(1, 0), x = c(1, 0), x2 = c(2, 1), x3 = c(6, 0))
model <- fepois(y ~ x + x2 + x3 | id + time, df)
#> NOTE: 0/1 fixed-effect (1 observation) removed because of only 0 outcomes.
#> Error in fepois(y ~ x + x2 + x3 | id + time, df) : 
#>  All variables, 'x', 'x2' and 'x3', are collinear with the fixed effects. In such circumstances, the estimation is void.

I remove 0-only variables beforehand. I do not give warnings since it can happen for factors when manipulating the data (hence there would be too much false positives).

Thanks for checking! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants