Skip to content

Commit

Permalink
Merge pull request #68 from sayantikaSSG/design_update
Browse files Browse the repository at this point in the history
Added Tests and found bugs to be fixed in src/
  • Loading branch information
sayantikaSSG authored Nov 2, 2022
2 parents bc6b242 + 437393d commit 12b9132
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
23 changes: 21 additions & 2 deletions test/SurveyDesign.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "SurveyDesign.jl" begin
@testset "SimpleRandomSample" begin
# SimpleRandomSample tests
apisrs_original = load_data("apisrs")
apisrs = copy(apisrs_original)
Expand All @@ -14,6 +14,25 @@
# TODO: needs change; this works but isn't what the user is expecting
srs_prob = SimpleRandomSample(apisrs; probs = fill(0.3, size(apisrs_original, 1)))
@test srs_prob.data.probs[1] == 0.3
@test srs_prob.data.weights == 1 ./ srs_prob.data.probs

srs = SimpleRandomSample(apisrs, ignorefpc = true, weights = :pw )
@test srs.data.probs == 1 ./ srs.data.weights

srs = SimpleRandomSample(apisrs, ignorefpc = false, weights = :pw)
@test srs.data.probs == 1 ./ srs.data.weights

srs_weights = SimpleRandomSample(apisrs, ignorefpc = false, weights = :fpc)
@test_throws srs_weights = SimpleRandomSample(apisrs, ignorefpc = false, weights = :stype)
srs_w_p = SimpleRandomSample(apisrs, ignorefpc = false, weights = :fpc, probs = fill(0.3, size(apisrs_original, 1)))

srs = SimpleRandomSample(apisrs, ignorefpc = true, probs = 1 ./ apisrs.pw )
@test srs.data.probs == 1 ./ srs.data.weights
srs = SimpleRandomSample(apisrs, popsize = -2.8, ignorefpc = true)# the errror is wrong
srs = SimpleRandomSample(apisrs, sampsize = -2.8, ignorefpc = true)# the function is working upto line 55

# StratifiedSample tests
end

@testset "StratifiedSample" begin
# StratifiedSample tests
end
15 changes: 13 additions & 2 deletions test/svymean.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
@testset "svymean.jl" begin
# SimpleRandomSample
using DataFrames
apisrs = load_data("apisrs")
apisrs.apidiff = apisrs.api00 - apisrs.api99
apisrs.apipct = apisrs.apidiff ./ apisrs.api99
srs = SimpleRandomSample(apisrs, popsize = apisrs.fpc)
# with fpc

@test svymean(:api00, srs).mean[1] == 656.585
@test svymean(:api00, srs).sem[1] 9.249722039282807
@test svymean(:enroll, srs).mean[1] 584.61
@test svymean(:enroll, srs).sem[1] 27.36836524766856
# without fpc

srs = SimpleRandomSample(apisrs, ignorefpc = true)
@test svymean(:api00, srs).mean[1] == 656.585
@test svymean(:api00, srs).sem[1] 9.402772170880636

# with fpc
@test svymean(:enroll, srs).mean[1] 584.61
@test svymean(:enroll, srs).sem[1] 27.821214737089324
@test svymean([:apidiff, :apipct], srs).mean[1][1] 31.900000
@test svymean([:api99,:api00],srs).mean [624.685,656.585]

srs_weights = SimpleRandomSample(apisrs, ignorefpc = false, weights = :fpc)
@test svymean(:enroll, srs_weights).mean[1] 584.61

# StratifiedSample
srs_w_p = srs_weights = SimpleRandomSample(apisrs, ignorefpc = false, weights = :fpc, probs = fill(0.3, size(apisrs_original, 1)))
@test svymean(:enroll, srs_weights).mean[1] 584.61
end

0 comments on commit 12b9132

Please sign in to comment.