SlicTranspilerStanBlocks → Stan
Spotlight
StanBlocks.jl ↗

Composable example · Grey-seal integrated population model

34 source units
Library
# Exact StanBlocks code: use StanBlocks.jl@20f12e8fcdc923a0adc88a9b9f7ffff566da4cdf.
using StanBlocks
Datalines 3–36
# Int64 → Stan int
# Int64 → Stan int
# Int64 → Stan int
# Int64 → Stan int
# Vector{Float64} → Stan vector[n]
# Vector{Float64} → Stan vector[n]
# Vector{Float64} → Stan vector[n]
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Float64 → Stan real
# Float64 → Stan real
# Vector{Float64} → Stan vector[n]
# Vector{Float64} → Stan vector[n]
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Vector{Float64} → Stan vector[n]
# Vector{Int} → Stan array[n] int
# Vector{Float64} → Stan vector[n]
# Vector{Int} → Stan array[n] int
# Matrix{Int} → Stan array[m,n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Matrix{Int} → Stan array[m,n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Matrix{Int} → Stan array[m,n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
# Matrix{Int} → Stan array[m,n] int
# Vector{Int} → Stan array[n] int
# Vector{Int} → Stan array[n] int
Functionslines 37–382
@deffun begin
UDF
@1aa28fCase studiesPinned source ↗
UDF
@2f9310Case studiesPinned source ↗
UDF
@870383Case studiesPinned source ↗
UDF
@fb8544Case studiesPinned source ↗
UDF
@865f2dCase studiesPinned source ↗
UDF
@39c925Case studiesPinned source ↗
UDF
@08ce3dCase studiesPinned source ↗
UDF
@6c593eCase studiesPinned source ↗
UDF
@bdb643Case studiesPinned source ↗
UDF
@d51fbfCase studiesPinned source ↗
UDF
@c93582Case studiesPinned source ↗
UDF
@71c1c7Case studiesPinned source ↗
UDF
@4ea457Case studiesuses: create_transition_matrix, multinomial_allocation, update_birth_rate, update_population_from_survivors, update_pregnancy_ratePinned source ↗
UDF
@3fc41fCase studiesPinned source ↗
UDF
@26cffdCase studiesPinned source ↗
UDF
@019bfbCase studiesPinned source ↗
UDF
@f1be0eCase studiesPinned source ↗
UDF
@f1b0f3Case studiesPinned source ↗
UDF
@da089eCase studiesPinned source ↗
UDF
@5b54cbCase studiesPinned source ↗
UDF
@6908eaCase studiesPinned source ↗
UDF
@afbe4bCase studiesPinned source ↗
UDF
@c0674fCase studiesPinned source ↗
UDF
@6101d4Case studiesPinned source ↗
UDF
@c5bafbCase studiesPinned source ↗
UDF
@e458abCase studiesPinned source ↗
UDF
@9dff06Case studiesPinned source ↗
UDF
@8e504dCase studiesPinned source ↗
UDF
@aea71dCase studiesPinned source ↗
UDF
@2b77aeCase studiesPinned source ↗
UDF
@a2028bCase studiesPinned source ↗
end
Anonymous submodelslines 383–395
Anonymous submodel
@4265f6Case studiesPinned source ↗
= @slic begin
end
Anonymous submodel
@846d62Case studiesPinned source ↗
= @slic begin
end
Endpoint modelslines 396–490
Endpoint model
@7826c3Case studiesdata: seal_ipmuses: birth_rate_at_carrying_capacity, compute_baseline_birth_rate, compute_density_dependence_intercept, create_aging_matrix, initialize_population, mortality_rates, run_state_processPinned source ↗
= @slic (; n_age, n_state_years, n_demo, population_burn_in, population_init, herring_index_1, herring_index_2, hunting_quota_sweden, hunting_quota_finland, t_mate_to_preg, t_birth_to_end_hunt, ode_init_state, ode_times, obs_aerial_count, aerial_year, obs_hunting_bag_sweden, hunting_bag_year_sweden, obs_hunting_bag_finland, hunting_bag_year_finland, obs_hunting_comp_sweden, hunting_comp_year_sweden, hunting_comp_sample_size_sweden, obs_hunting_comp_finland, hunting_comp_year_finland, hunting_comp_sample_size_finland, obs_bycatch_comp, bycatch_comp_year, bycatch_comp_sample_size, obs_pregnancy_count, pregnancy_count_year, pregnancy_sample_size, obs_reproductive_signs_finland, reproductive_signs_year, reproductive_signs_sample_size) begin
end
Add from Library
Aerial observation streamaerial_stream
ANONYMOUS SUBMODEL

