-
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 #147 from sayantikaSSG/jackknife2
Add Jackknife
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function jkknife(variable:: Symbol, design::OneStageClusterSample ,func:: Function; params =[]) | ||
statistic = func(design.data[!,variable],params...) | ||
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 | ||
push!(newv,func(DataFrame(gdf[i])[!,variable])) | ||
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)) | ||
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,10 @@ | ||
@testset "jackknife.jl" begin | ||
apiclus1_original = load_data("apiclus1") | ||
apiclus1_original[!, :pw] = fill(757/15,(size(apiclus1_original,1),)) # Correct api mistake for pw column | ||
############################## | ||
# one-stage cluster sample | ||
apiclus1 = copy(apiclus1_original) | ||
dclus1 = OneStageClusterSample(apiclus1, :dnum, :fpc) | ||
@test jkknife(:api00,dclus1, mean).SE[1] ≈ 26.5997 atol = 1e-4 | ||
@test jkknife(:api00, dclus1, mean).Statistic[1] ≈ 644.1693 atol = 1e-4 | ||
end |