Skip to content

Commit

Permalink
Use SurveyDesign! for mutable operations
Browse files Browse the repository at this point in the history
This commit updates the usage of `SurveyDesign` to `SurveyDesign!` in various instances within the test suite. The change reflects the need for mutable operations on the survey design objects, aligning with the Julia convention of using the bang symbol (!) to indicate functions that modify their arguments in place. This adjustment ensures that the test suite correctly utilizes the API for creating and modifying survey designs, particularly in the context of applying bootstrap and jackknife weights, as well as handling different sampling strategies such as simple random sampling, stratified sampling, and cluster sampling. The update is critical for maintaining the integrity and accuracy of the survey analysis tests.
  • Loading branch information
EngPeterAtef committed Mar 19, 2024
1 parent 3e804b9 commit 278cf20
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ REPLICATES_REGEX = r"r*_\d"

# Simple random sample
apisrs = load_data("apisrs") # Load API dataset
srs = SurveyDesign(apisrs, weights=:pw)
srs = SurveyDesign!(apisrs, weights=:pw)
unitrange = UnitRange((length(names(apisrs))+1):(TOTAL_REPLICATES+length(names(apisrs))))
bsrs = srs |> bootweights # Create bootstrap replicate design
jsrs = srs |> jackknifeweights # Create jackknife replicate design
Expand All @@ -22,7 +22,7 @@ bsrs_regex = ReplicateDesign{BootstrapReplicates}(bsrs.data, REPLICATES_REGEX, w

# Stratified sample
apistrat = load_data("apistrat") # Load API dataset
dstrat = SurveyDesign(apistrat, strata=:stype, weights=:pw) # Create SurveyDesign
dstrat = SurveyDesign!(apistrat, strata=:stype, weights=:pw) # Create SurveyDesign
unitrange = UnitRange((length(names(apistrat))+1):(TOTAL_REPLICATES+length(names(apistrat))))
bstrat = dstrat |> bootweights # Create replicate design
bstrat_direct = ReplicateDesign{BootstrapReplicates}(bstrat.data, REPLICATES_VECTOR, strata=:stype, weights=:pw) # using ReplicateDesign constructor
Expand All @@ -32,7 +32,7 @@ bstrat_regex = ReplicateDesign{BootstrapReplicates}(bstrat.data, REPLICATES_REGE
# One-stage cluster sample
apiclus1 = load_data("apiclus1") # Load API dataset
apiclus1[!, :pw] = fill(757 / 15, (size(apiclus1, 1),)) # Correct api mistake for pw column
dclus1 = SurveyDesign(apiclus1; clusters=:dnum, weights=:pw) # Create SurveyDesign
dclus1 = SurveyDesign!(apiclus1; clusters=:dnum, weights=:pw) # Create SurveyDesign
unitrange = UnitRange((length(names(apiclus1))+1):(TOTAL_REPLICATES+length(names(apiclus1))))
dclus1_boot = dclus1 |> bootweights # Create replicate design
dclus1_boot_direct = ReplicateDesign{BootstrapReplicates}(dclus1_boot.data, REPLICATES_VECTOR, clusters=:dnum, weights=:pw) # using ReplicateDesign constructor
Expand All @@ -41,14 +41,14 @@ dclus1_boot_regex = ReplicateDesign{BootstrapReplicates}(dclus1_boot.data, REPLI

# Two-stage cluster sample
apiclus2 = load_data("apiclus2") # Load API dataset
dclus2 = SurveyDesign(apiclus2; clusters=:dnum, weights=:pw) # Create SurveyDesign
dclus2 = SurveyDesign!(apiclus2; clusters=:dnum, weights=:pw) # Create SurveyDesign
dclus2_boot = dclus2 |> bootweights # Create replicate design

# NHANES
nhanes = load_data("nhanes")
nhanes.seq1 = collect(1.0:5.0:42955.0)
nhanes.seq2 = collect(1.0:9.0:77319.0) # [9k for k in 0:8590.0]
dnhanes = SurveyDesign(nhanes; clusters=:SDMVPSU, strata=:SDMVSTRA, weights=:WTMEC2YR)
dnhanes = SurveyDesign!(nhanes; clusters=:SDMVPSU, strata=:SDMVSTRA, weights=:WTMEC2YR)
dnhanes_boot = dnhanes |> bootweights

@testset "Survey.jl" begin
Expand Down

0 comments on commit 278cf20

Please sign in to comment.