Case studies

Angle probabilityangle_submodel
ANONYMOUS SUBMODEL

Case studies

Bycatch observation streambycatch_stream
ANONYMOUS SUBMODEL

Case studies

Disk submodeldisk
ANONYMOUS SUBMODEL

Worked examples

Distance probabilitydistance_submodel
ANONYMOUS SUBMODEL

Case studies

HSGP processhsgp
ANONYMOUS SUBMODEL

Case studies

Intercept plus HSGPintercept_hsgp
ANONYMOUS SUBMODEL

Case studies

Population effectpopulation_effect
ANONYMOUS SUBMODEL

Feature atlas

Reusable exponentiated-quadratic HSGPhsgp_eq
ANONYMOUS SUBMODEL

Case studies

Reusable periodic HSGPhsgp_periodic
ANONYMOUS SUBMODEL

Case studies

Reusable regularized horseshoe priorreg_horseshoe
ANONYMOUS SUBMODEL

Case studies

Soil dynamicssoil_dynamics
ANONYMOUS SUBMODEL

Case studies

Angle and distanceangle-distance
ENDPOINT MODEL

Worked examples

data: golf_distance
Angle modelangle
ENDPOINT MODEL

Worked examples

data: golf_angle
Angle modelangle
ENDPOINT MODEL

Case studies

data: golf_angle
Angle, distance and extra variationextra-variation
ENDPOINT MODEL

Case studies

data: golf_distance
Angle, distance and residual variationangle-distance-residual
ENDPOINT MODEL

Worked examples

data: golf_distance
Anonymous submodelatlas__anonymous_submodel
ENDPOINT MODEL

Feature atlas

data: regression_k
AR(1) recurrenceguide__ar1
ENDPOINT MODEL

Main guide

data: ar1
Base modelbase
ENDPOINT MODEL

StanCon 2026

data: xy_real
Basic normal modelguide__basic_normal
ENDPOINT MODEL

Main guide

data: normal
Bernoulli logit-link GLMatlas__bernoulli_glm
ENDPOINT MODEL

Feature atlas

data: binary_glm
Birthdays (HSGP + regularized horseshoe)case_study__birthdays
ENDPOINT MODEL

Case studies

data: births_gpbf8rhs
Block placement, types and shapesatlas__core_placement
ENDPOINT MODEL

Feature atlas

data: xy_real
Categorical plateauthoring__categorical_plate
ENDPOINT MODEL

Authoring guide

data: categorical_plate
Censored observationatlas__censored
ENDPOINT MODEL

Feature atlas

data: scalar_bounds
Complete observation-combinator modelauthoring__observation_combinators
ENDPOINT MODEL

Authoring guide

data: combinators
Complete poolingcomplete-pooling
ENDPOINT MODEL

Case studies

data: radon
Cookbook hierarchical normalguide__hierarchical_normal
ENDPOINT MODEL

Main guide

data: normal
Cookbook linear regressionguide__linear_regression
ENDPOINT MODEL

Main guide

data: xy_real
Cookbook logistic regressionguide__logistic_regression
ENDPOINT MODEL

Main guide

data: binary_glm
Cross-validation taintatlas__cv_taint
ENDPOINT MODEL

Feature atlas

data: cv_people
Custom distribution triadatlas__custom_distribution
ENDPOINT MODEL

Feature atlas

data: scalar_y
Daily incidenceincidence
ENDPOINT MODEL

Case studies

data: school_incidence
Data and parameter dependency placementstancon__dependency_graph
ENDPOINT MODEL

StanCon 2026

data: xy_real
Data rebinding Bernoulli modelatlas__rebinding_bernoulli
ENDPOINT MODEL

Feature atlas

data: counts
Defaults and keyword argumentsatlas__function_signatures
ENDPOINT MODEL

