Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary variables, parameters and comments #122

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/total.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ function total(x::Symbol, design::StratifiedSample)
return combine(gdf, :weights => sum => :Nₕ)
end
gdf = groupby(design.data, design.strata)
grand_total = sum(combine(gdf, [x, :weights] => ((a, b) -> wsum(a, b)) => :total).total) # works
grand_total = sum(combine(gdf, [x, :weights] => ((a, b) -> wsum(a, b)) => :total).total)
# variance estimation using closed-form formula
ȳₕ = combine(gdf, x => mean => :mean).mean
Nₕ = combine(gdf, :weights => sum => :Nₕ).Nₕ
nₕ = combine(gdf, nrow => :nₕ).nₕ
fₕ = nₕ ./ Nₕ
Wₕ = Nₕ ./ sum(Nₕ)
Ȳ̂ = sum(Wₕ .* ȳₕ)

s²ₕ = combine(gdf, x => var => :s²h).s²h
# the only difference between total and mean variance is the Nₕ instead of Wₕ
Expand Down Expand Up @@ -112,14 +109,14 @@ DataFrameRow
"""
function total(x::Symbol, by::Symbol, design::SimpleRandomSample)
function domain_total(x::AbstractVector, design::SimpleRandomSample, weights)
function se(x::AbstractVector, design::SimpleRandomSample, _)
function se(x::AbstractVector, design::SimpleRandomSample)
# vector of length equal to `sampsize` containing `x` and zeros
z = cat(zeros(design.sampsize - length(x)), x; dims=1)
variance = design.popsize^2 / design.sampsize * design.fpc * var(z)
return sqrt(variance)
end
total = wsum(x, weights)
return DataFrame(total=total, SE=se(x, design::SimpleRandomSample, weights))
return DataFrame(total=total, SE=se(x, design::SimpleRandomSample))
end
gdf = groupby(design.data, by)
combine(gdf, [x, :weights] => ((a, b) -> domain_total(a, design, b)) => AsTable)
Expand Down