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

New data structures to support multiple replicate methods. #297

Merged
merged 21 commits into from
May 11, 2023

Conversation

codetalker7
Copy link
Member

@codetalker7 codetalker7 commented May 2, 2023

This PR introduces a "replicate type" for every ReplicateDesign object. The purpose is mainly to help with multiple dispatch on difference replicate methods.

We have introduced a new abstract type called InferenceMethod, which will be a supertype for all inference types. For now, the package only supports two inference methods, which we've encoded by the BootstrapReplicates and JackknifeReplicates structs.

Relevant changes have been made to the ReplicateDesign struct to incorporate the new structure.

Also, the mean, total and quantile functions have now been written using the generic variance function. Since ratio takes two columns as it's arguments, it can't be implemented using variance as of now (see #295 ).

Closes #261

@codetalker7
Copy link
Member Author

The main crux of the code has been added; now I'll work on the documentation and modifying the tests.

@codetalker7 codetalker7 marked this pull request as ready for review May 2, 2023 15:30
@codecov-commenter
Copy link

codecov-commenter commented May 2, 2023

Codecov Report

Merging #297 (79b4c39) into main (0703cfc) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #297   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          242       245    +3     
=========================================
+ Hits           242       245    +3     
Impacted Files Coverage Δ
src/SurveyDesign.jl 100.00% <100.00%> (ø)
src/bootstrap.jl 100.00% <100.00%> (ø)
src/jackknife.jl 100.00% <100.00%> (ø)
src/mean.jl 100.00% <100.00%> (ø)

src/jackknife.jl Outdated
@@ -127,7 +127,7 @@ julia> jackknife_variance(:api00, weightedmean, rstrat)
# Reference
pg 380-382, Section 9.3.2 Jackknife - Sharon Lohr, Sampling Design and Analysis (2010)
"""
function jackknife_variance(x::Symbol, func::Function, design::ReplicateDesign)
function jackknife_variance(x::Symbol, func::Function, design::ReplicateDesign{JackknifeReplicates})
Copy link
Member

Choose a reason for hiding this comment

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

It should just be called variance. There should be 2 dispatches.

  1. variance(x::Symbol, func::Function, design::ReplicateDesign{JackknifeReplicates})
  2. variance(x::Symbol, func::Function, design::ReplicateDesign{BootstrapReplicates})

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, but we don't have a variance method for BootstrapReplicates method yet, do we?

Copy link
Member Author

@codetalker7 codetalker7 May 3, 2023

Choose a reason for hiding this comment

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

Also, should I rewrite the mean function using multiple dispatch now, or should that be done as a separate PR?

Copy link
Member

Choose a reason for hiding this comment

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

We should rewrite the functions now.
And we need a variance function for BootstrapReplicates. It's pretty simple, it's just the simple variable of the estimates.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should rewrite the functions now. And we need a variance function for BootstrapReplicates. It's pretty simple, it's just the simple variable of the estimates.

Okay. Also, just to confirm: haven't we already implemented the variance function for BootstrapReplicates in the mean function in line 48 of this file?: https://github.com/xKDR/Survey.jl/blob/main/src/mean.jl

So we should probably get rid of this mean function right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we should get rid of it, and

function variance(x::Symbol, func::Function, design::ReplicateDesign{BootstrapReplicates})
...
variance = sum((θ̂t .- θ̂) .^ 2) / design.replicates
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@ayushpatnaikgit ayushpatnaikgit merged commit ada9354 into xKDR:main May 11, 2023
@codetalker7 codetalker7 mentioned this pull request May 16, 2023
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.

Changes in data structures to support more replicate methods
3 participants