Feature atlas

data: signatures
Dense generated observation outputsatlas__dense_observation_outputs
ENDPOINT MODEL

Feature atlas

data: normal
Disk constraintsworked__constraints_disk
ENDPOINT MODEL

Worked examples

data: none
Dual Julia and Stan emissionatlas__julia_dual
ENDPOINT MODEL

Feature atlas

data: scalar_y
Earnings–height regressionguide__earn_height
ENDPOINT MODEL

Main guide

data: earn_height
Estimated overshoot and toleranceestimated-tolerance
ENDPOINT MODEL

Worked examples

data: golf_angle
Fixed betafixed
ENDPOINT MODEL

Feature atlas

data: xy_fixed_beta
Forward simulationsimulation
ENDPOINT MODEL

Case studies

data: planet_sim
Golf case studycase_study__golf
ENDPOINT MODEL

Case studies

data: golf_distance
Golf model familyworked__golf_family
ENDPOINT MODEL

Worked examples

data: golf_basic
Grey-seal integrated population modelcase_study__grey_seal_ipm
ENDPOINT MODEL

Case studies

data: seal_ipm
Homoskedastic modelhomoskedastic
ENDPOINT MODEL

Case studies

data: motorcycle
Infer gravitational interactioninfer-k
ENDPOINT MODEL

Case studies

data: planet_k
Inline mutation helpersatlas__inline_mutation
ENDPOINT MODEL

Feature atlas

data: iteration
Interval-censored observationatlas__interval_censored
ENDPOINT MODEL

Feature atlas

data: scalar_bounds
Iteration function suiteatlas__iteration
ENDPOINT MODEL

Feature atlas

data: iteration
l2_scaled_priorl2_scaled_prior
ENDPOINT MODEL

Starter sources

data: normal
Linear regressionstancon__linear_regression
ENDPOINT MODEL

StanCon 2026

data: xy_real
Linear regression with an explicit meanstancon__linear_regression_mu
ENDPOINT MODEL

StanCon 2026

data: xy_real
linear_regressionlinear_regression
ENDPOINT MODEL

Starter sources

data: regression
Logistic baselinelogistic
ENDPOINT MODEL

Case studies

data: golf_basic
Missing continuous outcomesatlas__missing_outcomes
ENDPOINT MODEL

Feature atlas

data: missing_y
Missing outcomesauthoring__missing_outcomes
ENDPOINT MODEL

Authoring guide

data: missing_y
Motorcycle case studycase_study__motorcycle
ENDPOINT MODEL

Case studies

data: motorcycle
Named random-slope submodelstancon__random_slope
ENDPOINT MODEL

StanCon 2026

data: xy_real
Named submodel dispatchatlas__named_submodel_dispatch
ENDPOINT MODEL

Feature atlas

data: xy_real
Negative-binomial log-link GLMatlas__negbin_glm
ENDPOINT MODEL

Feature atlas

data: count_glm
Nested heteroskedastic modelnested
ENDPOINT MODEL

Case studies

data: motorcycle
No poolingno-pooling
ENDPOINT MODEL

Case studies

data: radon
Normal identity-link GLMatlas__normal_glm
ENDPOINT MODEL

Feature atlas

data: regression_k
ODE with a captured closureatlas__ode_closure
ENDPOINT MODEL

Feature atlas

data: ode_scalar
Partly missing continuous outcomestancon__missing_outcome
ENDPOINT MODEL

StanCon 2026

data: missing_y
PK ODE function and modelatlas__pk_ode
ENDPOINT MODEL

Feature atlas

data: pk_ode
Planets case studycase_study__planets
ENDPOINT MODEL

Case studies

data: planet_full
Poisson log-link GLMatlas__poisson_glm
ENDPOINT MODEL

Feature atlas

data: count_glm
poisson_glmpoisson_glm
ENDPOINT MODEL

Starter sources

data: counts
Population PK/PD (two-compartment Friberg)case_study__population_pk
ENDPOINT MODEL

Case studies

data: pop_pkpd_friberg
Post-hoc model variantsatlas__model_variants
ENDPOINT MODEL

Feature atlas

