Comments (3)
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.
I have just fixed the first issue. @nilshg: could you have a look at the second one?
from fixedeffectmodels.jl.
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 leftjoin
ing 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)
- StatsBase version incompatibility HOT 1
- no method matching fe(::CategoricalValue
- MethodError: no method matching fe(::CategoricalValue{String15, UInt32}) HOT 1
- Implement StatsAPI.fit() HOT 1
- Generate confidence intervals for `predict` HOT 1
- Ignore rows with `Inf`s? HOT 3
- error in using gpu? HOT 3
- Feature request: GPU support in MacOS HOT 2
- Drop regressors that are collinear with the fixed effects (depending on tolerance for partialling-out)
- Get " run `reg` with the option save = :residuals" despite doing exactly that HOT 3
- How can I get the dof? HOT 2
- Degrees of freedom always 1 HOT 1
- Demeaning HOT 3
- Print name of dependent variable in FixedEffectModel results display? HOT 1
- tolerance in `invsym!` HOT 1
- Next release please! For Stata front-end HOT 4
- `predict` for fixed effects HOT 4
- Feature request: Saving an object of type `FixedEffectModel` HOT 1
- Using r2 as a regression name conflicts with r2 (r-squared?) HOT 1
- Wrong results in a large data set with one set of FE HOT 51
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fixedeffectmodels.jl.