Skip to content

Commit a17477e

Browse files
Use Vcov + correct partial_out with weights + allow nthreads option (#124)
* add align kwarg * Update partial_out.jl * update to 1.2 * Update README.md * Update README.md
1 parent 67c7ef6 commit a17477e

19 files changed

Lines changed: 201 additions & 408 deletions

Project.toml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
name = "FixedEffectModels"
22
uuid = "9d5cd8c9-2029-5cab-9928-427838db53e3"
3-
version = "1.1.0"
3+
version = "1.2.0"
44

55
[deps]
6-
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
76
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
8-
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
9-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
107
FixedEffects = "c8885935-8500-56a7-9867-7708b20db0eb"
118
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
129
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
13-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1410
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1511
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1612
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
13+
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
1714
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
1815
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
16+
Vcov = "ec2bfdc2-55df-4fc9-b9ae-4958c2cf2486"
1917

2018
[compat]
21-
Combinatorics = "0, 1"
2219
DataFrames = "0.21"
23-
Distributions = "0"
24-
FillArrays = "0"
25-
FixedEffects = "1"
26-
Reexport = "0"
27-
StatsBase = "0.32, 0.33"
20+
FixedEffects = "1.1"
21+
Reexport = "0.1, 0.2"
22+
StatsBase = "0.33"
23+
StatsFuns = "0.9"
2824
StatsModels = "0.6"
2925
Tables = "1"
26+
Vcov = "0.3"
3027
julia = "1.3"
3128

3229
[extras]
3330
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
3431
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
35-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3632
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
37-
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3833
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3934

4035
[targets]
41-
test = ["CSV", "CUDA", "LinearAlgebra", "Random", "Statistics", "Test"]
36+
test = ["CSV", "CUDA", "Random", "Test"]

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), Vcov.cluster(:State), weig
5151
reg(df, term(:Sales) ~ term(:NDI) + fe(:State) + fe(:Year))
5252
```
5353

54-
- Standard errors are indicated with the prefix `Vcov`.
54+
- Standard errors are indicated with the prefix `Vcov` (with the package [Vcov](http://github.com/matthieugomez/Vcov.jl))
5555
```julia
5656
Vcov.robust()
5757
Vcov.cluster(:State)
@@ -61,11 +61,8 @@ reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), Vcov.cluster(:State), weig
6161
```julia
6262
weights = :Pop
6363
```
64-
- The option `subset` specifies a subset of the data
65-
```julia
66-
subset = df.State .>= 30
67-
```
68-
- The option `save` can be set to one of the following: `:residuals` to save residuals, `:fe` to save fixed effects, `true` to save both. You can access the result with `residuals()` and `fe()`
64+
65+
- The option `save` can be set to one of the following: `none` (default) to save nothing `:residuals` to save residuals, `:fe` to save fixed effects. You can access the result with `residuals()` and `fe()`
6966

7067
- The option `method` can be set to one of the following: `:cpu`, `:gpu` (see Performances below).
7168

@@ -106,9 +103,9 @@ reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), method = :gpu, double_prec
106103
## Solution Method
107104
Denote the model `y = X β + D θ + e` where X is a matrix with few columns and D is the design matrix from categorical variables. Estimates for `β`, along with their standard errors, are obtained in two steps:
108105

109-
1. `y, X` are regressed on `D` using the package [FixedEffects.jl](https://github.com/matthieugomez/FixedEffects.jl)
106+
1. `y, X` are regressed on `D` using the package [FixedEffects.jl](https://github.com/FixedEffects/FixedEffects.jl)
110107
2. Estimates for `β`, along with their standard errors, are obtained by regressing the projected `y` on the projected `X` (an application of the Frisch Waugh-Lovell Theorem)
111-
3. With the option `save = true`, estimates for the high dimensional fixed effects are obtained after regressing the residuals of the full model minus the residuals of the partialed out models on `D` using the package [FixedEffects.jl](https://github.com/matthieugomez/FixedEffects.jl)
108+
3. With the option `save = true`, estimates for the high dimensional fixed effects are obtained after regressing the residuals of the full model minus the residuals of the partialed out models on `D` using the package [FixedEffects.jl](https://github.com/FixedEffects/FixedEffects.jl)
112109

113110
# References
114111

src/FixedEffectModel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ StatsBase.mss(x::FixedEffectModel) = deviance(x) - rss(x)
6363

6464

6565
function StatsBase.confint(x::FixedEffectModel)
66-
scale = quantile(TDist(dof_residual(x)), 1 - (1-0.95)/2)
66+
scale = tdistinvcdf(dof_residual(x), 1 - (1 - 0.95) / 2)
6767
se = stderror(x)
6868
hcat(x.coef - scale * se, x.coef + scale * se)
6969
end
@@ -172,7 +172,7 @@ function StatsBase.coeftable(x::FixedEffectModel)
172172
end
173173
tt = cc ./ se
174174
CoefTable2(
175-
hcat(cc, se, tt, ccdf.(Ref(FDist(1, dof_residual(x))), abs2.(tt)), conf_int[:, 1:2]),
175+
hcat(cc, se, tt, fdistccdf.(Ref(1), Ref(dof_residual(x)), abs2.(tt)), conf_int[:, 1:2]),
176176
["Estimate","Std.Error","t value", "Pr(>|t|)", "Lower 95%", "Upper 95%" ],
177177
["$(coefnms[i])" for i = 1:length(cc)], 4, ctitle, ctop)
178178
end

src/FixedEffectModels.jl

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,42 @@
11

22
module FixedEffectModels
33

4-
##############################################################################
5-
##
6-
## Dependencies
7-
##
8-
##############################################################################
4+
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel"))
5+
@eval Base.Experimental.@optlevel 1
6+
end
7+
8+
using DataFrames
9+
using FixedEffects
910
using LinearAlgebra
10-
using Statistics
1111
using Printf
12-
using FillArrays
13-
using DataFrames
14-
using Distributions
1512
using Reexport
16-
using Tables
17-
using FixedEffects
18-
@reexport using StatsBase
13+
using Statistics
14+
using StatsBase
15+
using StatsFuns
1916
@reexport using StatsModels
20-
21-
##############################################################################
22-
##
23-
## Exported methods and types
24-
##
25-
##############################################################################
26-
27-
export reg,
28-
partial_out,
29-
fe,
30-
FixedEffectModel,
31-
has_iv,
32-
has_fe,
33-
Vcov
34-
35-
##############################################################################
36-
##
37-
## Load files
38-
##
39-
##############################################################################
40-
include("vcov/Vcov.jl")
17+
using Tables
18+
using Vcov
4119

4220
include("utils/fixedeffects.jl")
4321
include("utils/basecol.jl")
4422
include("utils/tss.jl")
45-
include("utils/ranktest.jl")
4623
include("utils/formula.jl")
47-
48-
4924
include("FixedEffectModel.jl")
5025
include("fit.jl")
5126
include("partial_out.jl")
5227

28+
include("precompile.jl")
29+
_precompile_()
30+
31+
# Export from StatsBase
32+
export coef, coefnames, responsename, vcov, stderror, nobs, dof_residual, r2, adjr2, islinear, deviance, rss, mss, confint, predict, residuals
33+
34+
export reg,
35+
partial_out,
36+
fe,
37+
FixedEffectModel,
38+
has_iv,
39+
has_fe,
40+
Vcov
5341

54-
end # module FixedEffectModels
42+
end

0 commit comments

Comments
 (0)