data: xy_real
Prior-free regression coefficientguide__flat_regression
ENDPOINT MODEL

Main guide

data: regression
Radon case studycase_study__radon
ENDPOINT MODEL

Case studies

data: radon
Ragged constrained simplex parametersatlas__ragged_simplex
ENDPOINT MODEL

Feature atlas

data: ragged_simplex
Ragged dataatlas__ragged_data
ENDPOINT MODEL

Feature atlas

data: ragged
Ragged groupsauthoring__ragged_data
ENDPOINT MODEL

Authoring guide

data: ragged
Reported daily incidencereported-incidence
ENDPOINT MODEL

Case studies

data: school_incidence
Runtime assertion helperatlas__assertion
ENDPOINT MODEL

Feature atlas

data: scalar_xy
Scalar plateatlas__scalar_plate
ENDPOINT MODEL

Feature atlas

data: plate_scalar
Scalar plateauthoring__scalar_plate
ENDPOINT MODEL

Authoring guide

data: plate_scalar6
School case studycase_study__school
ENDPOINT MODEL

Case studies

data: school
Separate measurement errorlatent-measurement
ENDPOINT MODEL

Case studies

data: soil_measurement
Soil case studycase_study__soil
ENDPOINT MODEL

Case studies

data: soil
Stepping stone: additive HSGPadditive-hsgp
ENDPOINT MODEL

Case studies

data: births
Stepping stone: analytic population PKtwo-compartment-pk
ENDPOINT MODEL

Case studies

data: pop_pk
Transpile-time return type queryatlas__return_type_query
ENDPOINT MODEL

Feature atlas

data: signatures
Truncated observationatlas__truncated
ENDPOINT MODEL

Feature atlas

data: scalar_bounds
Typed flat parameteratlas__typed_flat_parameter
ENDPOINT MODEL

Feature atlas

data: regression_k
varying_interceptvarying_intercept
ENDPOINT MODEL

Starter sources

data: hierarchical
Vector plateauthoring__vector_plate
ENDPOINT MODEL

Authoring guide

data: plate_vector
Vector-valued plate cellsatlas__vector_plate
ENDPOINT MODEL

Feature atlas

data: plate_vector
Weighted observationatlas__weighted
ENDPOINT MODEL

Feature atlas

data: scalar_bounds
Wide-prior model variantstancon__wide_prior_variant
ENDPOINT MODEL

StanCon 2026

data: xy_real
Aerial Count Lpmfaerial_count_lpmf
UDF

Case studies

Aerial Count Lpmfsaerial_count_lpmfs
UDF

Case studies

Aerial Count Rngaerial_count_rng
UDF

Case studies

angle vec2angle matangle_vec2angle_mat
UDF

Helpful Stan Functions · Linear algebra

angle2cholangle2chol
UDF

Helpful Stan Functions · Linear algebra

AR(1) recurrencear1_recurse
UDF

Main guide

Birth Rate At Carrying Capacitybirth_rate_at_carrying_capacity
UDF

Case studies

bivariate normal copula cdfbivariate_normal_copula_cdf
UDF

Helpful Stan Functions · Copulas

Bycatch Comp Lpmfbycatch_comp_lpmf
UDF

Case studies

Bycatch Comp Lpmfsbycatch_comp_lpmfs
UDF

Case studies

Bycatch Comp Rngbycatch_comp_rng
UDF

Case studies

Caller-buffer mutationset_first!
UDF

Feature atlas

chol kronecker prodchol_kronecker_prod
UDF

Helpful Stan Functions · Linear algebra

clayton copula lpdfclayton_copula_lpdf
UDF

Helpful Stan Functions · Copulas

Column sums over EachColcol_sums
UDF

Feature atlas

Compute Baseline Birth Ratecompute_baseline_birth_rate
UDF

Case studies

Compute Density Dependence Interceptcompute_density_dependence_intercept
UDF

Case studies

Create Aging Matrixcreate_aging_matrix
UDF

Case studies

Create Transition Matrixcreate_transition_matrix
UDF

Case studies

cubecube
UDF

Starter sources

Deterministic centered-sum functioncentered_sum
UDF

StanCon 2026

DH dH/dtdH_dt
UDF

Case studies

