Skip to content

Commit

Permalink
update to FE 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugomez committed Oct 27, 2019
1 parent be97d4b commit 557c1b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Project.toml
@@ -1,6 +1,6 @@
name = "InteractiveFixedEffectModels"
uuid = "80307280-efb2-5c5d-af8b-a9c15821677b"
version = "0.6.0"
version = "0.6.1"

[deps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -26,7 +26,7 @@ StatsBase = "0"
StatsModels = "0.6"
Tables = "0"
DataFrames = "0.19"
FixedEffects = "0.4, 0.5"
FixedEffects = "0.6"
FixedEffectModels = "0.9, 0.10"
LeastSquaresOptim = "0.7"

Expand Down
11 changes: 4 additions & 7 deletions README.md
@@ -1,6 +1,10 @@
[![Build Status](https://travis-ci.org/matthieugomez/InteractiveFixedEffectModels.jl.svg?branch=master)](https://travis-ci.org/matthieugomez/InteractiveFixedEffectModels.jl)
[![Coverage Status](https://coveralls.io/repos/matthieugomez/InteractiveFixedEffectModels.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/matthieugomez/InteractiveFixedEffectModels.jl?branch=master)

## Installation
The package is registered in the [`General`](https://github.com/JuliaRegistries/General) registry and so can be installed at the REPL with

`] add InteractiveFixedEffectModels`.

## Motivation
This package implements a novel, fast and robust algorithm to estimate interactive fixed effect models.
Expand Down Expand Up @@ -113,10 +117,3 @@ In presence of cross or time correlation beyond the factor structure, the estima
- https://github.com/joidegn/FactorModels.jl : fits and predict factor models on matrices
- https://github.com/madeleineudell/LowRankModels.jl : fits general low rank approximations on matrices
- https://github.com/aaw/IncrementalSVD.jl: implementation of the backpropagation algorithm
## Install
```julia
using Pkg
Pkg.add("InteractiveFixedEffectModels")
```
15 changes: 9 additions & 6 deletions src/fit.jl
Expand Up @@ -87,10 +87,13 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
vcov_method_data = Vcov.materialize(view(df, esample,:), vcov)

# Compute weights
sqrtw = Ones{Float64}(sum(esample))
if has_weights
sqrtw = convert(Vector{Float64}, sqrt.(view(df, esample, weights)))
end
# Compute weights
if has_weights
weights = Weights(convert(Vector{Float64}, view(df, esample, weights)))
else
weights = Weights(Ones{Float64}(sum(esample)))
end
sqrtw = sqrt.(values(weights))
for a in FixedEffectModels.eachterm(formula.rhs)
if has_fe(a)
isa(a, InteractionTerm) && error("Fixed effects cannot be interacted")
Expand All @@ -111,7 +114,7 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
has_fes_intercept = true
end
fes = FixedEffect[FixedEffectModels._subset(fe, esample) for fe in fes]
feM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(fes, sqrtw, Val{:lsmr})
feM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(fes, weights, Val{:lsmr})
end


Expand Down Expand Up @@ -203,7 +206,7 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
# y ~ x + γ1 x factors + γ2 x loadings
# if not, this means fit! ended up on a a local minimum.
# restart with randomized coefficients, factors, loadings
newfeM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(getfactors(fp, fs), sqrtw, Val{:lsmr})
newfeM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(getfactors(fp, fs), weights, Val{:lsmr})
ym .= ym ./sqrtw
FixedEffectModels.solve_residuals!(ym, newfeM, tol = tol, maxiter = maxiter)
ym .= ym .* sqrtw
Expand Down

0 comments on commit 557c1b8

Please sign in to comment.