Skip to content

Commit a173917

Browse files
committed
update for new FixedEffectModels
1 parent 779240b commit a173917

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/InteractiveFixedEffectModels.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module InteractiveFixedEffectModels
2-
32
##############################################################################
43
##
54
## Dependencies

src/regife.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ function regife(df::AbstractDataFrame, m::Model; kwargs...)
88
regife(df, m.f; m.dict..., kwargs...)
99
end
1010

11-
#= salue
12-
13-
efe
14-
=#
15-
1611
function regife(df::AbstractDataFrame,
1712
f::Formula;
1813
ife::Union{Symbol, Expr, Nothing} = nothing,
@@ -83,22 +78,24 @@ function regife(df::AbstractDataFrame,
8378
# Compute data needed for errors
8479
vcov_method_data = VcovMethod(df[esample, unique(Symbol.(vcov_vars))], vcovformula)
8580

86-
# Compute weights
87-
sqrtw = get_weights(df, esample, weights)
88-
81+
8982
## Compute factors, an array of AbtractFixedEffects
9083
if has_absorb
91-
subdf = df[esample, unique(Symbol.(absorb_vars))]
92-
fes = FixedEffect(subdf, feformula, sqrtw)
84+
sqrtw = get_weights(df, trues(length(esample)), weights)
85+
fixedeffects = FixedEffect(df, Terms(@eval(@formula(nothing ~ $(feformula)))), sqrtw)
86+
fixedeffects = FixedEffect[x[esample] for x in fixedeffects]
9387
# in case some FixedEffect is a FixedEffectIntercept, remove the intercept
94-
if any([typeof(f.interaction) <: Ones for f in fes])
88+
if any([typeof(f.interactionname) <: Nothing for f in fixedeffects])
9589
rt.intercept = false
9690
end
97-
pfe = FixedEffectProblem(fes, Val{:lsmr})
91+
pfe = FixedEffectProblem(fixedeffects, Val{:lsmr})
9892
else
9993
pfe = nothing
10094
end
10195

96+
# Compute weights
97+
sqrtw = get_weights(df, esample, weights)
98+
10299
iterations = 0
103100
converged = false
104101
# get two dimensions
@@ -144,7 +141,9 @@ function regife(df::AbstractDataFrame,
144141
end
145142
y .= y .* sqrtw
146143
oldy = copy(y)
147-
residualize!(y, pfe, Int[], Bool[])
144+
v1 = Int[]
145+
v2 = Bool[]
146+
residualize!(y, pfe, v1, v2)
148147

149148
##############################################################################
150149
##
@@ -226,7 +225,7 @@ function regife(df::AbstractDataFrame,
226225
df_absorb_fe = 0
227226
if has_absorb
228227
## poor man adjustement of df for clustedered errors + fe: only if fe name != cluster name
229-
for fe in fes
228+
for fe in fixedeffects
230229
if isa(vcovformula, VcovClusterFormula) && in(fe.factorname, vcov_vars)
231230
df_absorb_fe += 0
232231
else

src/types.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,21 @@ function getfactors(fp::AbstractFactorModel, fs::AbstractFactorSolution)
105105
# partial out Y and X with respect to i.id x factors and i.time x loadings
106106
newfes = FixedEffect[]
107107
for r in 1:rank(fp)
108-
idfe = FixedEffect(fp.idrefs, size(fs.idpool, 1), fp.sqrtw, fs.timepool[fp.timerefs, r], :id, :time, :(idxtime))
108+
idfe = FixedEffect(fp.idrefs, fp.sqrtw, zeros(size(fs.idpool, 1)), fs.timepool[fp.timerefs, r], :id, :time, :(idxtime))
109+
for i in 1:length(idfe.refs)
110+
idfe.scale[idfe.refs[i]] += abs2(idfe.interaction[i] * idfe.sqrtw[i])
111+
end
112+
for i in 1:length(idfe.scale)
113+
idfe.scale[i] = idfe.scale[i] > 0 ? (1.0 / sqrt(idfe.scale[i])) : 0.
114+
end
109115
push!(newfes, idfe)
110-
timefe = FixedEffect(fp.timerefs, size(fs.timepool, 1), fp.sqrtw, fs.idpool[fp.idrefs, r], :time, :id, :(timexid))
116+
timefe = FixedEffect(fp.timerefs, fp.sqrtw, zeros(size(fs.timepool, 1)), fs.idpool[fp.idrefs, r], :time, :id, :(timexid))
117+
for i in 1:length(timefe.refs)
118+
timefe.scale[timefe.refs[i]] += abs2(timefe.interaction[i] * timefe.sqrtw[i])
119+
end
120+
for i in 1:length(timefe.scale)
121+
timefe.scale[i] = timefe.scale[i] > 0 ? (1.0 / sqrt(timefe.scale[i])) : 0.
122+
end
111123
push!(newfes, timefe)
112124
end
113125
# obtain the residuals and cross

0 commit comments

Comments
 (0)