Disk transformuniform_disk_constrain
UDF

Worked examples

Eight-state Friberg PK/PD ODEfriberg_rhs
UDF

Case studies

Element typeelement_type
UDF

Feature atlas

Enumerated accumulationweighted_sum
UDF

Feature atlas

Exponentiated-quadratic spectrumdiag_spd_eq
UDF

Case studies

Floating-holiday overridesholiday_overrides
UDF

Case studies

frank copula lpdffrank_copula_lpdf
UDF

Helpful Stan Functions · Copulas

gpareto cdfgpareto_cdf
UDF

Helpful Stan Functions · Distributions

gpareto lccdfgpareto_lccdf
UDF

Helpful Stan Functions · Distributions

gpareto lcdfgpareto_lcdf
UDF

Helpful Stan Functions · Distributions

gpareto lpdfgpareto_lpdf
UDF

Helpful Stan Functions · Distributions

gpareto rnggpareto_rng
UDF

Helpful Stan Functions · Distributions

gumbel copula lpdfgumbel_copula_lpdf
UDF

Helpful Stan Functions · Copulas

Harvest Bags Lpdfharvest_bags_lpdf
UDF

Case studies

Harvest Bags Lpdfsharvest_bags_lpdfs
UDF

Case studies

Harvest Bags Rngharvest_bags_rng
UDF

Case studies

Historical disk densityuniform_disk_lpdf
UDF

Worked examples

HSGP basisphi_eq
UDF

Case studies

Hunting Comp Lpmfhunting_comp_lpmf
UDF

Case studies

Hunting Comp Lpmfshunting_comp_lpmfs
UDF

Case studies

Hunting Comp Rnghunting_comp_rng
UDF

Case studies

in orderin_order
UDF

Helpful Stan Functions · Array operations

Initialize Populationinitialize_population
UDF

Case studies

Inline scalescale
UDF

Feature atlas

inv erfinv_erf
UDF

Helpful Stan Functions · Special functions

inv erf nsqrtinv_erf_nsqrt
UDF

Helpful Stan Functions · Special functions

l2_norml2_norm
UDF

Starter sources

lognormal qflognormal_qf
UDF

Helpful Stan Functions · Quantile functions

lower elementslower_elements
UDF

Helpful Stan Functions · Linear algebra

Mortality Ratesmortality_rates
UDF

Case studies

multi normal cholesky copula lpdfmulti_normal_cholesky_copula_lpdf
UDF

Helpful Stan Functions · Copulas

Multinomial Allocationmultinomial_allocation
UDF

Case studies

Mutating compositionmutate_scaled
UDF

Feature atlas

normal copula lpdfnormal_copula_lpdf
UDF

Helpful Stan Functions · Copulas

normal copula vector lpdfnormal_copula_vector_lpdf
UDF

Helpful Stan Functions · Copulas

One-compartment ODE RHSpk_rhs
UDF

Feature atlas

Optional keywordshift
UDF

Feature atlas

Periodic basisphi_periodic
UDF

Case studies

Periodic spectrumdiag_spd_periodic
UDF

Case studies

Planetary ODE right-hand sideplanetary_rhs
UDF

Case studies

Pointwise robust densityrobust_lpdfs
UDF

Feature atlas

Positional defaultaffine
UDF

Feature atlas

Positive safe logsafe_log
UDF

Feature atlas

Pregnancy Lpmfpregnancy_lpmf
UDF

Case studies

Pregnancy Lpmfspregnancy_lpmfs
UDF

Case studies

Pregnancy Rngpregnancy_rng
UDF

Case studies

Reproductive Signs Lpmfreproductive_signs_lpmf
UDF

Case studies

Reproductive Signs Lpmfsreproductive_signs_lpmfs
UDF

Case studies

Reproductive Signs Rngreproductive_signs_rng
UDF

Case studies

Required keywordsscale
UDF

Feature atlas

Return-type-driven copycopy_vec
UDF

Feature atlas

Robust densityrobust_lpdf
UDF

Feature atlas

Robust predictive RNGrobust_rng
UDF

Feature atlas

SIR ODE right-hand sideschool_sir_rhs
UDF

Case studies

softplussoftplus
UDF

Starter sources

