Skip to content

Make intermediate parameters generated in the for loop accessible for return and generated_quantities #2408

Discussion options

You must be logged in to vote

To be concrete, using generated_quantities you could do:

@model function model_Linear(y, x, participant, n)

    # Priors - Fixed Effects
    μ_intercept ~ Normal(0, 0.5)
    μ_x ~ Normal(0, 0.5)

    σ ~ truncated(Normal(0.0, 1), lower=0)

    # Priors - Random Effects
    μ_intercept_random_sd ~ truncated(Normal(0.0, 0.3), lower=0)
    μ_x_random_sd ~ truncated(Normal(0, 0.3), lower=0)

    # Participant-level priors (we only include these if `participant` is not `nothing`)
    if participant !== nothing
        μ_intercept_random ~ filldist(Normal(0, μ_intercept_random_sd), n)
        μ_x_random ~ filldist(Normal(0, μ_x_random_sd), n)
    end

    # CHANGED: Pre-allocate the vector.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@torfjelde
Comment options

Answer selected by DominiqueMakowski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants