diff --git a/test/SurveyDesign.jl b/test/SurveyDesign.jl index 17994e14..87be27de 100644 --- a/test/SurveyDesign.jl +++ b/test/SurveyDesign.jl @@ -1,4 +1,4 @@ -@testset "SurveyDesign.jl" begin +@testset "SimpleRandomSample" begin # SimpleRandomSample tests apisrs_original = load_data("apisrs") apisrs = copy(apisrs_original) @@ -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 \ No newline at end of file diff --git a/test/svymean.jl b/test/svymean.jl index 0b5c7f3e..b9b45810 100644 --- a/test/svymean.jl +++ b/test/svymean.jl @@ -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