Skip to content

predict doesn't work for FE-only models #258

@nilshg

Description

@nilshg

This is sort of self-assigned:

julia> using FixedEffectModels, DataFrames

julia> df = DataFrame(y=rand(10), id = rand(1:2, 10), t = rand(1:2, 10));

julia> predict(reg(df, @formula(y ~ fe(id) + fe(t)), save = :fe), df)
ERROR: ArgumentError: collection must be non-empty
Stacktrace:
 [1] first(itr::@NamedTuple{})
   @ Base .\abstractarray.jl:470
 [2] missing_omit(d::@NamedTuple{})
   @ StatsModels C:\Users\ngudat\.julia\packages\StatsModels\syVEq\src\modelframe.jl:57
 [3] missing_omit(data::@NamedTuple{y::Vector{Float64}, id::Vector{Int64}, t::Vector{Int64}}, formula::MatrixTerm{Tuple{InterceptTerm{false}}})
   @ StatsModels C:\Users\ngudat\.julia\packages\StatsModels\syVEq\src\modelframe.jl:70
 [4] predict(m::FixedEffectModel, data::DataFrame)
   @ FixedEffectModels C:\Users\ngudat\.julia\packages\FixedEffectModels\9B0we\src\FixedEffectModel.jl:142
 [5] top-level scope
   @ REPL[34]:1

julia> predict(reg(df, @formula(y ~ id + fe(t)), save = :fe), df)
10-element Vector{Float64}:
(...)

a workaround is to add a column of ones:

df.x .= 1
reg(@formula(y ~ -1 + x + fe(id) + fe(t))

but that's clearly not ideal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions