Skip to content

Commit

Permalink
Updates for Julia 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lbittarello committed Oct 13, 2018
1 parent 49211ae commit 36f0023
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
25 changes: 13 additions & 12 deletions src/general/etable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ function etable(args...;
)

N = length(args)
fspec = FormatSpec("0.$(digits)f")
cutpoints, symbols = _parsestars(stars)

(titles == [""]) && (titles = String["(" * string(i) * ")" for i = 1:N])

μ = Vector{Vector{String}}(N)
β = Vector{Vector{String}}(N)
σ = Vector{Vector{String}}(N)
μ = Vector{Vector{String}}(undef, N)
β = Vector{Vector{String}}(undef, N)
σ = Vector{Vector{String}}(undef, N)

for (i, ai) in enumerate(args)

μ[i] = coefnames(ai)
β[i] = fmt.(fspec, coef(ai))
β[i] = format.("{:.$(digits)f}", coef(ai))

(typeof(aux) == Void) || (σ[i] = "(" .* fmt.(fspec, aux(ai)) .* ")")
if typeof(aux) != Nothing
σ[i] = "(" .* format.("{:.$(digits)f}", aux(ai)) .* ")"
end

if cutpoints != []
for (j, pj) in enumerate(pval(ai))
Expand All @@ -36,7 +37,7 @@ function etable(args...;

inter = union...)

if typeof(aux) == Void
if typeof(aux) == Nothing
output = vcat("", inter)
else
output = fill("", 2 * length(inter) + 1)
Expand All @@ -50,12 +51,12 @@ function etable(args...;

for (i, (ni, ti, βi)) in enumerate(zip(μ, titles, β))
idx = findall((in)(ni), inter)
(typeof(aux) == Void) || (idx .= 2 * idx - 1)
(typeof(aux) == Nothing) || (idx .= 2 .* idx .- 1)
w2 .= ""
w2[idx] .= βi
(typeof(aux) == Void) || (w2[idx + 1] .= σ[i])
(typeof(aux) == Nothing) || (w2[(idx .+ 1)] .= σ[i])
_alignatchar!(w2, '.')
w1[1] .= ti
w1[1] = ti
w1[2:end] .= w2
_alignatchar!(w1)
output .*= " " .* w1
Expand All @@ -72,7 +73,7 @@ end

function _parsestars(x::Matrix{Any})
if size(x, 1) != 0
s = sortrows(x)
s = sort(x, dims = 1, rev = true)
cutpoints = vcat(0.0, convert(Vector{Float64}, s[:, 1]), 1.0)
symbols = vcat(convert(Vector{String}, s[:, 2]), "")
else
Expand All @@ -97,7 +98,7 @@ end
# ALIGN STRING VECTOR AT FIRST OCCURRENCE OF CHARACTER

function _alignatchar!(x::Vector{String}, y::Char)
pos = search.(x, y)
pos = findlast.(z -> z == y, x)
maxpos = maximum(pos)
add = " " .^ (maxpos .- pos)
x .= add .* x
Expand Down
2 changes: 1 addition & 1 deletion src/general/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mutable struct ParEstimate
β::AbstractArray
V::AbstractArray

ParObject() = new()
ParEstimate() = new()
end

const Par1S = Union{ParModel, GMM, ParEstimate}
Expand Down
14 changes: 7 additions & 7 deletions src/inference/hausman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ function hausman_1s(obj₁::ParM2S, obj₂::ParM2S, name::String )
return hausman_1s(obj₁, obj₂, [name])
end

function hausman_1s(obj₁::ParM2S, obj₂::ParM2S,names::Vector{String})
function hausman_1s(obj₁::ParM2S, obj₂::ParM2S, names::Vector{String})

i₁ = indexin(names, coefnames(obj₁))
i₂ = indexin(names, coefnames(obj₂))
i₁ = findall((in)(names), coefnames(obj₁))
i₂ = findall((in)(names), coefnames(obj₂))
w₁ = getweights(obj₁)
w₂ = getweights(obj₂)
corr₁ = getcorr(obj₁)
Expand Down Expand Up @@ -202,8 +202,8 @@ end

function hausman_2s(obj₁::ParM2S, obj₂::ParM2S, names::Vector{String})

i₁ = indexin(names, coefnames(obj₁))
i₂ = indexin(names, coefnames(obj₂))
i₁ = findall((in)(names), coefnames(obj₁))
i₂ = findall((in)(names), coefnames(obj₂))

(iszero(i₁) | iszero(i₂)) && throw("missing coefficients in at least one model")

Expand All @@ -229,8 +229,8 @@ end

function hausman_2s(obj₁::ParM2S, obj₂::ParM2S, corr::CorrStructure, names::Vector{String})

i₁ = indexin(names, coefnames(obj₁))
i₂ = indexin(names, coefnames(obj₂))
i₁ = findall((in)(names), coefnames(obj₁))
i₂ = findall((in)(names), coefnames(obj₂))
w₁ = getweights(obj₁)
w₂ = getweights(obj₂)

Expand Down
2 changes: 1 addition & 1 deletion src/inference/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Base.isequal(corr₁::C, corr₂::C) where {C <: CorrStructure}

output = true

for k in fieldnames(corr₁)
for k in fieldnames(typeof(corr₁))
output *= isequal(getfield(corr₁, k), getfield(corr₂, k))
end

Expand Down

0 comments on commit 36f0023

Please sign in to comment.