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

Implement particles for NamedTuple with array-valued field #40

Closed
ghost opened this issue Sep 13, 2019 · 2 comments
Closed

Implement particles for NamedTuple with array-valued field #40

ghost opened this issue Sep 13, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 13, 2019

Given

dept_id = [1,1,2,2,3,3,4,4,5,5,6,6]
male = [1,0,1,0,1,0,1,0,1,0,1,0]
applications = [825,108,560,25,325,593,417,375,191,393,373,341]
admit = [512,89,353,17,120,202,138,131,53,94,22,24]

we would like a varying intercepts model for each unique department

using Soss

varying_intercepts = @model (dept_id, applications, male) begin
    α ~ For(dept_id) do id
        Normal(0,10)
    end
    β ~ Normal(0,1)
    p = logistic.(α .+ β .* male)
    N = length(male)
    admit ~ For(1:N) do n
        Binomial(applications[n], p[n])
    end
end

errors

post = nuts(varying_intercepts(dept_id = dept_id, applications = applications, male = male), (admit = admit,)) |> particles

with output

(β = 0.00901 ± 0.97, α = ERROR: LoadError: MethodError: no method matching eps(::Type{Array{Float64,1}})
Closest candidates are:
  eps(!Matched::Type{Float16}) at float.jl:739
  eps(!Matched::Type{Float32}) at float.jl:740
  eps(!Matched::Type{Float64}) at float.jl:741
  ...
Stacktrace:
 [1] eps(::Particles{Array{Float64,1},1000}) at /home/oliver/.julia/packages/MonteCarloMeasurements/WZtSS/src/particles.jl:392

We would like this model to output the intercepts for each department.

reprex.zip

@cscherrer
Copy link
Owner

cscherrer commented Sep 14, 2019

Thanks @OdE33. This is a current limitation in particles. We'll need to add some more methods to cover this case. I'll edit the issue title to reflect this.

Just to be sure... On my machine it works fine if I remove |> particles. Can you confirm this works for you as well?

@cscherrer cscherrer changed the title Varying Intercepts Implement particles for NamedTuple with array-valued field Sep 14, 2019
@cscherrer cscherrer mentioned this issue Sep 15, 2019
Merged
@cscherrer
Copy link
Owner

We'll be changing nuts to dynamicHMC (more descriptive, since we also have AdvancedHMC). But at least the vector-of-vectors case is working now:

julia> post = dynamicHMC(varying_intercepts(dept_id = dept_id, applications = applications, male = male), (admit = admit,)) |> particles
(β = -0.053 ± 1.0, α = Particles{Float64,1000}[0.543 ± 1.0, 1.56 ± 0.26, 0.584 ± 1.0, 0.794 ± 0.41, -0.486 ± 1.0, -0.662 ± 0.084, -0.651 ± 1.0, -0.624 ± 0.11, -0.911 ± 1.0, -1.16 ± 0.12, -2.73 ± 1.0, -2.61 ± 0.21])

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

No branches or pull requests

1 participant