-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from smishr/design_update
Design update some features
- Loading branch information
Showing
10 changed files
with
259 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
# TODO: add docstrings | ||
function HorwitzThompson_HartleyRaoApproximation(y::AbstractVector, design::AbstractSurveyDesign, HT_total) | ||
""" | ||
Hartley Rao Approximation of the variance of the Horvitz-Thompson Estimator. | ||
Avoids exhaustively calculating joint (inclusion) probabilities πᵢⱼ of the sampling scheme. | ||
""" | ||
function HT_HartleyRaoVarApprox(y::AbstractVector, design::AbstractSurveyDesign, HT_total) | ||
# TODO: change function name | ||
# TODO: change variable name (gets mixed up with the constant pi) | ||
pi = design.data.probs | ||
hartley_rao_var = sum((1 .- ((design.sampsize .- 1) ./ design.sampsize) .* pi) .* | ||
πᵢ = design.data.probs | ||
hartley_rao_var = sum((1 .- ((design.sampsize .- 1) ./ design.sampsize) .* πᵢ) .* | ||
((y .* design.data.weights) .- (HT_total ./ design.sampsize)) .^ 2) | ||
return sqrt(hartley_rao_var) | ||
return hartley_rao_var | ||
end | ||
|
||
# TODO: add docstrings | ||
function ht_calc(x::Symbol, design) | ||
# TODO: change function name | ||
""" | ||
Horvitz-Thompson Estimator of Population Total | ||
For arbitrary sampling probabilities | ||
""" | ||
function ht_svytotal(x::Symbol, design) | ||
total = wsum(Float32.(design.data[!, x]), design.data.weights) | ||
se = HorwitzThompson_HartleyRaoApproximation(design.data[!, x], design, total) | ||
return DataFrame(total = total, se = se) | ||
var_total = HT_HartleyRaoVarApprox(design.data[!, x], design, total) | ||
return DataFrame(total = total, se = sqrt(var_total)) | ||
end | ||
|
||
# TODO: add docstrings | ||
""" | ||
Horvitz-Thompson Estimator of Population Mean | ||
Scales the Population Total by the relevant | ||
""" | ||
function ht_svymean(x::Symbol, design) | ||
total_df = ht_svytotal(x, design) | ||
total = total_df.total[1] | ||
var_total = total_df.se[1] | ||
|
||
mean = 1.0 ./ sum(design.popsize) .* total | ||
# @show total_df, total, var_total, mean | ||
#1.0 ./ (sum(design.popsize).^2) .* | ||
|
||
se = sqrt( var_total ) | ||
|
||
@show design.popsize | ||
|
||
return DataFrame(mean = mean, se = se) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Postratification functions | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Sampling functions using various schemes | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Ratio estimators and Subpopulation estimates. | ||
Domain Estimation is special case of subpopulation estimate. | ||
""" | ||
|
||
function ratio(x::Symbol,y::Symbol,design::AbstractSurveyDesign) | ||
num = design.data[!,x] | ||
denom = design.data[!,y] | ||
# fill(A,) | ||
# A == B | ||
|
||
mean = num / denom | ||
return DataFrame(mean = mean) | ||
end |
Oops, something went wrong.