Show the code of the figure
show(concepts.workflow({1: "done", 2: "done", 3: "here", 4: "here", 5: "here", 6: "here", 7: "here", 8: "here", 9: "later"}))November 30, 2026
Series: Bayesian Modelling for Agriculture, Part 2. Part 1 stated the planting decision as a loss that depends on the day. It described the onset of the rains as a time to event that is censored in 23 of 264 region-seasons, and it showed that the dipole of August to October is correlated with it in every region. This post builds the Bayesian model of the onset on the dipole and takes the planting day from its predictions.
Part 1 reduced the planting decision to one distribution that is still to be found, . It is the distribution of the onset day of the coming season, given the dipole index known on 1 November and the record . This post finds it with a Bayesian survival regression, one step at a time. Figure 1 shows the steps that it takes, from the likelihood to the action of least expected loss. The questions in the figure are the ones to ask of another problem in which a decision depends on a quantity that is observed with gaps.
The steps reuse the earlier posts by reference. Industrial Part 1 introduced Bayes’ theorem for the failure rate of a machine, and it checked the sampler and the prior. It turned a posterior into a decision on a service contract. It also remarked that a constant failure rate ignores wear-out and that a Weibull lifetime fits better when failures grow with age. This post applies that remedy to the wait for the rain. Industrial Part 3 supplies partial pooling and its non-centred form, and Industrial Part 4 the censored lifetime. The treatment follows the standard texts on Bayesian survival analysis, Bayesian data analysis and statistical decision theory.1
The slope of the log onset day on the dipole is negative in every analysis. The median onset moves earlier by about 8 days for each standard deviation of the index, averaged over the six regions. The 90% interval runs from 4.9 to 11.0 days once the seasons share an effect. The 23 seasons without an onset matter, because dropping them shrinks the slope by 14%. At Dodoma the median onset is day 58 after a season of positive dipole and day 86 after one of negative dipole. The planting day of least expected loss moves from day 56 to day 70, and in the second case 44% of the probability lies beyond the end of the window.
The first two steps were taken in Part 1, which fixed the loss and described the data, and the last is the test of Part 3. Figure 1 marks the steps of this post in blue: the likelihood, the priors, the posterior, the checks, the expansion of the model and the prediction with its action. The dashed loop is the part of a Bayesian analysis that a list of steps hides. A check that fails sends the analysis back to the model, and in this post it does so once, when the independence of the regions is relaxed.
The third step is to say how the data arise. Bayes’ theorem, and the roles of the prior, the likelihood and the posterior, are those of Industrial Part 1, and Part 1 worked a normal update by hand. There a posterior for the failure rate of a machine was computed from a short pilot. Here stands for all the parameters of the model and for the record. Each of the 264 records has a time , an indicator that is 1 when the onset was seen and 0 when it was censored, and an index . What changes is the likelihood,
where and are the density and the survival function of the time of record given and . As in Industrial Part 4, a censored season enters through its survival function. It counts for what it tells, that the time exceeds 92 days, and not as a missing value or as an onset on day 92.
What also changes is what is done with the posterior. In Industrial Part 1 the decision compared an expected cost with a price. Here the posterior is first turned into a predictive distribution for a new season with index ,
and the loss of the first section is averaged over it. A model and a prior give a posterior, the posterior gives a predictive distribution, and the predictive distribution and the loss give the action of least expected loss. The integral has no closed form for the censored model below. It becomes an average over draws from the sampler of Industrial Part 1, which here is the No-U-Turn sampler of PyMC.2
The time to the onset is Weibull, the form that Industrial Part 4 used for the life of a cell. Its survival function, with shape and scale , is
The scale sets the typical day of the onset. With a shape above one, the chance of an onset on a day, given that it has not come, rises with the days of waiting. The dipole enters through the scale, as an accelerated failure time model. For region and season ,
where is the standardised index, the level of the region and its slope. A slope multiplies the onset time by for each standard deviation of the index, so brings the onset forward by 14%. The slopes of the regions are drawn around a common slope with a spread , in the non-centred form of Industrial Part 3,
where each is standard normal. The levels are drawn in the same way around a common level. The offsets are the non-centred form of the hierarchy, a reparametrisation whose choice changes how efficiently a sampler explores a hierarchical model.3 In this partial pooling, a region with a short or scattered record borrows strength from the others in proportion to how alike the regions are. A region with a clear record keeps its own slope. Times are counted in units of 50 days, which keeps the parameters near one for the sampler.
The fourth step states what is believed before the record is seen, and each prior needs a reason that a reader can challenge. Table 1 lists every prior of the model with its reason, and the text below gives the sources.
| Parameter | Prior | Reason |
|---|---|---|
| Common slope, physical | Negative sign from the mechanism of the dipole, and a modest size of 14% earlier onset for one standard deviation, about 6 days. | |
| Common slope, weak | Centred on no effect and wide, so that the data decide. It is the comparison for the first. | |
| Weibull shape | Positive, with 90% of its mass from 1.3 to 4.8. A shape of 2.5 gives a coefficient of variation of 0.43. | |
| Level of the log scale | A scale of 40 days at the centre and 18 to 91 days at 90%, which covers most of the window. | |
| Spread of the slopes | Weakly informative for a group-level spread with six regions. | |
| Spread of the levels | The same reason, on a log scale where 0.3 is a difference of about a third. | |
| Season scale | The same reason. It enters in the section on dependence between regions. | |
| Offsets of the hierarchy | Standardised offsets of the non-centred form. |
The physical prior of the slope states what is known and leaves the rest open. Its sign follows the mechanism of the dipole described in Part 1. Its size is a judgement and not a published estimate. A change of 14% for one standard deviation moves the mean onset of 43 days by about 6 days. A farmer would notice that, and it still leaves most of the variation unexplained. Its 5%, 50% and 95% quantiles are a change of , and , and the probability of a negative slope is 0.84. The prior therefore leans towards the mechanism without excluding no effect. The weak prior has quantiles of , and . It serves as the comparison, in the spirit of the sensitivity check of Industrial Part 1.
The shape and the level are checked against the record, which means that they are not independent of it. The onsets of the regions have coefficients of variation of 0.37 to 0.50. A Weibull with a shape of 2.5 has 0.43, so the centre of the prior is in line with the record. The posterior moves to a shape of 2.59 without the season effect and 3.73 with it. The level of 40 days centres the scale on a typical onset, and its spread leaves most of the window open.
The three spreads follow the advice for group-level standard deviations. A noninformative prior on such a scale can change the inference when the groups are few, and six regions are few, so a weakly informative prior is used.4 The half-normal is the limit of the half- family that Gelman recommends as its degrees of freedom grow. Its scales are set against the effects they describe. A spread of the slopes of 0.15 is as large as the common slope. The half-normal gives a spread of that size or more a probability of about one in three. A spread of 0.3 on the log scale is a difference of about a third between regions or between seasons.
A prior is judged in the context of the likelihood,5 which is why the prior predictive check asks what the priors imply for the quantity of interest.6 The onset of a season of average index has 5%, 50% and 95% quantiles at days 7, 33 and 110 under the priors. Of the draws, 8.3% fall after the window, against 8.7% of the records that are censored. The priors thus allow every onset that is plausible and rule out little else, and they do not contradict the share of late seasons. Figure 2 draws the two priors of the slope with the least squares slope of each region. These slopes use only the seasons with an onset and are therefore a rough guide.
The fifth step computes the posterior and asks whether the computation can be trusted. Each fit has four chains of 1,000 draws after 1,000 tuning draws and a target acceptance rate of 0.95. The checks of the sampler are those of Industrial Part 1: the agreement of the chains, the effective sample size and the divergent transitions. The agreement of the chains is measured by the rank-normalised , and the sample size by its bulk and tail forms.7 The six fits to the 44 seasons have no divergent transitions, the largest is 1.009 and the smallest bulk effective sample size is 800.
In the posterior the common slope has a median of with a 90% interval from to . A slope on the log scale multiplies the onset by for each standard deviation of the index, so the median onset is 17% earlier. All 4,000 draws of the slope are negative. Averaged over the regions the median onset moves by days, with an interval from to days. A high dipole therefore brings the rains about a week forward, and the interval stays well away from no change. The weak prior gives the same, with an interval from to , so with 264 records the data overrule both priors. The update by hand of Part 1 pointed the same way, with a prior share of 3.8% or less. The result is hence a property of the record and not of the prior. Figure 3 draws the fitted median onset of each region against the record. Unlike the gamma posterior of Industrial Part 1, this model has no closed form to compare with, which is where sampling earns its place. The change in days is a proportion of the onset, so it is larger where the onset is later. It is about 14 days for each standard deviation at Dodoma, as the last section shows.
The seasons without an onset can be handled in three ways, and only one is right. They can be dropped, which treats a late season as missing. They can be read as an onset on day 92, which says that the rain came when the window closed. Or they can be censored, which says that the onset is later than day 92, and Figure 4 compares the three. Dropping the 23 seasons gives a slope of , a change of days. Reading them as onsets gives , or days, against and days when they are censored. Both shortcuts shrink the slope towards zero, by 14% and by 11%, because the missing seasons are the late ones and they occur where the index is low. The difference is small against an interval that is about 0.1 wide, so on this record the handling of the censoring changes the estimate modestly. It would matter more with more censoring, and it would be expected to matter most for Dodoma, where 34% of the seasons are censored.
The model so far treats the 264 records as independent, but the regions of one season share the ocean. After the index is taken out, the residuals of the log onset of different regions correlate at 0.55 on average over the seasons that have an onset. A shared season effect is therefore added to the log scale of all the regions of a season,
where is standard normal for each season and is its scale. The term makes the season the unit of information, whereas a model that ignores the dependence reports a precision that the data do not contain. Its scale has a half-normal prior like the other spreads and a posterior median of 0.30 with a 90% interval from 0.24 to 0.37. Two regions in one season share this effect and nothing else, so it implies a correlation of their log onset times of
The implied correlation has a median of 0.43 with an interval from 0.32 to 0.55. The measured 0.55 lies at the upper end of that interval, so the effect captures most of the dependence and perhaps not all of it.
Figure 5 compares the slope with and without the effect. With the effect the common slope has a median of and an interval from to , which is 1.6 times as wide as the interval without it. The regions of a season are not independent evidence, so the honest precision is that of 44 seasons and not of 264 records, and the wider interval says so. A bootstrap that resamples whole seasons and refits by maximum likelihood gives with an interval from to , between the two. Its estimate agrees with the median of the posterior. The shape of the Weibull rises from 2.59 to 3.73 when the season effect is added. The effect absorbs the variation between seasons and leaves the spread within a season to the shape. A higher shape means a tighter wait around the typical day once the common season is known. The model with the season effect is used for the predictions below. Its uncertainty matches the number of seasons and not the number of records.
Partial pooling lets each region borrow from the others in proportion to how alike they are. The spread of the regional slopes around the common slope has a median of 0.03 with a 90% interval from 0.00 to 0.09. The six regions therefore share one slope to a good approximation. Figure 6 compares the slope of each region without pooling and with partial pooling. Without pooling the slopes run from at Njombe to at Rukwa, each with an interval about 0.2 wide. Partial pooling moves them to between and and narrows the intervals, and the regions at the ends, Rukwa and Njombe, move most. The differences between regions are therefore consistent with sampling noise, and one effect of the dipole describes all six. A region with a short record could borrow its slope from the others in the same way.
The sixth step asks whether the model could have produced the data, and the seventh expands it if not. A model that fits a slope can still misplace the probability of a late season, which the planting decision uses. The first check therefore simulates the data from the fitted model with the season effect and counts the seasons without an onset in each region. This is a posterior predictive check, in which data replicated under the fitted model are compared with the observed data.8 The simulation draws a season effect for each of the 44 seasons. Figure 7 shows the distribution of the simulated count in each region, with the observed count marked under the axis. Dodoma has 15 seasons without an onset against a predicted median of 13 with a 90% range from 7 to 19. Iringa has 6 against 3 with a range from 1 to 8. In these two regions the observed counts lie on the upper side of the bars, where the record has somewhat more late seasons than the model’s most likely count. In the other four regions, which have 0 or 1, they lie in the bulk of the bars. The model gives the observed count a probability of 0.07 at Dodoma, 0.08 at Iringa and 0.32 at Mbeya. The probabilities are 0.24 at Njombe, 0.83 at Rukwa and 0.25 at Ruvuma. Each observed count is therefore a value that the model produces readily, and all six lie inside their 90% ranges. The two driest regions sit on the upper side, which suggests that the model if anything understates the chance of a late season there. A planting rule that leans on the tail should therefore be read as a lower bound on the risk at Dodoma and Iringa.
The second check asks whether one Weibull shape for all regions is too rigid. The standard deviations of the onsets of the regions run from 15 to 20 days. A model with a shape for each region, drawn from a common distribution, is the natural expansion. The shapes come out between 2.36 at Dodoma and 2.79 at Mbeya. Leave-one-out cross-validation scores how well each model predicts a record that it has not seen,9 as in Industrial Part 3, and it does not separate the two. The expected log predictive density is for one shape and for a shape for each region, a difference of 0.09 with a standard error of 1.49. A difference of 0.06 standard errors cannot separate the models. The richer one adds parameters, 12.9 effective against 9.6, without predicting better, so the simpler model is kept. The common slope under the richer model is with an interval from to , almost the same. The conclusion about the dipole therefore does not depend on this choice.
A check that passes does not prove a model. The records constrain the Weibull only up to day 92. The probability of an onset after the window comes from extending its tail, which the 23 censored seasons constrain and no onset beyond the window can confirm.
The eighth step turns the posterior into a prediction and the prediction into an action. For a season at Dodoma, the model with the season effect gives the distribution of the onset day. Figure 8 draws it for a dipole one standard deviation above the mean index and one below. Both values occur in the record, whose index has a standard deviation of 0.42 and runs from to 0.86. After a positive dipole the median onset is day 58 and 14% of the probability lies after the window. After a negative dipole the median is day 86 and 44% lies after it. The dipole therefore moves the whole distribution and not only its centre, by 14 days for each standard deviation of the index at Dodoma. A farmer who learns on 1 November that the dipole is negative should expect a late season. The chance that the rains do not come within the window is then more than two in five, and after a positive dipole it falls to about one in seven.
Figure 9 gives the expected loss of each planting day for the two cases under the ratio of 30 to 1. After a positive dipole the day of least loss is day 56, two days before the median onset. The days within 5% of the least loss run from day 46 to day 66. After a negative dipole it is day 70, and the days within 5% of the least loss run from day 50 to day 85. The climatology of Dodoma alone puts the best day at 60, with a band from day 40 to day 63. The two best days differ by 14 days, which is how far the advice moves with the dipole. The band after a negative dipole is 36 days wide against 21 days after a positive one. The forecast therefore says less about the date when the dipole is negative. The sensible advice there is to wait for the rain and not to commit to a day. It is not yet a gain in expected loss, which Part 3 measures on seasons that were held out.
The flat curve after a negative dipole carries a second message. With 44% of the probability beyond the window, no calendar date is a good bet, because every date has a large chance of being a false start. The honest advice is to wait for the rain and to plant when it has proved itself. That is the in-season problem of Part 4. These results describe what the fitted model believes about the seasons that it was fitted to. They do not say how well it predicts, and Part 3 tests that on seasons that the model has not seen.
The nine questions apply to another problem in which a decision depends on a quantity observed with gaps. The answer to each is a choice that the problem has to make for itself. First, state the loss, because it decides whether the optimum is a quantile or depends on the shape of the distribution. Second, define the quantity with its origin, horizon and target, and find what is hidden in its record. Here the late seasons were censored and occurred at a low dipole, so dropping them shrank the slope. Third, write the likelihood so that each kind of record contributes what it knows. An onset gives a density and a censored season gives the survival function, which in PyMC is pm.Censored.
Fourth, state the priors with a reason for each and judge them by what they imply for the quantity of interest. Fifth, compute the posterior, and trust it only when the chains agree, the effective sample size is large and no transition diverges. Sixth, ask the model to reproduce a feature that it was not fitted to, here the count of seasons without an onset. Seventh, expand the model only where a check or a comparison asks for it. The shared season effect was added for that reason, and a shape for each region was dropped for the opposite one. Eighth, turn the posterior into a distribution of the quantity and the distribution into the action of least expected loss. Ninth, test the whole on seasons that were held out, which Part 3 does. The functions of this post are in the bayes.climate package, and each one can be reused with another record.
The record holds 44 seasons, which fixes the precision of every result. The onset is the onset of a rule whose constants are not validated for Tanzania, and no gauge or farmer record of the onset exists to check it against. The rainfall is a satellite estimate averaged over regions, so a region is a coarse stand-in for a farm. The dipole was chosen from the record after the comparison with El Niño had been made on the same seasons, so that comparison is not out of sample. The Weibull tail beyond the window is an extension and not an observation, and the 44% after a negative dipole at Dodoma rests on it. The ratio of 30 to 1 is an illustration, and the planting day follows it. The post predicts the onset of the rule and not the agronomic onset. Part 4 approaches the agronomic onset by filtering the daily rainfall.
The distribution that the planting decision needs was built with a Weibull regression of the onset on the dipole of August to October. The 23 seasons without an onset were censored at the end of the window. The slope of the log onset day is , a median onset 17% earlier for each standard deviation of the index, or about 8 days earlier on average. The interval is to days once the regions of a season share an effect. A prior had little influence, the regions share one slope, and dropping the censored seasons would have shrunk the slope by 14%. The model reproduced the number of seasons without an onset in every region. At Dodoma the planting day of least expected loss is day 56 after a positive dipole and day 70 after a negative one. In the second case 44% of the probability lies beyond the window, so the advice is to wait for the rain. Part 3 tests these predictions on seasons that the model has not seen.
The notebook is in the bayesian-modelling repository and runs from the first cell to the last in its uv environment, with PyMC 6.4 and ArviZ 1.3. The rainfall of the regions ships with the package, and the indices are downloaded from NOAA on the first run. The rule, the models, the checks and the decision are functions of the bayes.climate package, which has unit tests. Among them are a closed-form test of the decision, a likelihood checked against a hand computation and a recovery of a planted slope from censored data. The fits are stored so that a repeat run takes seconds, and setting CLIMATE_FAST=1 runs the whole notebook with a few draws. Gabry and colleagues, Papaspiliopoulos and colleagues, Betancourt and Girolami, and Vehtari and colleagues were read by abstract only. The passages of Bayesian Data Analysis cited in Sections 6.3 and 7.2 were read in its free electronic edition. The other records were verified on Crossref and not read.
[1] J. G. Ibrahim, M.-H. Chen, and D. Sinha, Bayesian Survival Analysis. New York, NY, USA: Springer, 2001, doi: 10.1007/978-1-4757-3447-8; J. P. Klein and M. L. Moeschberger, Survival Analysis, 2nd ed. New York, NY, USA: Springer, 2003, doi: 10.1007/b97377; A. Gelman et al., Bayesian Data Analysis, 3rd ed. Boca Raton, FL, USA: CRC Press, 2013, doi: 10.1201/b16018; J. O. Berger, Statistical Decision Theory and Bayesian Analysis, 2nd ed. New York, NY, USA: Springer, 1985, doi: 10.1007/978-1-4757-4286-2. The records were verified on Crossref and the books were not read in this work, so they are cited as general texts for the method and no chapter or page is claimed.↩︎
[2] M. D. Hoffman and A. Gelman, “The No-U-Turn Sampler: Adaptively setting path lengths in Hamiltonian Monte Carlo,” J. Mach. Learn. Res., vol. 15, pp. 1593-1623, 2014.↩︎
[3] O. Papaspiliopoulos, G. O. Roberts, and M. Sköld, “A general framework for the parametrization of hierarchical models,” Stat. Sci., vol. 22, no. 1, pp. 59-73, 2007, doi: 10.1214/088342307000000014. The abstract describes “centering and noncentering methodology as complementary techniques for use in parametrization of broad classes of hierarchical models, with a view to the construction of effective MCMC algorithms.” M. Betancourt and M. Girolami, “Hamiltonian Monte Carlo for hierarchical models,” arXiv:1312.0906, 2013. Its abstract says that hierarchical models “introduce distinctive pathologies that quickly limit the efficiency of most common methods of inference.” Both were read by abstract only, so the text claims no more than that the parametrisation matters.↩︎
[4] A. Gelman et al., Bayesian Data Analysis, 3rd ed. Boca Raton, FL, USA: CRC Press, 2013, doi: 10.1201/b16018, Sec. 5.7: “the choice of ‘noninformative’ prior distribution can have a big effect on inferences, especially for problems where the number of groups J is small or the group-level variation τ is small.” A. Gelman, “Prior distributions for variance parameters in hierarchical models,” Bayesian Anal., vol. 1, no. 3, pp. 515-534, 2006, doi: 10.1214/06-BA117A. Its abstract suggests “a uniform prior on the hierarchical standard deviation, using the half- family when the number of groups is small and in other settings where a weakly informative prior is desired.” The book was read in its free electronic edition and the paper by abstract only. That the half-normal is the limit of the half- as its degrees of freedom grow is a property of the distribution and not a statement of the paper.↩︎
[5] A. Gelman, D. Simpson, and M. Betancourt, “The prior can often only be understood in the context of the likelihood,” Entropy, vol. 19, no. 10, Art. no. 555, 2017, doi: 10.3390/e19100555. The abstract places “the choice of prior into the context of the entire Bayesian analysis, from inference to prediction to model evaluation.” Read by abstract only.↩︎
[6] J. Gabry, D. Simpson, A. Vehtari, M. Betancourt, and A. Gelman, “Visualization in Bayesian workflow,” J. R. Stat. Soc. A, vol. 182, no. 2, pp. 389-402, 2019. Abstract read, not the full text; it states that visualisation is helpful at each stage of the workflow.↩︎
[7] A. Vehtari, A. Gelman, D. Simpson, B. Carpenter, and P.-C. Bürkner, “Rank-normalization, folding, and localization: An improved for assessing convergence of MCMC,” Bayesian Anal., vol. 16, no. 2, pp. 667-718, 2021, doi: 10.1214/20-BA1221. The abstract states that “traditional will fail to correctly diagnose convergence failures when the chain has a heavy tail or when the variance varies across the chains” and proposes a rank-based diagnostic. Read by abstract only. The values come from ArviZ, whose diagnostics table reports with bulk and tail effective sample sizes.↩︎
[8] A. Gelman et al., Bayesian Data Analysis, 3rd ed. Boca Raton, FL, USA: CRC Press, 2013, doi: 10.1201/b16018, Sec. 6.3: “If the model fits, then replicated data generated under the model should look similar to observed data.” Read in the free electronic edition of the book.↩︎
[9] A. Vehtari, A. Gelman, and J. Gabry, “Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC,” Stat. Comput., vol. 27, no. 5, pp. 1413-1432, 2017, doi: 10.1007/s11222-016-9696-4. The abstract describes LOO as “estimating pointwise out-of-sample prediction accuracy from a fitted Bayesian model,” computed with Pareto-smoothed importance sampling, and notes that the calculations also give “approximate standard errors for comparing of predictive errors between two models,” which is the difference and its standard error reported here. Read by abstract only. Cross-validation is also treated in A. Gelman et al., Bayesian Data Analysis, 3rd ed. Boca Raton, FL, USA: CRC Press, 2013, doi: 10.1201/b16018, Sec. 7.2, read in the free electronic edition of the book.↩︎
@online{faustine2026,
author = {Faustine, Anthony},
title = {When to {Plant:} {Bayesian} {Survival} {Regression} and the
{Planting} {Day}},
date = {2026-11-30},
url = {https://sambaiga.github.io/pages/blog/posts/2026/11/2026-11-30-survival-regression-for-planting.html},
langid = {en}
}