Skip to content

Commit

Permalink
Merge pull request #13 from matthieugomez/patch-7
Browse files Browse the repository at this point in the history
rename df_Fstat to dof_tstat
  • Loading branch information
eloualiche authored Jun 28, 2022
2 parents 34a756f + 957a25b commit 912844e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name = "Vcov"
uuid = "ec2bfdc2-55df-4fc9-b9ae-4958c2cf2486"
version = "0.5.2"
version = "0.6.0"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
GroupedArrays = "6407cd72-fade-4a84-8a1e-56e431fc1533"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Combinatorics = "1"
GroupedArrays = "0.3"
StatsBase = "0.32, 0.33"
StatsAPI = "1"
StatsBase = "0.33"
Tables = "1"
julia = "1"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ completecases(table, ::CovarianceEstimator) = trues(size(df, 1))
materialize(table, v::CovarianceEstimator) = v
# return variance-covariance matrix
vcov(x::RegressionModel, ::CovarianceEstimator) = error("vcov not defined for this type")
# returns the degree of freedom for the F-statistic
df_FStat(x::RegressionModel, ::CovarianceEstimator, hasintercept::Bool) = dof_residual(x) - hasintercept
# returns the degree of freedom for the t-statistics and F-statistic
dof_tstat(x::RegressionModel, ::CovarianceEstimator, hasintercept::Bool) = dof_residual(x) - hasintercept
```

For now, it includes `Vcov.simple()`, `Vcov.robust()`, and `Vcov.cluster(...)`.
Expand Down
13 changes: 7 additions & 6 deletions src/Vcov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module Vcov
using Combinatorics: combinations
using GroupedArrays: GroupedArray
using LinearAlgebra: cholesky!, Symmetric, Hermitian, svd, rmul!, eigen, Diagonal
using StatsBase: StatsBase, dof_residual, RegressionModel, CovarianceEstimator, modelmatrix, crossmodelmatrix, residuals, dof_residual
using StatsAPI: StatsAPI, RegressionModel, modelmatrix, crossmodelmatrix, residuals, dof_residual
using StatsBase: CovarianceEstimator
using Tables: Tables
using Base: @propagate_inbounds

Expand All @@ -18,10 +19,10 @@ struct VcovData{T, N} <: RegressionModel
residuals::Array{Float64, N} # vector or matrix of residuals (matrix in the case of IV, residuals of Xendo on (Z, Xexo))
dof_residual::Int
end
StatsBase.modelmatrix(x::VcovData) = x.modelmatrix
StatsBase.crossmodelmatrix(x::VcovData) = x.crossmodelmatrix
StatsBase.residuals(x::VcovData) = x.residuals
StatsBase.dof_residual(x::VcovData) = x.dof_residual
StatsAPI.modelmatrix(x::VcovData) = x.modelmatrix
StatsAPI.crossmodelmatrix(x::VcovData) = x.crossmodelmatrix
StatsAPI.residuals(x::VcovData) = x.residuals
StatsAPI.dof_residual(x::VcovData) = x.dof_residual

##############################################################################
##
Expand All @@ -34,7 +35,7 @@ function completecases(table, ::CovarianceEstimator)
end
materialize(table, v::CovarianceEstimator) = v
S_hat(x::RegressionModel, ::CovarianceEstimator) = error("S_hat not defined for this type")
df_FStat(x::RegressionModel, ::CovarianceEstimator, hasintercept::Bool) = dof_residual(x) - hasintercept
dof_tstat(x::RegressionModel, ::CovarianceEstimator, hasintercept::Bool) = dof_residual(x) - hasintercept



Expand Down
4 changes: 2 additions & 2 deletions src/covarianceestimators/vcovcluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function nclusters(v::ClusterCovariance)
NamedTuple{names(v)}(map(x -> x.ngroups, v.clusters))
end

function df_FStat(x::RegressionModel, v::ClusterCovariance, ::Bool)
function dof_tstat(x::RegressionModel, v::ClusterCovariance, ::Bool)
minimum(nclusters(v)) - 1
end

Expand Down Expand Up @@ -110,7 +110,7 @@ function helper_cluster(X::Matrix, res::Union{Vector, Matrix}, g::GroupedArray)
return Symmetric(X2' * X2)
end

function StatsBase.vcov(x::RegressionModel, v::ClusterCovariance)
function StatsAPI.vcov(x::RegressionModel, v::ClusterCovariance)
xtx = inv(crossmodelmatrix(x))
pinvertible(Symmetric(xtx * S_hat(x, v) * xtx))
end
Expand Down
2 changes: 1 addition & 1 deletion src/covarianceestimators/vcovrobust.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function S_hat(x::RegressionModel, ::RobustCovariance)
Symmetric(rmul!(S2, size(m, 1) / dof_residual(x)))
end

function StatsBase.vcov(x::RegressionModel, v::RobustCovariance)
function StatsAPI.vcov(x::RegressionModel, v::RobustCovariance)
xtx = inv(crossmodelmatrix(x))
pinvertible(Symmetric(xtx * S_hat(x, v) * xtx))
end
Expand Down
2 changes: 1 addition & 1 deletion src/covarianceestimators/vcovsimple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function S_hat(x::RegressionModel, ::SimpleCovariance)
rmul!(crossmodelmatrix(x), sum(abs2, residuals(x)))
end

function StatsBase.vcov(x::RegressionModel, ::SimpleCovariance)
function StatsAPI.vcov(x::RegressionModel, ::SimpleCovariance)
invcrossmodelmatrix = Matrix(inv(crossmodelmatrix(x)))
rmul!(invcrossmodelmatrix, sum(abs2, residuals(x)) / dof_residual(x))
Symmetric(invcrossmodelmatrix)
Expand Down

2 comments on commit 912844e

@matthieugomez
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/63279

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 912844ea16946f212b67b4049536b852c6daff6e
git push origin v0.6.0

Please sign in to comment.