Skip to content

Error with singleton observations #63

@pdeffebach

Description

@pdeffebach

This error occurs when there are singleton observations. It looks like GLFixedEffectModels.jl isn't keeping track of the number of observations well enough, and some indexing persists even after dropping singleton observations. Here is an MWE

julia> df = DataFrame(y = rand(100), x = rand(100), g = rand(1:10, 100));

julia> push!(df, (y = 0.5, x = 0.5, g = 11));

julia> m = nlreg(df, @formula(y ~ x + fe(g)), Poisson(), LogLink(), save = [:fe])
[ Info: 1 observations detected as singletons. Dropping them ...
ERROR: BoundsError: attempt to access 100×1 Matrix{Float64} at index [101-element BitVector, 1:1]
Stacktrace:

The bug only occurs when we have save = [:fe]. So it has to do with creating the augmentdf data frame


julia> m = nlreg(df, @formula(y ~ x + fe(g)), Poisson(), LogLink())
[ Info: 1 observations detected as singletons. Dropping them ...
             Generalized Linear Fixed Effect Model             
===============================================================
Distribution:        "Poisson"   Link:                "LogLink"
Number of obs:             100   Degrees of freedom:         11
Deviance:               19.013   Pseudo-R2:                 NaN
Pseudo-Adj. R2:            NaN   Iterations:                  5
Converged:                true   
===============================================================
      Estimate Std.Error   t value Pr(>|t|) Lower 95% Upper 95%
---------------------------------------------------------------
x    -0.343138  0.516953 -0.663771    0.509  -1.35635   0.67007
===============================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions