Skip to content

Commit

Permalink
Merge pull request #187 from ayushpatnaikgit/jnkremove
Browse files Browse the repository at this point in the history
Remove jackknife and use bootstrap in ratio estimation.
  • Loading branch information
ayushpatnaikgit authored Jan 20, 2023
2 parents c7126a1 + 8bb8bfd commit 800c361
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/Survey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ include("SurveyDesign.jl")
include("bootstrap.jl")
include("mean.jl")
include("quantile.jl")
include("jackknife.jl")
include("total.jl")
include("load_data.jl")
include("hist.jl")
Expand Down
16 changes: 0 additions & 16 deletions src/jackknife.jl

This file was deleted.

33 changes: 11 additions & 22 deletions src/ratio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@ Estimate the ratio of the columns specified in numerator and denominator
```jldoctest
julia> apiclus1 = load_data("apiclus1");
julia> clus_one_stage = SurveyDesign(apiclus1; clusters = :dnum, weights = :pw);
julia> clus_one_stage = SurveyDesign(apiclus1; clusters = :dnum, weights = :pw) |> bootweights;
julia> ratio(:api00, :enroll, clus_one_stage)
ratio(:api00, :enroll, clus_one_stage)
1×2 DataFrame
Row │ Statistic SE
│ Float64 Float64
─────┼─────────────────────
1 │ 1.17182 0.151242
Row │ ratio SE
│ Float64 Float64
─────┼───────────────────
1 │ 1.17182 0.130834
```
"""
function ratio(variable_num:: Symbol, variable_den:: Symbol, design::SurveyDesign)
statistic = wsum(design.data[!,variable_num],design.data[!,design.weights])/wsum(design.data[!,variable_den],design.data[!,design.weights])
nh = length(unique(design.data[!,design.cluster]))
newv = []
gdf = groupby(design.data, design.cluster)
replicates = [filter(n -> n != i, 1:nh) for i in 1:nh]
for i in replicates
df = DataFrame(gdf[i])
push!(newv, wsum(df[!,variable_num],df[!,design.weights])/wsum(df[!,variable_den],df[!,design.weights]))
end
c = 0
for i in 1:nh
c = c+(newv[i]-statistic)^2
end
var = c*(nh-1)/nh
return DataFrame(Statistic = statistic, SE = sqrt(var))
function ratio(variable_num::Symbol, variable_den::Symbol, design::ReplicateDesign)
X = wsum(design.data[!, variable_num], design.data[!, design.weights]) / wsum(design.data[!, variable_den], design.data[!, design.weights])
Xt = [(wsum(design.data[!, variable_num], weights(design.data[! , "replicate_"*string(i)]))) / (wsum(design.data[!, variable_den], weights(design.data[! , "replicate_"*string(i)]))) for i in 1:design.replicates]
variance = sum((Xt .- X).^2) / design.replicates
DataFrame(ratio = X, SE = sqrt(variance))
end
8 changes: 0 additions & 8 deletions test/jackknife.jl

This file was deleted.

6 changes: 3 additions & 3 deletions test/ratio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##############################
# one-stage cluster sample
apiclus1 = copy(apiclus1_original)
dclus1 = SurveyDesign(apiclus1; clusters = :dnum, popsize = :fpc)
@test ratio(:api00, :enroll, dclus1).SE[1] 0.151242 atol = 1e-4
@test ratio(:api00, :enroll, dclus1).Statistic[1] 1.17182 atol = 1e-4
dclus1 = SurveyDesign(apiclus1; clusters = :dnum, popsize = :fpc) |> bootweights
@test ratio(:api00, :enroll, dclus1).SE[1] 0.1275446 atol = 1e-1
@test ratio(:api00, :enroll, dclus1).ratio[1] 1.17182 atol = 1e-4
end

0 comments on commit 800c361

Please sign in to comment.