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

jackknife_variance hardcoded for binary func #295

Open
smishr opened this issue Mar 27, 2023 · 3 comments
Open

jackknife_variance hardcoded for binary func #295

smishr opened this issue Mar 27, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@smishr
Copy link
Contributor

smishr commented Mar 27, 2023

In jackknife.jl line 152,

θhj = func(design.data[!, x], rep_weights)

The func will only apply over a single data vector x. This is fine for mean and total, but wont work for ratio, which needs y

In general case, we need a type system here so that func with different number of args can work here

@smishr smishr added the bug Something isn't working label Mar 27, 2023
@codetalker7
Copy link
Member

This issue is still relevant, but this PR changes the jackknife_variance function and calls it variance: #297

@ayushpatnaikgit
Copy link
Member

We can do the following:

function variance(x::Vector{Symbol}, func::Function, design::ReplicateDesign{BootstrapReplicates})
    θ̂ = func(design.data, x, design.weights)
    θ̂t = [
        func(design.data, x, "replicate_"*string(i)) for
        i = 1:design.replicates
    ]
    variance = sum.((θ̂t .- θ̂) .^ 2) ./ design.replicates
    return DataFrame(estimator = θ̂, SE = sqrt(variance))
end
function ratio(df::DataFrame, columns, weights)
       return sum(df[!, columns[1]], StatsBase.weights(df[!, weights])) / sum(df[!, columns[2]], StatsBase.weights(df[!, weights]))
end

In the case of GLM,

function glm_tmp(df::DataFrame, columns, weights, link, family)
   formula_str = string("$(columns[1]) ~ ", join(columns[2:end], " + "))
   formula = eval(Meta.parse("@formula($formula_str)"))
   coef(glm(formula, data, link, family))
end

@nadiaenh can you try this?

@ayushpatnaikgit
Copy link
Member

Can you also accept args, and kwargs in the variance functions and pass them to func? @nadiaenh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants