Skip to content

Commit

Permalink
Add Svymean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sayantikaSSG committed Oct 28, 2022
1 parent 123fb60 commit 32f4860
Showing 1 changed file with 13 additions and 2 deletions.
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 32f4860

Please sign in to comment.