Giter Club home page Giter Club logo

Comments (3)

alfaromartino avatar alfaromartino commented on September 26, 2024

I just also noticed that adding an intercept in this way crashes predict if there are missing values (it works fine if there are no missing values). The MWE is:

df = DataFrame(a = rand(100), b = rand(100), c = rand(100), d = ones(100))
allowmissing!(df)
df.b[[30,40]] .= missing

ols = FixedEffectModels.reg(df, @formula(a ~ b + c + fe(d)), save = true)
residuals(ols) #this works fine
predict(ols,df) #this doesn't work

ols = FixedEffectModels.reg(df, @formula(a ~ b + c), save = true)
residuals(ols) #this gives error 
predict(ols,df) #this works fine

from fixedeffectmodels.jl.

matthieugomez avatar matthieugomez commented on September 26, 2024

I have just fixed the first issue. @nilshg: could you have a look at the second one?

from fixedeffectmodels.jl.

nilshg avatar nilshg commented on September 26, 2024

So what happens here is that with missing we are getting two predicted fixed effects for the one group included in the model:

julia> unique(ols.fe)
2×2 DataFrame
 Row │ d         fe_d
     │ Float64?  Float64?
─────┼──────────────────────────
   1 │      1.0        0.608499
   2 │      1.0  missing

Which then means when leftjoining fixed effects onto the original data to be able to add them to the predicted response, the data set is duplicated - every row with a fixed effect value of 1 will turn into one row with a fixed effect ot 0.6, and one with a missing fixed effect. We then get an error as the nonmissings vector used to pick the rows without missing data is only half as long as the data set we're indexing into following duplication.

I'm a little surprised that we end up with a missing fixed effect here, as I would have expected rows with missing observations to get dropped. The immediate issue would be solved by by replacing

fes = leftjoin(select(df, m.fekeys), unique(m.fe); on = m.fekeys, makeunique = true, matchmissing = :equal)

with

fes = leftjoin(select(df, m.fekeys), dropmissing(unique(m.fe)); on = m.fekeys, makeunique = true, matchmissing = :equal)

but it feels like a fix someplace before we reach predict might be more appropriate?

from fixedeffectmodels.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.