Solver-specialized subject predictionfriberg_subject
UDF

Case studies

sqsq
UDF

Starter sources

standardizestandardize
UDF

Starter sources

Stepping-stone two-compartment IV bolustwocmt_iv
UDF

Case studies

student t lccdf stanstudent_t_lccdf_stan
UDF

Helpful Stan Functions · Distributions

student t lcdf stanstudent_t_lcdf_stan
UDF

Helpful Stan Functions · Distributions

Two-axis comprehensionouter
UDF

Feature atlas

Two-pool ODE right-hand sidetwo_pool_feedback
UDF

Case studies

unit johnson cdfunit_johnson_cdf
UDF

Helpful Stan Functions · Distributions

unit johnson lccdfunit_johnson_lccdf
UDF

Helpful Stan Functions · Distributions

unit johnson lcdfunit_johnson_lcdf
UDF

Helpful Stan Functions · Distributions

unit johnson lpdfunit_johnson_lpdf
UDF

Helpful Stan Functions · Distributions

unit johnson qfunit_johnson_qf
UDF

Helpful Stan Functions · Quantile functions

unit johnson rngunit_johnson_rng
UDF

Helpful Stan Functions · Distributions

Update Birth Rateupdate_birth_rate
UDF

Case studies

Update Population From Survivorsupdate_population_from_survivors
UDF

Case studies

Update Pregnancy Rateupdate_pregnancy_rate
UDF

Case studies

Value comprehensionsquares
UDF

Feature atlas

Year-recursive state processrun_state_process
UDF

Case studies

Zipped productsproducts
UDF

Feature atlas

Expand a section to edit its bluish-outlined code; the summary keeps its full-script line range visible. Data is shared by every endpoint; anonymous submodels are the reusable authoring unit. Choose Transpile model to make another endpoint active; public Library saving stays disabled.

Example ready

• ready loaded from the pinned Library entry without executing
Transpiling model and checking the generated Stan…
This pinned example has not run. Review it, then transpile when ready.

Using SlicTranspiler

StanBlocks (SLIC) → Stan, in the browser

What this does

SlicTranspiler turns editable Julia/StanBlocks source into Stan, checks the generated program with stanc, and keeps source and output side by side. Most prepared Library examples transpile as soon as you open them; large workspaces and shared links stay review-first until you choose Transpile.

The workbench

  • Compose data, functions, anonymous submodels and endpoint models in one copyable Julia script. Section summaries keep their global line ranges visible while collapsed; Data starts collapsed.
  • Arrange the source and generated-code panes with the center divider. Drag it, focus it and use the arrow keys, or use its edge buttons to collapse either pane completely; your layout stays in this browser.
  • Edit the bluish-outlined code in place. Binding names live in the code itself, so there is no second label to drift out of sync.
  • Transpile an endpoint with its button or ⌘/Ctrl + Enter; the Stan program and its stanc result appear on the right and that endpoint is highlighted.
  • The Function tab transpiles a single @deffun into its emitted Stan function.
  • The Library collects runnable examples and a guided Model spotlight; call any Library function by name.
  • Share builds a link that reopens the editor with your source.

SLIC in a nutshell

y ~ normal(mu, sigma)
A ~ statement — a prior on a parameter, or a likelihood when the left side is data.
mu = alpha + beta * x
An = assignment — a deterministic transform.
beta::vector[k] ~ normal(0, 1)
A typed declaration. Left bare (beta::vector[k]) it becomes a flat-prior parameter.
No loops or if in a model body
Control flow lives in a @deffun Stan function (the Function tab); the model calls it straight-line.
theta ~ plate(y; outer=N) do yi … end
The one sampling loop — a fresh parameter and observation per group.
Submodels
Name a reusable fragment and pass its inputs by keyword: eta ~ regression(; x).
Observations
weighted, truncated, censored and interval_censored wrap a family; missing outcomes are imputed automatically.

Try a Spotlight model

These prepared examples open editable and already transpiled:

Browse every prepared source in the Library.

StanBlocks documentation ↗

Send feedback

Tell me what worked, or what broke
Your workspace source — every editor's contents — is attached so I can reproduce exactly what you saw. Uncheck to send only your message.