Skip to content

Commit f0a03dc

Browse files
Update README.md (#59)
* Update README.md * Update fit.jl * Update Project.toml * Update fit.jl * Update Project.toml * Update fit.jl
1 parent 4d2adba commit f0a03dc

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InteractiveFixedEffectModels"
22
uuid = "80307280-efb2-5c5d-af8b-a9c15821677b"
3-
version = "1.3.0"
3+
version = "1.3.1"
44

55
[deps]
66
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
@@ -23,7 +23,7 @@ Vcov = "ec2bfdc2-55df-4fc9-b9ae-4958c2cf2486"
2323
[compat]
2424
DataFrames = "0.21, 0.22, 1"
2525
FillArrays = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 1"
26-
FixedEffectModels = "1.11"
26+
FixedEffectModels = "1.12"
2727
FixedEffects = "2"
2828
GroupedArrays = "0.3"
2929
LeastSquaresOptim = "0.7, 0.8"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build status](https://github.com/matthieugomez/InteractiveFixedEffectModels.jl/workflows/CI/badge.svg)](https://github.com/matthieugomez/InteractiveFixedEffectModels.jl/actions)
1+
[![Build status](https://github.com/FixedEffects/InteractiveFixedEffectModels.jl/workflows/CI/badge.svg)](https://github.com/FixedEffects/InteractiveFixedEffectModels.jl/actions)
22
[![Coverage Status](https://coveralls.io/repos/matthieugomez/InteractiveFixedEffectModels.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/matthieugomez/InteractiveFixedEffectModels.jl?branch=master)
33

44
## Installation

src/fit.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,29 @@ function regife(
6767
Symbol(fesymbol(a)) factor_vars && error("FixedEffect should correspond to id or time dimension of the factor model")
6868
end
6969
end
70-
fes, ids, fekeys, formula = FixedEffectModels.parse_fixedeffect(df, formula)
71-
has_fes = !isempty(fes)
72-
has_fes_intercept = false
73-
## Compute factors, an array of AbtractFixedEffects
70+
formula, formula_fes = FixedEffectModels.parse_fe(formula)
71+
has_fes = formula_fes != FormulaTerm(ConstantTerm(0), ConstantTerm(0))
72+
73+
fes, feids, fekeys = FixedEffectModels.parse_fixedeffect(df, formula_fes)
74+
has_fe_intercept = any(fe.interaction isa UnitWeights for fe in fes)
75+
76+
# remove intercept if absorbed by fixed effects
77+
if has_fe_intercept
78+
formula = FormulaTerm(formula.lhs, tuple(InterceptTerm{false}(), (term for term in eachterm(formula.rhs) if !isa(term, Union{ConstantTerm,InterceptTerm}))...))
79+
end
80+
has_intercept = hasintercept(formula)
81+
82+
7483
if has_fes
75-
if any([isa(fe.interaction, Ones) for fe in fes])
76-
formula = FormulaTerm(formula.lhs, tuple(ConstantTerm(0), (t for t in eachterm(formula.rhs) if t!= ConstantTerm(1))...))
77-
has_fes_intercept = true
84+
if any(fe.interaction isa UnitWeights for fe in fes)
85+
has_fe_intercept = true
7886
end
7987
fes = FixedEffect[fe[esample] for fe in fes]
8088
feM = AbstractFixedEffectSolver{Float64}(fes, weights, Val{:cpu})
8189
end
8290

8391

84-
has_intercept = ConstantTerm(1) eachterm(formula.rhs)
92+
8593

8694

8795
iterations = 0
@@ -101,7 +109,7 @@ function regife(
101109
formula_schema = apply_schema(formula, schema(formula, subdf, contrasts), StatisticalModel)
102110

103111
y = convert(Vector{Float64}, response(formula_schema, subdf))
104-
tss_total = tss(y, has_intercept || has_fes_intercept, weights)
112+
tss_total = tss(y, has_intercept | has_fe_intercept, weights)
105113

106114
X = convert(Matrix{Float64}, modelmatrix(formula_schema, subdf))
107115

@@ -227,7 +235,7 @@ function regife(
227235
# compute various r2
228236
nobs = sum(esample)
229237
rss = sum(abs2, residualsm)
230-
_tss = tss(ym ./ sqrtw, has_intercept || has_fes_intercept, weights)
238+
_tss = tss(ym ./ sqrtw, has_intercept | has_fe_intercept, weights)
231239
r2_within = 1 - rss / _tss
232240

233241
rss = sum(abs2, residuals)
@@ -269,8 +277,8 @@ function regife(
269277
# get fixed effect
270278
newfes, b, c = solve_coefficients!(oldresiduals, feM; tol = tol, maxiter = maxiter)
271279
for j in 1:length(fes)
272-
augmentdf[!, ids[j]] = Vector{Union{Float64, Missing}}(missing, length(esample))
273-
augmentdf[esample, ids[j]] = newfes[j]
280+
augmentdf[!, feids[j]] = Vector{Union{Float64, Missing}}(missing, length(esample))
281+
augmentdf[esample, feids[j]] = newfes[j]
274282
end
275283
end
276284
end

0 commit comments

Comments
 (0)