diff --git a/Project.toml b/Project.toml index 8c4aaa1..7b8ca14 100644 --- a/Project.toml +++ b/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" @@ -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" diff --git a/README.md b/README.md index a72a926..b65b3dc 100755 --- a/README.md +++ b/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. @@ -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") -``` diff --git a/src/fit.jl b/src/fit.jl index c104dbe..a4f3e68 100644 --- a/src/fit.jl +++ b/src/fit.jl @@ -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") @@ -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 @@ -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