🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 18 (from laksa013)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

🚫
NOT INDEXABLE
CRAWLED
14 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.5 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalFAILmeta_canonical IS NULL OR = '' OR = src_unparsedorg,mc-stan!/docs/stan-users-guide/finite-mixtures.html s443

Page Details

PropertyValue
URLhttps://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html
Last Crawled2026-03-22 23:10:12 (14 days ago)
First Indexed2019-08-13 23:45:20 (6 years ago)
HTTP Status Code200
Meta Title5.6 Zero-Inflated and Hurdle Models | Stan User’s Guide
Meta DescriptionStan user’s guide with examples and programming techniques.
Meta Canonicalorg,mc-stan!/docs/stan-users-guide/finite-mixtures.html s443
Boilerpipe Text
Zero-inflated and hurdle models both provide mixtures of a Poisson and Bernoulli probability mass function to allow more flexibility in modeling the probability of a zero outcome. Zero-inflated models, as defined by Lambert ( 1992 ) , add additional probability mass to the outcome of zero. Hurdle models, on the other hand, are formulated as pure mixtures of zero and non-zero outcomes. Zero inflation and hurdle models can be formulated for discrete distributions other than the Poisson. Zero inflation does not work for continuous distributions in Stan because of issues with derivatives; in particular, there is no way to add a point mass to a continuous distribution, such as zero-inflating a normal as a regression coefficient prior. Zero Inflation Consider the following example for zero-inflated Poisson distributions. It uses a parameter theta here there is a probability θ of drawing a zero, and a probability 1 − θ of drawing from P o i s s o n ( λ ) (now θ is being used for mixing proportions because λ is the traditional notation for a Poisson mean parameter). The probability function is thus p ( y n | θ , λ ) = { θ + ( 1 − θ ) ∗ P o i s s o n ( 0 | λ )  if  y n = 0 ,  and ( 1 − θ ) ∗ P o i s s o n ( y n | λ )  if  y n > 0. The log probability function can be implemented directly in Stan as follows. data { int<lower=0> N; int<lower=0> y[N]; } parameters { real<lower=0, upper=1> theta; real<lower=0> lambda; } model { for (n in 1:N) { if (y[n] == 0) target += log_sum_exp(bernoulli_lpmf(1 | theta), bernoulli_lpmf(0 | theta) + poisson_lpmf(y[n] | lambda)); else target += bernoulli_lpmf(0 | theta) + poisson_lpmf(y[n] | lambda); } } The log_sum_exp(lp1,lp2) function adds the log probabilities on the linear scale; it is defined to be equal to log(exp(lp1) + exp(lp2)) , but is more arithmetically stable and faster. Optimizing the zero-inflated Poisson model The code given above to compute the zero-inflated Poisson redundantly calculates all of the Bernoulli terms and also poisson_lpmf(0 | lambda) every time the first condition body executes. The use of the redundant terms is conditioned on y , which is known when the data are read in. This allows the transformed data block to be used to compute some more convenient terms for expressing the log density each iteration. The number of zero cases is computed and handled separately. Then the nonzero cases are collected into their own array for vectorization. The number of zeros is required to declare y_nonzero , so it must be computed in a function. functions { int num_zeros(int[] y) { int sum = 0; for (n in 1:size(y)) sum += (y[n] == 0); return sum; } } ... transformed data { int<lower = 0> N_zero = num_zeros(y); int<lower = 1> y_nonzero[N - N_zero]; int N_nonzero = 0; for (n in 1:N) { if (y[n] == 0) continue; N_nonzero += 1; y_nonzero[N_nonzero] = y[n]; } } ... model { ... target += N_zero * log_sum_exp(bernoulli_lpmf(1 | theta), bernoulli_lpmf(0 | theta) + poisson_lpmf(0 | lambda)); target += N_nonzero * bernoulli_lpmf(0 | theta); target += poisson_lpmf(y_nonzero | lambda); ... The boundary conditions of all zeros and no zero outcomes is handled appropriately; in the vectorized case, if y_nonzero is empty, N_nonzero will be zero, and the last two target increment terms will add zeros. Hurdle Models The hurdle model is similar to the zero-inflated model, but more flexible in that the zero outcomes can be deflated as well as inflated. The probability mass function for the hurdle likelihood is defined by p ( y | θ , λ ) = {   θ if  y = 0 ,  and   ( 1 − θ )   P o i s s o n ( y | λ ) 1 − P o i s s o n C D F ( 0 | λ ) if  y > 0 , where P o i s s o n C D F is the cumulative distribution function for the Poisson distribution. The hurdle model is even more straightforward to program in Stan, as it does not require an explicit mixture. if (y[n] == 0) 1 ~ bernoulli(theta); else { 0 ~ bernoulli(theta); y[n] ~ poisson(lambda) T[1, ]; } The Bernoulli statements are just shorthand for adding log ⁡ θ and log ⁡ ( 1 − θ ) to the log density. The T[1,] after the Poisson indicates that it is truncated below at 1; see the truncation section for more about truncation and the Poisson regresison section for the specifics of the Poisson CDF. The net effect is equivalent to the direct definition of the log likelihood. if (y[n] == 0) target += log(theta); else target += log1m(theta) + poisson_lpmf(y[n] | lambda) - poisson_lccdf(0 | lambda)); Julian King pointed out that because log ⁡ ( 1 − P o i s s o n C D F ( 0 | λ ) )   =   log ⁡ ( 1 − P o i s s o n ( 0 | λ ) )   =   log ⁡ ( 1 − exp ⁡ ( − λ ) ) the CCDF in the else clause can be replaced with a simpler expression. target += log1m(theta) + poisson_lpmf(y[n] | lambda) - log1m_exp(-lambda)); The resulting code is about 15% faster than the code with the CCDF. This is an example where collecting counts ahead of time can also greatly speed up the execution speed without changing the density. For data size N = 200 and parameters θ = 0.3 and λ = 8 , the speedup is a factor of 10; it will be lower for smaller N and greater for larger N ; it will also be greater for larger θ . To achieve this speedup, it helps to have a function to count the number of non-zero entries in an array of integers, functions { int num_zero(int[] y) { int nz = 0; for (n in 1:size(y)) if (y[n] == 0) nz += 1; return nz; } } Then a transformed data block can be used to store the sufficient statistics, transformed data { int<lower=0, upper=N> N0 = num_zero(y); int<lower=0, upper=N> Ngt0 = N - N0; int<lower=1> y_nz[N - num_zero(y)]; { int pos = 1; for (n in 1:N) { if (y[n] != 0) { y_nz[pos] = y[n]; pos += 1; } } } } The model block can then be reduced to three statements. model { N0 ~ binomial(N, theta); y_nz ~ poisson(lambda); target += -Ngt0 * log1m_exp(-lambda); } The first statement accounts for the Bernoulli contribution to both the zero and non-zero counts. The second line is the Poisson contribution from the non-zero counts, which is now vectorized. Finally, the normalization for the truncation is a single line, so that the expression for the log CCDF at 0 isn’t repeated. Also note that the negation is applied to the constant Ngt0 ; whenever possible, leave subexpressions constant because then gradients need not be propagated until a non-constant term is encountered. References Lambert, Diane. 1992. “Zero-Inflated Poisson Regression, with an Application to Defects in Manufacturing.” Technometrics 34 (1).
Markdown
Type to search - [Stan User's Guide](https://mc-stan.org/docs/stan-users-guide/index.html) - [About this Book](https://mc-stan.org/docs/2_20/stan-users-guide/index.html) - [*Part 1. Example Models*](https://mc-stan.org/docs/2_20/stan-users-guide/example-models-part.html#example-models.part) - [**1** Regression Models](https://mc-stan.org/docs/2_20/stan-users-guide/regression-models.html) - [**1\.1** Linear Regression](https://mc-stan.org/docs/2_20/stan-users-guide/linear-regression.html) - [Matrix Notation and Vectorization](https://mc-stan.org/docs/2_20/stan-users-guide/linear-regression.html#vectorization.section) - [**1\.2** The QR Reparameterization](https://mc-stan.org/docs/2_20/stan-users-guide/QR-reparameterization-section.html) - [**1\.3** Priors for Coefficients and Scales](https://mc-stan.org/docs/2_20/stan-users-guide/regression-priors-section.html) - [**1\.4** Robust Noise Models](https://mc-stan.org/docs/2_20/stan-users-guide/robust-noise-models.html) - [**1\.5** Logistic and Probit Regression](https://mc-stan.org/docs/2_20/stan-users-guide/logistic-probit-regression-section.html) - [**1\.6** Multi-Logit Regression](https://mc-stan.org/docs/2_20/stan-users-guide/multi-logit-section.html) - [Identifiability](https://mc-stan.org/docs/2_20/stan-users-guide/multi-logit-section.html#identifiability) - [**1\.7** Parameterizing Centered Vectors](https://mc-stan.org/docs/2_20/stan-users-guide/parameterizing-centered-vectors.html) - [K−1 K − 1 Degrees of Freedom](https://mc-stan.org/docs/2_20/stan-users-guide/parameterizing-centered-vectors.html#k-1-degrees-of-freedom) - [QR Decomposition](https://mc-stan.org/docs/2_20/stan-users-guide/parameterizing-centered-vectors.html#qr-decomposition) - [Translated and Scaled Simplex](https://mc-stan.org/docs/2_20/stan-users-guide/parameterizing-centered-vectors.html#translated-and-scaled-simplex) - [Soft Centering](https://mc-stan.org/docs/2_20/stan-users-guide/parameterizing-centered-vectors.html#soft-centering) - [**1\.8** Ordered Logistic and Probit Regression](https://mc-stan.org/docs/2_20/stan-users-guide/ordered-logistic-section.html) - [Ordered Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/ordered-logistic-section.html#ordered-logistic-regression) - [**1\.9** Hierarchical Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/hierarchical-logistic-regression.html) - [**1\.10** Hierarchical Priors](https://mc-stan.org/docs/2_20/stan-users-guide/hierarchical-priors-section.html) - [Boundary-Avoiding Priors for MLE in Hierarchical Models](https://mc-stan.org/docs/2_20/stan-users-guide/hierarchical-priors-section.html#boundary-avoiding-priors-for-mle-in-hierarchical-models) - [**1\.11** Item-Response Theory Models](https://mc-stan.org/docs/2_20/stan-users-guide/item-response-models-section.html) - [Data Declaration with Missingness](https://mc-stan.org/docs/2_20/stan-users-guide/item-response-models-section.html#data-declaration-with-missingness) - [1PL (Rasch) Model](https://mc-stan.org/docs/2_20/stan-users-guide/item-response-models-section.html#pl-rasch-model) - [Multilevel 2PL Model](https://mc-stan.org/docs/2_20/stan-users-guide/item-response-models-section.html#multilevel-2pl-model) - [**1\.12** Priors for Identifiability](https://mc-stan.org/docs/2_20/stan-users-guide/priors-for-identification-section.html) - [Location and Scale Invariance](https://mc-stan.org/docs/2_20/stan-users-guide/priors-for-identification-section.html#location-and-scale-invariance) - [Collinearity](https://mc-stan.org/docs/2_20/stan-users-guide/priors-for-identification-section.html#collinearity) - [Separability](https://mc-stan.org/docs/2_20/stan-users-guide/priors-for-identification-section.html#separability) - [**1\.13** Multivariate Priors for Hierarchical Models](https://mc-stan.org/docs/2_20/stan-users-guide/multivariate-hierarchical-priors-section.html) - [Multivariate Regression Example](https://mc-stan.org/docs/2_20/stan-users-guide/multivariate-hierarchical-priors-section.html#multivariate-regression-example) - [**1\.14** Prediction, Forecasting, and Backcasting](https://mc-stan.org/docs/2_20/stan-users-guide/prediction-forecasting-and-backcasting.html) - [Programming Predictions](https://mc-stan.org/docs/2_20/stan-users-guide/prediction-forecasting-and-backcasting.html#programming-predictions) - [Predictions as Generated Quantities](https://mc-stan.org/docs/2_20/stan-users-guide/prediction-forecasting-and-backcasting.html#predictions-as-generated-quantities) - [**1\.15** Multivariate Outcomes](https://mc-stan.org/docs/2_20/stan-users-guide/multivariate-outcomes.html) - [Seemingly Unrelated Regressions](https://mc-stan.org/docs/2_20/stan-users-guide/multivariate-outcomes.html#seemingly-unrelated-regressions) - [Multivariate Probit Regression](https://mc-stan.org/docs/2_20/stan-users-guide/multivariate-outcomes.html#multivariate-probit-regression) - [**1\.16** Applications of Pseudorandom Number Generation](https://mc-stan.org/docs/2_20/stan-users-guide/applications-of-pseudorandom-number-generation.html) - [Prediction](https://mc-stan.org/docs/2_20/stan-users-guide/applications-of-pseudorandom-number-generation.html#prediction) - [Posterior Predictive Checks](https://mc-stan.org/docs/2_20/stan-users-guide/applications-of-pseudorandom-number-generation.html#posterior-predictive-checks) - [**2** Time-Series Models](https://mc-stan.org/docs/2_20/stan-users-guide/time-series-chapter.html) - [**2\.1** Autoregressive Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html) - [AR(1) Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html#ar1-models) - [Extensions to the AR(1) Model](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html#extensions-to-the-ar1-model) - [AR(2) Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html#ar2-models) - [AR(K K) Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html#ark-models) - [ARCH(1) Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-section.html#arch1-models) - [**2\.2** Modeling Temporal Heteroscedasticity](https://mc-stan.org/docs/2_20/stan-users-guide/modeling-temporal-heteroscedasticity.html) - [GARCH(1,1) Models](https://mc-stan.org/docs/2_20/stan-users-guide/modeling-temporal-heteroscedasticity.html#garch11-models) - [**2\.3** Moving Average Models](https://mc-stan.org/docs/2_20/stan-users-guide/moving-average-models.html) - [MA(2) Example](https://mc-stan.org/docs/2_20/stan-users-guide/moving-average-models.html#ma2-example) - [Vectorized MA(Q) Model](https://mc-stan.org/docs/2_20/stan-users-guide/moving-average-models.html#vectorized-maq-model) - [**2\.4** Autoregressive Moving Average Models](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-moving-average-models.html) - [Identifiability and Stationarity](https://mc-stan.org/docs/2_20/stan-users-guide/autoregressive-moving-average-models.html#identifiability-and-stationarity) - [**2\.5** Stochastic Volatility Models](https://mc-stan.org/docs/2_20/stan-users-guide/stochastic-volatility-models.html) - [**2\.6** Hidden Markov Models](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html) - [Supervised Parameter Estimation](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#supervised-parameter-estimation) - [Start-State and End-State Probabilities](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#start-state-and-end-state-probabilities) - [Calculating Sufficient Statistics](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#calculating-sufficient-statistics) - [Analytic Posterior](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#analytic-posterior) - [Semisupervised Estimation](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#semisupervised-estimation) - [Predictive Inference](https://mc-stan.org/docs/2_20/stan-users-guide/hmms-section.html#predictive-inference) - [**3** Missing Data and Partially Known Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/missing-data-and-partially-known-parameters.html "3 Missing Data and Partially Known Parameters") - [**3\.1** Missing Data](https://mc-stan.org/docs/2_20/stan-users-guide/missing-data.html) - [**3\.2** Partially Known Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/partially-known-parameters-section.html) - [**3\.3** Sliced Missing Data](https://mc-stan.org/docs/2_20/stan-users-guide/sliced-missing-data.html) - [**3\.4** Loading matrix for factor analysis](https://mc-stan.org/docs/2_20/stan-users-guide/loading-matrix-for-factor-analysis.html) - [**3\.5** Missing Multivariate Data](https://mc-stan.org/docs/2_20/stan-users-guide/missing-multivariate-data.html) - [**4** Truncated or Censored Data](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-or-censored-data.html) - [**4\.1** Truncated Distributions](https://mc-stan.org/docs/2_20/stan-users-guide/truncation-section.html) - [**4\.2** Truncated Data](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-data-section.html) - [Constraints and Out-of-Bounds Returns](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-data-section.html#constraints-and-out-of-bounds-returns) - [Unknown Truncation Points](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-data-section.html#unknown-truncation-points) - [**4\.3** Censored Data](https://mc-stan.org/docs/2_20/stan-users-guide/censored-data.html) - [Estimating Censored Values](https://mc-stan.org/docs/2_20/stan-users-guide/censored-data.html#estimating-censored-values) - [Integrating out Censored Values](https://mc-stan.org/docs/2_20/stan-users-guide/censored-data.html#integrating-out-censored-values) - [**5** Finite Mixtures](https://mc-stan.org/docs/2_20/stan-users-guide/mixture-modeling-chapter.html) - [**5\.1** Relation to Clustering](https://mc-stan.org/docs/2_20/stan-users-guide/clustering-mixture-section.html) - [**5\.2** Latent Discrete Parameterization](https://mc-stan.org/docs/2_20/stan-users-guide/latent-discrete-parameterization.html) - [**5\.3** Summing out the Responsibility Parameter](https://mc-stan.org/docs/2_20/stan-users-guide/summing-out-the-responsibility-parameter.html "5.3 Summing out the Responsibility Parameter") - [Log Sum of Exponentials: Linear Sums on the Log Scale](https://mc-stan.org/docs/2_20/stan-users-guide/summing-out-the-responsibility-parameter.html#log-sum-of-exponentials-linear-sums-on-the-log-scale) - [Dropping uniform mixture ratios](https://mc-stan.org/docs/2_20/stan-users-guide/summing-out-the-responsibility-parameter.html#dropping-uniform-mixture-ratios) - [Recovering posterior mixture proportions](https://mc-stan.org/docs/2_20/stan-users-guide/summing-out-the-responsibility-parameter.html#recovering-posterior-mixture-proportions) - [Estimating Parameters of a Mixture](https://mc-stan.org/docs/2_20/stan-users-guide/summing-out-the-responsibility-parameter.html#estimating-parameters-of-a-mixture) - [**5\.4** Vectorizing Mixtures](https://mc-stan.org/docs/2_20/stan-users-guide/vectorizing-mixtures.html) - [**5\.5** Inferences Supported by Mixtures](https://mc-stan.org/docs/2_20/stan-users-guide/mixture-inference-section.html "5.5 Inferences Supported by Mixtures") - [Mixtures with Unidentifiable Components](https://mc-stan.org/docs/2_20/stan-users-guide/mixture-inference-section.html#mixtures-with-unidentifiable-components) - [Inference under Label Switching](https://mc-stan.org/docs/2_20/stan-users-guide/mixture-inference-section.html#inference-under-label-switching) - [**5\.6** Zero-Inflated and Hurdle Models](https://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html) - [Zero Inflation](https://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html#zero-inflation) - [Hurdle Models](https://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html#hurdle-models) - [**5\.7** Priors and Effective Data Size in Mixture Models](https://mc-stan.org/docs/2_20/stan-users-guide/priors-and-effective-data-size-in-mixture-models.html "5.7 Priors and Effective Data Size in Mixture Models") - [Comparison to Model Averaging](https://mc-stan.org/docs/2_20/stan-users-guide/priors-and-effective-data-size-in-mixture-models.html#comparison-to-model-averaging) - [**6** Measurement Error and Meta-Analysis](https://mc-stan.org/docs/2_20/stan-users-guide/measurement-error-and-meta-analysis.html "6 Measurement Error and Meta-Analysis") - [**6\.1** Bayesian Measurement Error Model](https://mc-stan.org/docs/2_20/stan-users-guide/bayesian-measurement-error-model.html) - [Regression with Measurement Error](https://mc-stan.org/docs/2_20/stan-users-guide/bayesian-measurement-error-model.html#regression-with-measurement-error) - [Rounding](https://mc-stan.org/docs/2_20/stan-users-guide/bayesian-measurement-error-model.html#rounding) - [**6\.2** Meta-Analysis](https://mc-stan.org/docs/2_20/stan-users-guide/meta-analysis.html) - [Treatment Effects in Controlled Studies](https://mc-stan.org/docs/2_20/stan-users-guide/meta-analysis.html#treatment-effects-in-controlled-studies) - [**7** Latent Discrete Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/latent-discrete-chapter.html) - [**7\.1** The Benefits of Marginalization](https://mc-stan.org/docs/2_20/stan-users-guide/rao-blackwell-section.html) - [**7\.2** Change Point Models](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html) - [Model with Latent Discrete Parameter](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#model-with-latent-discrete-parameter) - [Marginalizing out the Discrete Parameter](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#marginalizing-out-the-discrete-parameter) - [Coding the Model in Stan](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#coding-the-model-in-stan-1) - [Fitting the Model with MCMC](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#fitting-the-model-with-mcmc) - [Posterior Distribution of the Discrete Change Point](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#posterior-distribution-of-the-discrete-change-point) - [Discrete Sampling](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#discrete-sampling) - [Posterior Covariance](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#posterior-covariance) - [Multiple Change Points](https://mc-stan.org/docs/2_20/stan-users-guide/change-point-section.html#multiple-change-points) - [**7\.3** Mark-Recapture Models](https://mc-stan.org/docs/2_20/stan-users-guide/mark-recapture-models.html) - [Simple Mark-Recapture Model](https://mc-stan.org/docs/2_20/stan-users-guide/mark-recapture-models.html#simple-mark-recapture-model) - [Cormack-Jolly-Seber with Discrete Parameter](https://mc-stan.org/docs/2_20/stan-users-guide/mark-recapture-models.html#cormack-jolly-seber-with-discrete-parameter) - [Collective Cormack-Jolly-Seber Model](https://mc-stan.org/docs/2_20/stan-users-guide/mark-recapture-models.html#collective-cormack-jolly-seber-model) - [Individual Cormack-Jolly-Seber Model](https://mc-stan.org/docs/2_20/stan-users-guide/mark-recapture-models.html#individual-cormack-jolly-seber-model) - [**7\.4** Data Coding and Diagnostic Accuracy Models](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html) - [Diagnostic Accuracy](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#diagnostic-accuracy) - [Data Coding](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#data-coding) - [Noisy Categorical Measurement Model](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#noisy-categorical-measurement-model) - [Model Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#model-parameters) - [Noisy Measurement Model](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#noisy-measurement-model) - [Stan Implementation](https://mc-stan.org/docs/2_20/stan-users-guide/data-coding-and-diagnostic-accuracy-models.html#stan-implementation) - [**8** Sparse and Ragged Data Structures](https://mc-stan.org/docs/2_20/stan-users-guide/sparse-ragged-chapter.html) - [**8\.1** Sparse Data Structures](https://mc-stan.org/docs/2_20/stan-users-guide/sparse-data-structures.html) - [**8\.2** Ragged Data Structures](https://mc-stan.org/docs/2_20/stan-users-guide/ragged-data-structs-section.html) - [**9** Clustering Models](https://mc-stan.org/docs/2_20/stan-users-guide/clustering-chapter.html) - [**9\.1** Relation to Finite Mixture Models](https://mc-stan.org/docs/2_20/stan-users-guide/relation-to-finite-mixture-models.html) - [**9\.2** Soft K K-Means](https://mc-stan.org/docs/2_20/stan-users-guide/soft-k-means.html) - [**9\.2.1** Geometric Hard K K-Means Clustering](https://mc-stan.org/docs/2_20/stan-users-guide/soft-k-means.html#geometric-hard-k-means-clustering) - [**9\.2.2** Soft K K-Means Clustering](https://mc-stan.org/docs/2_20/stan-users-guide/soft-k-means.html#soft-k-means-clustering) - [Stan Implementation of Soft K K-Means](https://mc-stan.org/docs/2_20/stan-users-guide/soft-k-means.html#stan-implementation-of-soft-k-means) - [Generalizing Soft K K-Means](https://mc-stan.org/docs/2_20/stan-users-guide/soft-k-means.html#generalizing-soft-k-means) - [**9\.3** The Difficulty of Bayesian Inference for Clustering](https://mc-stan.org/docs/2_20/stan-users-guide/the-difficulty-of-bayesian-inference-for-clustering.html) - [Non-Identifiability](https://mc-stan.org/docs/2_20/stan-users-guide/the-difficulty-of-bayesian-inference-for-clustering.html#non-identifiability) - [Multimodality](https://mc-stan.org/docs/2_20/stan-users-guide/the-difficulty-of-bayesian-inference-for-clustering.html#multimodality) - [**9\.4** Naive Bayes Classification and Clustering](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html) - [Coding Ragged Arrays](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html#coding-ragged-arrays) - [Estimation with Category-Labeled Training Data](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html#estimation-with-category-labeled-training-data) - [Estimation without Category-Labeled Training Data](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html#estimation-without-category-labeled-training-data) - [Full Bayesian Inference for Naive Bayes](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html#full-bayesian-inference-for-naive-bayes) - [Prediction without Model Updates](https://mc-stan.org/docs/2_20/stan-users-guide/naive-bayes-classification-and-clustering.html#prediction-without-model-updates) - [**9\.5** Latent Dirichlet Allocation](https://mc-stan.org/docs/2_20/stan-users-guide/latent-dirichlet-allocation.html) - [The LDA Model](https://mc-stan.org/docs/2_20/stan-users-guide/latent-dirichlet-allocation.html#the-lda-model) - [Summing out the Discrete Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/latent-dirichlet-allocation.html#summing-out-the-discrete-parameters) - [Implementation of LDA](https://mc-stan.org/docs/2_20/stan-users-guide/latent-dirichlet-allocation.html#implementation-of-lda) - [Correlated Topic Model](https://mc-stan.org/docs/2_20/stan-users-guide/latent-dirichlet-allocation.html#correlated-topic-model) - [**10** Gaussian Processes](https://mc-stan.org/docs/2_20/stan-users-guide/gaussian-processes-chapter.html) - [**10\.1** Gaussian Process Regression](https://mc-stan.org/docs/2_20/stan-users-guide/gaussian-process-regression.html) - [**10\.2** Simulating from a Gaussian Process](https://mc-stan.org/docs/2_20/stan-users-guide/simulating-from-a-gaussian-process.html) - [Multivariate Inputs](https://mc-stan.org/docs/2_20/stan-users-guide/simulating-from-a-gaussian-process.html#multivariate-inputs) - [Cholesky Factored and Transformed Implementation](https://mc-stan.org/docs/2_20/stan-users-guide/simulating-from-a-gaussian-process.html#cholesky-factored-and-transformed-implementation) - [**10\.3** Fitting a Gaussian Process](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html) - [GP with a normal outcome](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#gp-with-a-normal-outcome) - [Discrete outcomes with Gaussian Processes](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#discrete-outcomes-with-gaussian-processes) - [Automatic Relevance Determination](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#automatic-relevance-determination) - [**10\.3.1** Priors for Gaussian Process Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#priors-gp.section) - [Predictive Inference with a Gaussian Process](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#predictive-inference-with-a-gaussian-process) - [Multiple-output Gaussian processes](https://mc-stan.org/docs/2_20/stan-users-guide/fit-gp-section.html#multiple-output-gaussian-processes) - [**11** Directions, Rotations, and Hyperspheres](https://mc-stan.org/docs/2_20/stan-users-guide/directions-rotations-and-hyperspheres.html "11 Directions, Rotations, and Hyperspheres") - [**11\.1** Unit Vectors](https://mc-stan.org/docs/2_20/stan-users-guide/unit-vectors.html) - [**11\.2** Circles, Spheres, and Hyperspheres](https://mc-stan.org/docs/2_20/stan-users-guide/circles-spheres-and-hyperspheres.html) - [**11\.3** Transforming to Unconstrained Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/transforming-to-unconstrained-parameters.html) - [**11\.4** Unit Vectors and Rotations](https://mc-stan.org/docs/2_20/stan-users-guide/unit-vectors-and-rotations.html) - [Unit vector type](https://mc-stan.org/docs/2_20/stan-users-guide/unit-vectors-and-rotations.html#unit-vector-type) - [Angles from unit vectors](https://mc-stan.org/docs/2_20/stan-users-guide/unit-vectors-and-rotations.html#angles-from-unit-vectors) - [**11\.5** Circular Representations of Days and Years](https://mc-stan.org/docs/2_20/stan-users-guide/circular-representations-of-days-and-years.html) - [**12** Solving Algebraic Equations](https://mc-stan.org/docs/2_20/stan-users-guide/algebra-solver-chapter.html) - [**12\.1** Example: System of Nonlinear Algebraic Equations](https://mc-stan.org/docs/2_20/stan-users-guide/example-system-of-nonlinear-algebraic-equations.html) - [**12\.2** Coding an Algebraic System](https://mc-stan.org/docs/2_20/stan-users-guide/coding-an-algebraic-system.html) - [**12\.3** Calling the Algebraic Solver](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-algebraic-solver.html) - [Data versus Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-algebraic-solver.html#data-versus-parameters) - [Length of the Algebraic Function and of the Vector of Unknowns](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-algebraic-solver.html#length-of-the-algebraic-function-and-of-the-vector-of-unknowns) - [Pathological Solutions](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-algebraic-solver.html#pathological-solutions) - [**12\.4** Control Parameters for the Algebraic Solver](https://mc-stan.org/docs/2_20/stan-users-guide/algebra-control-section.html) - [Tolerance](https://mc-stan.org/docs/2_20/stan-users-guide/algebra-control-section.html#tolerance) - [Maximum Number of Steps](https://mc-stan.org/docs/2_20/stan-users-guide/algebra-control-section.html#maximum-number-of-steps) - [**13** Ordinary Differential Equations](https://mc-stan.org/docs/2_20/stan-users-guide/ode-solver-chapter.html) - [**13\.1** Example: Simple Harmonic Oscillator](https://mc-stan.org/docs/2_20/stan-users-guide/example-simple-harmonic-oscillator.html) - [Solutions Given Initial Conditions](https://mc-stan.org/docs/2_20/stan-users-guide/example-simple-harmonic-oscillator.html#solutions-given-initial-conditions) - [**13\.2** Coding an ODE System](https://mc-stan.org/docs/2_20/stan-users-guide/coding-an-ode-system.html) - [Strict Signature](https://mc-stan.org/docs/2_20/stan-users-guide/coding-an-ode-system.html#strict-signature-1) - [Discontinuous ODE System Function](https://mc-stan.org/docs/2_20/stan-users-guide/coding-an-ode-system.html#discontinuous-ode-system-function) - [**13\.3** Solving a System of Linear ODEs using a Matrix Exponential](https://mc-stan.org/docs/2_20/stan-users-guide/solving-a-system-of-linear-odes-using-a-matrix-exponential.html) - [**13\.4** Measurement Error Models](https://mc-stan.org/docs/2_20/stan-users-guide/measurement-error-models.html) - [Simulating Noisy Measurements](https://mc-stan.org/docs/2_20/stan-users-guide/measurement-error-models.html#simulating-noisy-measurements) - [Data versus Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/measurement-error-models.html#data-versus-parameters-1) - [Estimating System Parameters and Initial State](https://mc-stan.org/docs/2_20/stan-users-guide/measurement-error-models.html#estimating-system-parameters-and-initial-state) - [**13\.5** Stiff ODEs](https://mc-stan.org/docs/2_20/stan-users-guide/stiff-ode-section.html) - [**13\.6** Control Parameters for ODE Solving](https://mc-stan.org/docs/2_20/stan-users-guide/control-parameters-for-ode-solving.html) - [Data only for control parameters](https://mc-stan.org/docs/2_20/stan-users-guide/control-parameters-for-ode-solving.html#data-only-for-control-parameters) - [Tolerance](https://mc-stan.org/docs/2_20/stan-users-guide/control-parameters-for-ode-solving.html#tolerance-1) - [Maximum Number of Steps](https://mc-stan.org/docs/2_20/stan-users-guide/control-parameters-for-ode-solving.html#maximum-number-of-steps-1) - [**14** Computing One Dimensional Integrals](https://mc-stan.org/docs/2_20/stan-users-guide/integrate-1d.html "14 Computing One Dimensional Integrals") - [**14\.0.1** Strict Signature](https://mc-stan.org/docs/2_20/stan-users-guide/integrate-1d.html#strict-signature-2) - [**14\.1** Calling the Integrator](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-integrator.html) - [**14\.1.1** Limits of Integration](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-integrator.html#limits-of-integration) - [**14\.1.2** Data Versus Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/calling-the-integrator.html#data-versus-parameters-2) - [**14\.2** Integrator Convergence](https://mc-stan.org/docs/2_20/stan-users-guide/integrator-convergence.html) - [**14\.2.1** Zero-crossing Integrals](https://mc-stan.org/docs/2_20/stan-users-guide/integrator-convergence.html#zero-crossing) - [**14\.2.2** Avoiding precision loss near limits of integration in definite integrals](https://mc-stan.org/docs/2_20/stan-users-guide/integrator-convergence.html#integral-precision) - [*Part 2. Programming Techniques*](https://mc-stan.org/docs/2_20/stan-users-guide/part-2-programming-techniques.html#part-2.-programming-techniques) - [**15** Floating Point Arithmetic](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-arithmetic.html) - [**15\.1** Floating-point representations](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html) - [**15\.1.1** Finite values](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#finite-values) - [**15\.1.2** Normality](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#normality) - [**15\.1.3** Ranges and extreme values](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#ranges-and-extreme-values) - [**15\.1.4** Signed zero](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#signed-zero) - [**15\.1.5** Not-a-number values](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#not-a-number-values) - [**15\.1.6** Positive and negative infinity](https://mc-stan.org/docs/2_20/stan-users-guide/floating-point-representations.html#positive-and-negative-infinity) - [**15\.2** Literals: decimal and scientific notation](https://mc-stan.org/docs/2_20/stan-users-guide/literals-decimal-and-scientific-notation.html) - [**15\.3** Arithmetic Precision](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html) - [**15\.3.1** Rounding and probabilities](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#rounding-and-probabilities) - [**15\.3.2** Machine precision and the asymmetry of 0 and 1](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#machine-precision-and-the-asymmetry-of-0-and-1) - [**15\.3.3** Complementary and epsilon functions](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#complementary-and-epsilon-functions) - [**15\.3.4** Catastrophic cancellation](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#catastrophic-cancellation) - [**15\.3.5** Overflow](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#overflow) - [**15\.3.6** Underflow and the log scale](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#underflow-and-the-log-scale) - [**15\.3.7** Adding on the log scale](https://mc-stan.org/docs/2_20/stan-users-guide/arithmetic-precision.html#adding-on-the-log-scale) - [**15\.4** Comparing floating-point numbers](https://mc-stan.org/docs/2_20/stan-users-guide/comparing-floating-point-numbers.html) - [**16** Matrices, Vectors, and Arrays](https://mc-stan.org/docs/2_20/stan-users-guide/matrices-vectors-and-arrays.html) - [**16\.1** Basic Motivation](https://mc-stan.org/docs/2_20/stan-users-guide/basic-motivation.html) - [**16\.2** Fixed Sizes and Indexing out of Bounds](https://mc-stan.org/docs/2_20/stan-users-guide/fixed-sizes-and-indexing-out-of-bounds.html) - [**16\.3** Data Type and Indexing Efficiency](https://mc-stan.org/docs/2_20/stan-users-guide/indexing-efficiency-section.html) - [Matrices vs. Two-Dimensional Arrays](https://mc-stan.org/docs/2_20/stan-users-guide/indexing-efficiency-section.html#matrices-vs.-two-dimensional-arrays) - [(Row) Vectors vs. One-Dimensional Arrays](https://mc-stan.org/docs/2_20/stan-users-guide/indexing-efficiency-section.html#row-vectors-vs.-one-dimensional-arrays) - [**16\.4** Memory Locality](https://mc-stan.org/docs/2_20/stan-users-guide/memory-locality.html) - [Memory Locality](https://mc-stan.org/docs/2_20/stan-users-guide/memory-locality.html#memory-locality-1) - [Matrices](https://mc-stan.org/docs/2_20/stan-users-guide/memory-locality.html#matrices) - [Arrays](https://mc-stan.org/docs/2_20/stan-users-guide/memory-locality.html#arrays) - [**16\.5** Converting among Matrix, Vector, and Array Types](https://mc-stan.org/docs/2_20/stan-users-guide/converting-among-matrix-vector-and-array-types.html) - [**16\.6** Aliasing in Stan Containers](https://mc-stan.org/docs/2_20/stan-users-guide/aliasing-in-stan-containers.html) - [**17** Multiple Indexing and Range Indexing](https://mc-stan.org/docs/2_20/stan-users-guide/multi-indexing-chapter.html "17 Multiple Indexing and Range Indexing") - [**17\.1** Multiple Indexing](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexing.html) - [**17\.2** Slicing with Range Indexes](https://mc-stan.org/docs/2_20/stan-users-guide/slicing-with-range-indexes.html) - [Lower and Upper Bound Indexes](https://mc-stan.org/docs/2_20/stan-users-guide/slicing-with-range-indexes.html#lower-and-upper-bound-indexes) - [Lower or Upper Bound Indexes](https://mc-stan.org/docs/2_20/stan-users-guide/slicing-with-range-indexes.html#lower-or-upper-bound-indexes) - [Full Range Indexes](https://mc-stan.org/docs/2_20/stan-users-guide/slicing-with-range-indexes.html#full-range-indexes) - [**17\.3** Multiple Indexing on the Left of Assignments](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexing-on-the-left-of-assignments.html) - [Assign-by-Value and Aliasing](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexing-on-the-left-of-assignments.html#assign-by-value-and-aliasing) - [**17\.4** Multiple Indexes with Vectors and Matrices](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexes-with-vectors-and-matrices.html) - [Vectors](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexes-with-vectors-and-matrices.html#vectors) - [Matrices](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexes-with-vectors-and-matrices.html#matrices-1) - [Matrices with One Multiple Index](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexes-with-vectors-and-matrices.html#matrices-with-one-multiple-index) - [Arrays of Vectors or Matrices](https://mc-stan.org/docs/2_20/stan-users-guide/multiple-indexes-with-vectors-and-matrices.html#arrays-of-vectors-or-matrices) - [**17\.5** Matrices with Parameters and Constants](https://mc-stan.org/docs/2_20/stan-users-guide/matrices-with-parameters-and-constants.html) - [**18** User-Defined Functions](https://mc-stan.org/docs/2_20/stan-users-guide/functions-programming-chapter.html) - [**18\.1** Basic Functions](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html) - [User-Defined Functions Block](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#user-defined-functions-block) - [Function Bodies](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#function-bodies) - [Return Statements](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#return-statements) - [Reject Statements](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#reject-statements) - [Type Declarations for Functions](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#type-declarations-for-functions) - [Array Types for Function Declarations](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#array-types-for-function-declarations) - [Data-only Function Arguments](https://mc-stan.org/docs/2_20/stan-users-guide/basic-functions-section.html#data-only-function-arguments) - [**18\.2** Functions as Statements](https://mc-stan.org/docs/2_20/stan-users-guide/functions-as-statements.html) - [**18\.3** Functions Accessing the Log Probability Accumulator](https://mc-stan.org/docs/2_20/stan-users-guide/functions-accessing-the-log-probability-accumulator.html) - [**18\.4** Functions Acting as Random Number Generators](https://mc-stan.org/docs/2_20/stan-users-guide/functions-acting-as-random-number-generators.html) - [**18\.5** User-Defined Probability Functions](https://mc-stan.org/docs/2_20/stan-users-guide/user-defined-probability-functions.html) - [**18\.6** Overloading Functions](https://mc-stan.org/docs/2_20/stan-users-guide/overloading-functions.html) - [**18\.7** Documenting Functions](https://mc-stan.org/docs/2_20/stan-users-guide/documenting-functions-section.html) - [**18\.8** Summary of Function Types](https://mc-stan.org/docs/2_20/stan-users-guide/summary-of-function-types.html) - [Void vs. Non-Void Return](https://mc-stan.org/docs/2_20/stan-users-guide/summary-of-function-types.html#void-vs.-non-void-return) - [Suffixed or Non-Suffixed](https://mc-stan.org/docs/2_20/stan-users-guide/summary-of-function-types.html#suffixed-or-non-suffixed) - [**18\.9** Recursive Functions](https://mc-stan.org/docs/2_20/stan-users-guide/recursive-functions.html) - [**18\.10** Truncated Random Number Generation](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-random-number-generation.html) - [Generation with Inverse CDFs](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-random-number-generation.html#generation-with-inverse-cdfs) - [Truncated variate generation](https://mc-stan.org/docs/2_20/stan-users-guide/truncated-random-number-generation.html#truncated-variate-generation) - [**19** Custom Probability Functions](https://mc-stan.org/docs/2_20/stan-users-guide/custom-probability-functions-chapter.html) - [**19\.1** Examples](https://mc-stan.org/docs/2_20/stan-users-guide/examples.html) - [Triangle distribution](https://mc-stan.org/docs/2_20/stan-users-guide/examples.html#triangle-distribution) - [Exponential distribution](https://mc-stan.org/docs/2_20/stan-users-guide/examples.html#exponential-distribution) - [Bivariate normal cumulative distribution function](https://mc-stan.org/docs/2_20/stan-users-guide/examples.html#bivariate-normal-cumulative-distribution-function) - [**20** Problematic Posteriors](https://mc-stan.org/docs/2_20/stan-users-guide/problematic-posteriors-chapter.html) - [**20\.1** Collinearity of Predictors in Regressions](https://mc-stan.org/docs/2_20/stan-users-guide/collinearity-section.html) - [Examples of Collinearity](https://mc-stan.org/docs/2_20/stan-users-guide/collinearity-section.html#examples-of-collinearity) - [Mitigating the Invariances](https://mc-stan.org/docs/2_20/stan-users-guide/collinearity-section.html#mitigating-the-invariances) - [**20\.2** Label Switching in Mixture Models](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html) - [Mixture Models](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html#mixture-models) - [Convergence Monitoring and Effective Sample Size](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html#convergence-monitoring-and-effective-sample-size) - [Some Inferences are Invariant](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html#some-inferences-are-invariant) - [Highly Multimodal Posteriors](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html#highly-multimodal-posteriors) - [Hacks as Fixes](https://mc-stan.org/docs/2_20/stan-users-guide/label-switching-problematic-section.html#hacks-as-fixes) - [**20\.3** Component Collapsing in Mixture Models](https://mc-stan.org/docs/2_20/stan-users-guide/component-collapsing-in-mixture-models.html) - [**20\.4** Posteriors with Unbounded Densities](https://mc-stan.org/docs/2_20/stan-users-guide/posteriors-with-unbounded-densities.html) - [Mixture Models with Varying Scales](https://mc-stan.org/docs/2_20/stan-users-guide/posteriors-with-unbounded-densities.html#mixture-models-with-varying-scales) - [Beta-Binomial Models with Skewed Data and Weak Priors](https://mc-stan.org/docs/2_20/stan-users-guide/posteriors-with-unbounded-densities.html#beta-binomial-models-with-skewed-data-and-weak-priors) - [**20\.5** Posteriors with Unbounded Parameters](https://mc-stan.org/docs/2_20/stan-users-guide/posteriors-with-unbounded-parameters.html) - [Separability in Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/posteriors-with-unbounded-parameters.html#separability-in-logistic-regression) - [**20\.6** Uniform Posteriors](https://mc-stan.org/docs/2_20/stan-users-guide/uniform-posteriors.html) - [**20\.7** Sampling Difficulties with Problematic Priors](https://mc-stan.org/docs/2_20/stan-users-guide/sampling-difficulties-with-problematic-priors.html) - [Gibbs Sampling](https://mc-stan.org/docs/2_20/stan-users-guide/sampling-difficulties-with-problematic-priors.html#gibbs-sampling) - [Hamiltonian Monte Carlo Sampling](https://mc-stan.org/docs/2_20/stan-users-guide/sampling-difficulties-with-problematic-priors.html#hamiltonian-monte-carlo-sampling) - [No-U-Turn Sampling](https://mc-stan.org/docs/2_20/stan-users-guide/sampling-difficulties-with-problematic-priors.html#no-u-turn-sampling) - [Examples: Fits in Stan](https://mc-stan.org/docs/2_20/stan-users-guide/sampling-difficulties-with-problematic-priors.html#examples-fits-in-stan) - [**21** Reparameterization and Change of Variables](https://mc-stan.org/docs/2_20/stan-users-guide/change-of-variables-chapter.html "21 Reparameterization and Change of Variables") - [**21\.1** Theoretical and Practical Background](https://mc-stan.org/docs/2_20/stan-users-guide/theoretical-and-practical-background.html) - [**21\.2** Reparameterizations](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterizations.html) - [Beta and Dirichlet Priors](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterizations.html#beta-and-dirichlet-priors) - [Transforming Unconstrained Priors: Probit and Logit](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterizations.html#transforming-unconstrained-priors-probit-and-logit) - [**21\.3** Changes of Variables](https://mc-stan.org/docs/2_20/stan-users-guide/changes-of-variables.html) - [Change of Variables vs. Transformations](https://mc-stan.org/docs/2_20/stan-users-guide/changes-of-variables.html#change-of-variables-vs.-transformations) - [Multivariate Changes of Variables](https://mc-stan.org/docs/2_20/stan-users-guide/changes-of-variables.html#multivariate-changes-of-variables) - [**21\.4** Vectors with Varying Bounds](https://mc-stan.org/docs/2_20/stan-users-guide/vectors-with-varying-bounds.html) - [Varying Lower Bounds](https://mc-stan.org/docs/2_20/stan-users-guide/vectors-with-varying-bounds.html#varying-lower-bounds) - [Varying Upper and Lower Bounds](https://mc-stan.org/docs/2_20/stan-users-guide/vectors-with-varying-bounds.html#varying-upper-and-lower-bounds) - [**22** Efficiency Tuning](https://mc-stan.org/docs/2_20/stan-users-guide/optimization-chapter.html) - [**22\.1** What is Efficiency?](https://mc-stan.org/docs/2_20/stan-users-guide/what-is-efficiency.html) - [**22\.2** Efficiency for Probabilistic Models and Algorithms](https://mc-stan.org/docs/2_20/stan-users-guide/efficiency-for-probabilistic-models-and-algorithms.html) - [**22\.3** Statistical vs. Computational Efficiency](https://mc-stan.org/docs/2_20/stan-users-guide/statistical-vs-computational-efficiency.html) - [**22\.4** Model Conditioning and Curvature](https://mc-stan.org/docs/2_20/stan-users-guide/model-conditioning-and-curvature.html) - [Condition Number and Adaptation](https://mc-stan.org/docs/2_20/stan-users-guide/model-conditioning-and-curvature.html#condition-number-and-adaptation) - [Unit Scales without Correlation](https://mc-stan.org/docs/2_20/stan-users-guide/model-conditioning-and-curvature.html#unit-scales-without-correlation) - [Varying Curvature](https://mc-stan.org/docs/2_20/stan-users-guide/model-conditioning-and-curvature.html#varying-curvature) - [Reparameterizing with a Change of Variables](https://mc-stan.org/docs/2_20/stan-users-guide/model-conditioning-and-curvature.html#reparameterizing-with-a-change-of-variables) - [**22\.5** Well-Specified Models](https://mc-stan.org/docs/2_20/stan-users-guide/well-specified-models.html) - [**22\.6** Avoiding Validation](https://mc-stan.org/docs/2_20/stan-users-guide/avoiding-validation.html) - [**22\.7** Reparameterization](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html) - [Example: Neal’s Funnel](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#example-neals-funnel) - [Reparameterizing the Cauchy](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#reparameterizing-the-cauchy) - [Reparameterizing a Student-t Distribution](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#reparameterizing-a-student-t-distribution) - [Hierarchical Models and the Non-Centered Parameterization](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#hierarchical-models-and-the-non-centered-parameterization) - [Non-Centered Parameterization](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#non-centered-parameterization) - [Multivariate Reparameterizations](https://mc-stan.org/docs/2_20/stan-users-guide/reparameterization-section.html#multivariate-reparameterizations) - [**22\.8** Vectorization](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html) - [Gradient Bottleneck](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html#gradient-bottleneck) - [Vectorizing Summations](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html#vectorizing-summations) - [Vectorization through Matrix Operations](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html#vectorization-through-matrix-operations) - [Vectorized Probability Functions](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html#vectorized-probability-functions) - [Reshaping Data for Vectorization](https://mc-stan.org/docs/2_20/stan-users-guide/vectorization.html#reshaping-data-for-vectorization) - [**22\.9** Exploiting Sufficient Statistics](https://mc-stan.org/docs/2_20/stan-users-guide/exploiting-sufficient-statistics.html) - [**22\.10** Aggregating Common Subexpressions](https://mc-stan.org/docs/2_20/stan-users-guide/aggregating-common-subexpressions.html) - [**22\.11** Exploiting Conjugacy](https://mc-stan.org/docs/2_20/stan-users-guide/exploiting-conjugacy.html) - [**22\.12** Standardizing Predictors and Outputs](https://mc-stan.org/docs/2_20/stan-users-guide/standardizing-predictors-and-outputs.html) - [Standard Normal Distribution](https://mc-stan.org/docs/2_20/stan-users-guide/standardizing-predictors-and-outputs.html#standard-normal-distribution) - [**22\.13** Using Map-Reduce](https://mc-stan.org/docs/2_20/stan-users-guide/using-map-reduce.html) - [**23** Map-Reduce](https://mc-stan.org/docs/2_20/stan-users-guide/map-reduce-chapter.html) - [**23\.1** Overview of Map-Reduce](https://mc-stan.org/docs/2_20/stan-users-guide/overview-of-map-reduce.html) - [**23\.2** Map Function](https://mc-stan.org/docs/2_20/stan-users-guide/map-function.html) - [Map Function Signature](https://mc-stan.org/docs/2_20/stan-users-guide/map-function.html#map-function-signature) - [Map Function Semantics](https://mc-stan.org/docs/2_20/stan-users-guide/map-function.html#map-function-semantics) - [**23\.3** Example: Mapping Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/example-mapping-logistic-regression.html) - [Unmapped Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/example-mapping-logistic-regression.html#unmapped-logistic-regression) - [Mapped Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/example-mapping-logistic-regression.html#mapped-logistic-regression) - [**23\.4** Example: Hierarchical Logistic Regression](https://mc-stan.org/docs/2_20/stan-users-guide/example-hierarchical-logistic-regression.html) - [Unmapped Implementation](https://mc-stan.org/docs/2_20/stan-users-guide/example-hierarchical-logistic-regression.html#unmapped-implementation) - [Mapped Implementation](https://mc-stan.org/docs/2_20/stan-users-guide/example-hierarchical-logistic-regression.html#mapped-implementation) - [**23\.5** Ragged Inputs and Outputs](https://mc-stan.org/docs/2_20/stan-users-guide/ragged-inputs-and-outputs.html) - [Ragged Inputs](https://mc-stan.org/docs/2_20/stan-users-guide/ragged-inputs-and-outputs.html#ragged-inputs) - [Ragged Outputs](https://mc-stan.org/docs/2_20/stan-users-guide/ragged-inputs-and-outputs.html#ragged-outputs) - [*Appendices*](https://mc-stan.org/docs/2_20/stan-users-guide/appendices-part.html#appendices.part) - [**24** Stan Program Style Guide](https://mc-stan.org/docs/2_20/stan-users-guide/stan-program-style-guide.html) - [**24\.1** Choose a Consistent Style](https://mc-stan.org/docs/2_20/stan-users-guide/choose-a-consistent-style.html) - [**24\.2** Line Length](https://mc-stan.org/docs/2_20/stan-users-guide/line-length.html) - [**24\.3** File Extensions](https://mc-stan.org/docs/2_20/stan-users-guide/file-extensions.html) - [**24\.4** Variable Naming](https://mc-stan.org/docs/2_20/stan-users-guide/variable-naming.html) - [**24\.5** Local Variable Scope](https://mc-stan.org/docs/2_20/stan-users-guide/local-variable-scope.html) - [**24\.6** Parentheses and Brackets](https://mc-stan.org/docs/2_20/stan-users-guide/parentheses-and-brackets.html) - [Optional Parentheses for Single-Statement Blocks](https://mc-stan.org/docs/2_20/stan-users-guide/parentheses-and-brackets.html#optional-parentheses-for-single-statement-blocks) - [Parentheses in Nested Operator Expressions](https://mc-stan.org/docs/2_20/stan-users-guide/parentheses-and-brackets.html#parentheses-in-nested-operator-expressions) - [No Open Brackets on Own Line](https://mc-stan.org/docs/2_20/stan-users-guide/parentheses-and-brackets.html#no-open-brackets-on-own-line) - [**24\.7** Conditionals](https://mc-stan.org/docs/2_20/stan-users-guide/conditionals.html) - [Explicit Comparisons of Non-Boolean Conditions](https://mc-stan.org/docs/2_20/stan-users-guide/conditionals.html#explicit-comparisons-of-non-boolean-conditions) - [**24\.8** Functions](https://mc-stan.org/docs/2_20/stan-users-guide/functions.html) - [**24\.9** White Space](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html) - [Line Breaks Between Statements and Declarations](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#line-breaks-between-statements-and-declarations) - [No Tabs](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#no-tabs) - [Two-Character Indents](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#two-character-indents) - [**24\.9.1** Space Between `if`, `{` and Condition](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#space-between-if-and-condition) - [No Space For Function Calls](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#no-space-for-function-calls) - [Spaces Around Operators](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#spaces-around-operators) - [Breaking Expressions across Lines](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#breaking-expressions-across-lines) - [Optional Spaces after Commas](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#optional-spaces-after-commas) - [Unix Newlines](https://mc-stan.org/docs/2_20/stan-users-guide/white-space.html#unix-newlines) - [**25** Transitioning from BUGS](https://mc-stan.org/docs/2_20/stan-users-guide/stan-for-bugs-appendix.html) - [**25\.1** Some Differences in How BUGS and Stan Work](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html) - [BUGS is interpreted, Stan is compiled](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#bugs-is-interpreted-stan-is-compiled) - [BUGS performs MCMC updating one scalar parameter at a time, Stan uses HMC which moves in the entire space of all the parameters at each step](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#bugs-performs-mcmc-updating-one-scalar-parameter-at-a-time-stan-uses-hmc-which-moves-in-the-entire-space-of-all-the-parameters-at-each-step) - [Differences in tuning during warmup](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#differences-in-tuning-during-warmup) - [The Stan language is directly executable, the BUGS modeling language is not](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#the-stan-language-is-directly-executable-the-bugs-modeling-language-is-not) - [Differences in statement order](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#differences-in-statement-order) - [Stan computes the gradient of the log density, BUGS computes the log density but not its gradient](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#stan-computes-the-gradient-of-the-log-density-bugs-computes-the-log-density-but-not-its-gradient) - [Both BUGS and Stan are semi-automatic](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#both-bugs-and-stan-are-semi-automatic) - [Licensing](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#licensing) - [Interfaces](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#interfaces) - [Platforms](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html#platforms) - [**25\.2** Some Differences in the Modeling Languages](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-the-modeling-languages.html) - [**25\.3** Some Differences in the Statistical Models that are Allowed](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-in-the-statistical-models-that-are-allowed.html) - [**25\.4** Some Differences when Running from R](https://mc-stan.org/docs/2_20/stan-users-guide/some-differences-when-running-from-r.html) - [**25\.5** The Stan Community](https://mc-stan.org/docs/2_20/stan-users-guide/the-stan-community.html) - [*References*](https://mc-stan.org/docs/2_20/stan-users-guide/references.html#references) A A Serif Sans White Sepia Night # [Stan User’s Guide](https://mc-stan.org/docs/2_20/stan-users-guide/) This is an old version, [view current version](https://mc-stan.org/docs/stan-users-guide/finite-mixtures.html#zero-inflated.section). ## 5\.6 Zero-Inflated and Hurdle Models Zero-inflated and hurdle models both provide mixtures of a Poisson and Bernoulli probability mass function to allow more flexibility in modeling the probability of a zero outcome. Zero-inflated models, as defined by Lambert ([1992](https://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html#ref-Lambert:1992)), add additional probability mass to the outcome of zero. Hurdle models, on the other hand, are formulated as pure mixtures of zero and non-zero outcomes. Zero inflation and hurdle models can be formulated for discrete distributions other than the Poisson. Zero inflation does not work for continuous distributions in Stan because of issues with derivatives; in particular, there is no way to add a point mass to a continuous distribution, such as zero-inflating a normal as a regression coefficient prior. ### Zero Inflation Consider the following example for zero-inflated Poisson distributions. It uses a parameter `theta` here there is a probability θ θ of drawing a zero, and a probability 1−θ 1 − θ of drawing from Poisson(λ) P o i s s o n ( λ ) (now θ θ is being used for mixing proportions because λ λ is the traditional notation for a Poisson mean parameter). The probability function is thus p(yn\|θ,λ)\={θ\+(1−θ)∗Poisson(0\|λ) if yn\=0, and(1−θ)∗Poisson(yn\|λ) if yn\>0\. p ( y n \| θ , λ ) \= { θ \+ ( 1 − θ ) ∗ P o i s s o n ( 0 \| λ ) if y n \= 0 , and ( 1 − θ ) ∗ P o i s s o n ( y n \| λ ) if y n \> 0\. The log probability function can be implemented directly in Stan as follows. ``` data { int<lower=0> N; int<lower=0> y[N]; } parameters { real<lower=0, upper=1> theta; real<lower=0> lambda; } model { for (n in 1:N) { if (y[n] == 0) target += log_sum_exp(bernoulli_lpmf(1 | theta), bernoulli_lpmf(0 | theta) + poisson_lpmf(y[n] | lambda)); else target += bernoulli_lpmf(0 | theta) + poisson_lpmf(y[n] | lambda); } } ``` The `log_sum_exp(lp1,lp2)` function adds the log probabilities on the linear scale; it is defined to be equal to `log(exp(lp1) + exp(lp2))`, but is more arithmetically stable and faster. #### Optimizing the zero-inflated Poisson model The code given above to compute the zero-inflated Poisson redundantly calculates all of the Bernoulli terms and also `poisson_lpmf(0 | lambda)` every time the first condition body executes. The use of the redundant terms is conditioned on `y`, which is known when the data are read in. This allows the transformed data block to be used to compute some more convenient terms for expressing the log density each iteration. The number of zero cases is computed and handled separately. Then the nonzero cases are collected into their own array for vectorization. The number of zeros is required to declare `y_nonzero`, so it must be computed in a function. ``` functions { int num_zeros(int[] y) { int sum = 0; for (n in 1:size(y)) sum += (y[n] == 0); return sum; } } ... transformed data { int<lower = 0> N_zero = num_zeros(y); int<lower = 1> y_nonzero[N - N_zero]; int N_nonzero = 0; for (n in 1:N) { if (y[n] == 0) continue; N_nonzero += 1; y_nonzero[N_nonzero] = y[n]; } } ... model { ... target += N_zero * log_sum_exp(bernoulli_lpmf(1 | theta), bernoulli_lpmf(0 | theta) + poisson_lpmf(0 | lambda)); target += N_nonzero * bernoulli_lpmf(0 | theta); target += poisson_lpmf(y_nonzero | lambda); ... ``` The boundary conditions of all zeros and no zero outcomes is handled appropriately; in the vectorized case, if `y_nonzero` is empty, `N_nonzero` will be zero, and the last two target increment terms will add zeros. ### Hurdle Models The hurdle model is similar to the zero-inflated model, but more flexible in that the zero outcomes can be deflated as well as inflated. The probability mass function for the hurdle likelihood is defined by p(y\|θ,λ)\=⎧⎨⎩ θif y\=0, and (1−θ) Poisson(y\|λ)1−PoissonCDF(0\|λ)if y\>0, p ( y \| θ , λ ) \= { θ if y \= 0 , and ( 1 − θ ) P o i s s o n ( y \| λ ) 1 − P o i s s o n C D F ( 0 \| λ ) if y \> 0 , where PoissonCDF P o i s s o n C D F is the cumulative distribution function for the Poisson distribution. The hurdle model is even more straightforward to program in Stan, as it does not require an explicit mixture. ``` if (y[n] == 0) 1 ~ bernoulli(theta); else { 0 ~ bernoulli(theta); y[n] ~ poisson(lambda) T[1, ]; } ``` The Bernoulli statements are just shorthand for adding logθ log ⁡ θ and log(1−θ) log ⁡ ( 1 − θ ) to the log density. The `T[1,]` after the Poisson indicates that it is truncated below at 1; see the [truncation section](https://mc-stan.org/docs/2_20/stan-users-guide/truncation-section.html#truncation.section) for more about truncation and the [Poisson regresison section](https://mc-stan.org/docs/2_20/stan-users-guide/zero-inflated-section.html#poisson.section) for the specifics of the Poisson CDF. The net effect is equivalent to the direct definition of the log likelihood. ``` if (y[n] == 0) target += log(theta); else target += log1m(theta) + poisson_lpmf(y[n] | lambda) - poisson_lccdf(0 | lambda)); ``` Julian King pointed out that because log(1−PoissonCDF(0\|λ)) \= log(1−Poisson(0\|λ)) \= log(1−exp(−λ)) log ⁡ ( 1 − P o i s s o n C D F ( 0 \| λ ) ) \= log ⁡ ( 1 − P o i s s o n ( 0 \| λ ) ) \= log ⁡ ( 1 − exp ⁡ ( − λ ) ) the CCDF in the else clause can be replaced with a simpler expression. ``` target += log1m(theta) + poisson_lpmf(y[n] | lambda) - log1m_exp(-lambda)); ``` The resulting code is about 15% faster than the code with the CCDF. This is an example where collecting counts ahead of time can also greatly speed up the execution speed without changing the density. For data size N\=200 N \= 200 and parameters θ\=0\.3 θ \= 0\.3 and λ\=8 λ \= 8, the speedup is a factor of 10; it will be lower for smaller N N and greater for larger N N; it will also be greater for larger θ θ. To achieve this speedup, it helps to have a function to count the number of non-zero entries in an array of integers, ``` functions { int num_zero(int[] y) { int nz = 0; for (n in 1:size(y)) if (y[n] == 0) nz += 1; return nz; } } ``` Then a transformed data block can be used to store the sufficient statistics, ``` transformed data { int<lower=0, upper=N> N0 = num_zero(y); int<lower=0, upper=N> Ngt0 = N - N0; int<lower=1> y_nz[N - num_zero(y)]; { int pos = 1; for (n in 1:N) { if (y[n] != 0) { y_nz[pos] = y[n]; pos += 1; } } } } ``` The model block can then be reduced to three statements. ``` model { N0 ~ binomial(N, theta); y_nz ~ poisson(lambda); target += -Ngt0 * log1m_exp(-lambda); } ``` The first statement accounts for the Bernoulli contribution to both the zero and non-zero counts. The second line is the Poisson contribution from the non-zero counts, which is now vectorized. Finally, the normalization for the truncation is a single line, so that the expression for the log CCDF at 0 isn’t repeated. Also note that the negation is applied to the constant `Ngt0`; whenever possible, leave subexpressions constant because then gradients need not be propagated until a non-constant term is encountered. ### *References* Lambert, Diane. 1992. “Zero-Inflated Poisson Regression, with an Application to Defects in Manufacturing.” *Technometrics* 34 (1).
Readable Markdownnull
Shard18 (laksa)
Root Hash17466047053846532618
Unparsed URLorg,mc-stan!/docs/2_20/stan-users-guide/zero-inflated-section.html s443