Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Tests and found bugs to be fixed in src/ #68

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

sayantikaSSG
Copy link
Collaborator

  1. Added tests regarding svymean for vector inputs
  2. Added tests for survey design using different factors like probs,
  3. Found that the process works even when the sum of the probabilities is more than 1
  4. Shows the wrong error when we put a negative number as a popsize
  5. Finds the error at line 55 when we put a negative number as a sampsize.

Suggesstion: We can proceed by checking whether the popsize or the sampsize is nonnegative integer.

@sayantikaSSG sayantikaSSG merged commit 12b9132 into xKDR:design_update Nov 2, 2022
@iuliadmtru
Copy link
Contributor

This PR does not pass the CI tests. It should not have been merged. We should revert and fix the errors before merging.

@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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @test_throws macro needs another argument, which is the error type. See the documentation. In this case the test throws a MethodError because of a lateral error (not because weights cannot be a string vector, but because the operations done on weights give errors for strings), which is fine for now but eventually it should throw a more specific error.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails and it should indeed fail because, I believe the probability weights should be frequency weights divided by population size. In this case, probs should be given apisrs.pw ./ apisrs.fpc and we should check that srs.data.weights == srs.data.probs .* srs.popsize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, remove the space before the last paranthesis on line 29.

@@ -1,19 +1,30 @@
@testset "svymean.jl" begin
# SimpleRandomSample
using DataFrames
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not be here. If you need to use DataFrames functionality use DataFrames. as prefix.


# StratifiedSample
srs_w_p = srs_weights = SimpleRandomSample(apisrs, ignorefpc = false, weights = :fpc, probs = fill(0.3, size(apisrs_original, 1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apisrs_original is undefined.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These last two lines give errors. There are no tests attached to them. We should check that these lines do indeed throw an error with @test_throws ERROR_NAME. Otherwise, they will simply throw errors (uncaught) and stop the process. If the error thrown right now is wrong, maybe we should wait to do the merge after we fix the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants