Show the code of the figure
show(lambda: plots.loss_curve(days, clim["curve"], clim))November 29, 2026
Series: Bayesian Modelling for Agriculture, Part 1. The earlier series, Bayesian Modelling for Industrial Applications, supplied the tools that this post applies to a new field.
A smallholder farmer in central Tanzania prepares the land in October and buys seed before the rains of November, but the day on which to plant depends on when the rains start. Planting too early risks a false start: the first rain falls, the seed is sown, the rain stops, and the seed, the fertiliser and the labour are lost and the field has to be sown again. Planting late costs a part of the growing season for every day of delay. The two mistakes are not equal, so the farmer needs more than an estimate of the day on which the rains will start. The farmer needs its distribution, and that is what a Bayesian analysis supplies. This post asks what a number that is known on 1 November, the state of the Indian Ocean Dipole, tells about that distribution.
The post is a worked example of a Bayesian analysis from the problem to the decision, and it is written so that the steps can be taken over to another problem. They are nine. State the decision and the loss that it carries. Name the quantity that the decision needs and what is hidden in its data. Choose a likelihood. State priors and check what they imply. Compute the posterior and check the computation. Check the model against the data. Expand it where the check fails. Turn the posterior into a prediction and choose the action of least expected loss. Test the whole on data that were not used. Each section below is one of these steps, with the theory that justifies it, and the last section restates them for another problem. The ninth step, the test, is the subject of the second post of the series.
The earlier series is reused throughout. Its first part introduced the updating of a prior by data, its second a regression with a likelihood and priors, its third partial pooling, the non-centred form and prior predictive checks, and its fourth a cell that had not yet failed as a censored Weibull lifetime. Forecast Value, Part 1 derived the cost-loss rule for an event. Three things are new. A season without an onset is censored in the same way as a cell that has not failed, but the censoring tells something about the season. The loss rewards waiting, so the rule is not a quantile. The regions of one season share the ocean, so they are not independent observations. The treatment follows the standard texts on Bayesian survival analysis, Bayesian data analysis and statistical decision theory.1
The answer is stated with its limits. 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, with a 90% interval 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, and the planting day of least expected loss moves from day 56 to day 70, with 44% of the probability beyond the end of the window in the second case.
The first step is the decision, because it fixes what the model has to supply. Let be the day of the onset, counted from 1 November as day 1, and the day on which the farmer plants. Planting before the onset is a false start and costs . Planting on or after it costs for each day of delay,
The farmer does not know , only its distribution given what is known, so the farmer minimises the expected loss. For an onset with distribution function and density the expected loss of planting on day is
Its derivative with respect to is , and the loss is least where it vanishes,
The planting day of least loss is where the ratio of the probability that the onset has come to the density with which it arrives equals the ratio of the cost of a false start to the cost of a day. It is not a quantile of the distribution. The cost-loss rule of Forecast Value, Part 1 and the rule for retiring a cell in Part 3 compare a probability with a ratio of costs, and they are quantile rules. Here a delay is paid for in days and a false start only once, so the shape of the distribution matters as well as a probability. For an exponential onset with rate the solution is , which the code of this post is tested against.
Two things follow. The decision needs the distribution of and not a date, and the ratio is an input that the farmer or an agronomist has to argue about. The example uses a false start that costs as much as 30 days of delay, which is an illustration and not an estimate. Figure 1 shows the expected loss for the climatology of the record, in which the 264 onsets of six regions in 44 seasons are treated as 264 draws and a season without an onset counts as later than every day.
The least loss, 21.1 days, falls on day 45, which is 1.5 days after the median onset of 43.5, and the days within 5% of it run from day 41 to day 47. Planting on the median day loses 21.5. The minimum is shallow, so any day in the band is nearly as good. The ratio matters more than the day. With a false start worth 10 days of delay the best day is 29, and with one worth 60 days it is 61, so a plan has to say which ratio it assumes. What a forecast can add is a better distribution for the coming season than the climatology of the record, and Bayesian regression is the way to build one from the dipole.
The second step names the quantity that the decision needs and what is hidden in its data. The quantity is the day of the onset. Its origin is 1 November, when the dipole index of August to October is known, so the forecast is issued on the day the window opens and its lead time is zero. Its horizon is the search window, 92 days from 1 November to 31 January, and its target is one onset day for each region and season. The record is therefore 44 observations for each region and not a daily series. The model below takes the seasons as exchangeable once the index is given, which is a regression assumption and not a time series model.
The onset is defined by a rule of the form that the agronomic literature uses for the start of the sowing season, for example in West Africa.2 The onset is the first day on which the rain of the day and the two before it reaches 20 mm and no run of 7 days with less than 5 mm follows in the next 21 days. A trigger that is followed by such a dry run is a false start of the rain and the search goes on. The constants are the general defaults of that literature and are not validated for Tanzania. A sensitivity run of the rule in the project notes, not repeated here, gave correlations between the onset day and the dipole from to over eight variants of the constants, and a number of seasons without an onset from 11 to 42, so the conclusions about the dipole survive a change of the rule and the count of failures does not.
The rainfall is the daily estimate of CHIRPS, which combines satellite observations with stations,3 averaged over six regions: Dodoma, Iringa, Mbeya, Njombe, Rukwa and Ruvuma. A season is kept when at least 90% of the days of its window are observed, which leaves 44 seasons from 1981 to 2025 for each region, 264 region-seasons in all, since December 2021 is missing at the source. The rule finds an onset in 241 of them. In the other 23 the rule did not fire before the window closed. These records are not missing: all that is known is that the onset lies beyond day 92. This is right censoring, exactly as in Part 4, where a cell that had not failed was known to outlast its test. Figure 2 shows the onsets and the censored seasons.
The mean onset of the seasons that have one runs from day 30 at Rukwa to day 52 at Dodoma, with standard deviations from 15 to 20 days, and the onsets of all the regions have 5%, 50% and 95% quantiles at days 17, 42 and 75. The late and missing onsets are not spread evenly. Dodoma has 15 seasons of 44 without an onset, Iringa has 6, Mbeya and Ruvuma have 1 each, and Njombe and Rukwa have none. The onset defined by the rule is observed, but it is a convention that stands for the agronomic onset, the first day on which planting would establish a crop, which nobody observes in this record. No gauge or farmer record of the onset exists here, so the rule cannot be validated, and the decision below is a decision about the rule’s onset.
The Indian Ocean Dipole is a pattern of sea surface temperature in which the western Indian Ocean is warmer than the eastern in one phase and cooler in the other.4 The Dipole Mode Index, published by the NOAA Physical Sciences Laboratory, measures the difference. The predictor is its average over August, September and October, the latest window that is complete before the window of the onset opens, so the index is known when the forecast is made. A window that included November would leak the season into its own prediction. Figure 3 shows the mechanism that makes the index a candidate: a warm west draws moisture towards East Africa, and a cool west does the reverse. A coupled model study of the East African short rains reports an influence of the dipole that is overwhelming compared with that of El Niño.5 That season runs from October to December and the rains here fall from November, so the mechanism is a hypothesis that the data have to support.
Figure 4 shows the onset against the index for each region. The onset day falls as the index rises in all six regions, with correlations of at Iringa, at Njombe, at Dodoma, at Mbeya, at Ruvuma and at Rukwa, computed from the seasons that have an onset. The correlation of the mean onset of the regions with the index over the 44 seasons is . The correlation with El Niño is weaker in each region, between and , and for the 44 seasons, so the dipole is the predictor used. The orange points show what a correlation of the confirmed onsets alone would hide. The seasons without an onset lie at low values of the index, mostly in the panel of Dodoma, and their mean index at Dodoma is against in the seasons that have an onset. The late seasons are the ones in which the dipole is low, so dropping them removes evidence for the effect and not noise.
The third step is to say how the data arise, and Bayes’ theorem says what to do with the answer. Let stand for the parameters of a model and for the record, which consists of a time , an indicator that is 1 when the onset was seen and 0 when it was censored, and an index for each of the 264 records. The posterior is
The likelihood of an onset is the density of the time, and the likelihood of a censored season is the probability that the time is later than the end of the window, which is the survival function . With independent records the likelihood is the product
where and are the density and the survival function of the time of record given and .
A season without an onset therefore counts for what it tells, that the time exceeds 92 days, and not as a missing value or as an onset on day 92. The prediction for a new season with index averages over the posterior, and the decision of the first section averages the loss over that prediction,
This is the chain of Bayesian decision theory: 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. Neither the posterior nor the integral has a closed form for the censored model below, so PyMC draws from the posterior with the No-U-Turn sampler6 and every integral becomes an average over draws. The sections that follow take the steps in order.
The time to the onset is Weibull. Its survival function is with shape and scale , the form that Part 4 used for the life of a cell. The shape says whether the chance of an onset rises with the days of waiting, and the scale sets the typical day. 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 term is one standard normal effect for each season that all its regions share, with scale , and it carries the dependence between regions that the data show. The slopes of the regions are drawn around a common slope with a spread , in the non-centred form of Part 3,
Here each is standard normal. The levels are drawn in the same way around a common level. This is partial pooling in the sense of the earlier post: a region with a short or scattered record borrows strength from the others, and 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 then looks at what the priors imply. The common slope has the physical prior . Its sign is negative because the mechanism says that a positive dipole brings the rains earlier, and its size is modest, a change of 14% in the median onset for one standard deviation, with room for none and for a strong effect. Its 5%, 50% and 95% quantiles are a change of , and , and the probability of a negative slope is 0.84. A weak prior, , serves as the comparison. It has no sign and its quantiles are , and . The other parameters take weak priors: a log-normal prior for the shape centred on 2.5, a normal prior for the log of the level of the scale centred on 40 days, and half-normal priors for the spreads and for .
A prior predictive check shows what such priors imply for the quantity of interest.7 The onset of a season of average index has 5%, 50% and 95% quantiles at days 7, 33 and 110 under the priors, and 8.3% of the draws 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 5 draws the two priors of the slope with the least squares slope of each region, which uses the seasons with an onset only and is 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 chains agree when , a measure of their disagreement, is close to one, and the effective sample size says how many independent draws the correlated ones are worth. A divergent transition warns that the sampler left a region that it could not explore. The six fits of this post have no divergent transitions, the largest is 1.009 and the smallest bulk effective sample size is 800.
The posterior is then read. The common slope has a median of with a 90% interval from to , which is a median onset 17% earlier for each standard deviation of the index, and the probability that the slope is negative is above 0.9999. Averaged over the regions the median onset moves by days, with an interval from to days. The weak prior gives the same, with an interval from to . With 264 records the data overrule both priors. Unlike the normal regression with known noise of the earlier posts, this model has no closed-form posterior 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. Figure 6 compares the three. Dropping the 23 seasons gives a slope of , a change of days, and 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 the record of Dodoma, with 34% of its seasons censored, is where the handling would be expected to matter most.
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 model that ignores this reports a precision that the data do not contain, so the shared season effect is added. Its scale has a 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 the log onset times of , which 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 7 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. A bootstrap that resamples whole seasons and refits by maximum likelihood gives with an interval from to , between the two, and the estimate agrees with the posterior median. The shape of the Weibull rises from 2.59 to 3.73 when the season effect is added, because the effect absorbs the variation between seasons and leaves the spread within a season to the shape. The model with the season effect is used for the predictions below, because its uncertainty matches the number of seasons and not the number of records.
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, so the six regions share one slope to a good approximation. Figure 8 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, so the first check simulates the data from the fitted model with the season effect and counts the seasons without an onset in each region. The simulation draws a season effect for each of the 44 seasons. Figure 9 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, and Iringa has 6 against 3 with a range from 1 to 8. The observed counts lie on the upper side of the bars in these two regions, where the record has somewhat more late seasons than the model’s most likely count, and in the bulk of the bars in the other four, which have 0 or 1. The model gives the observed count a probability of 0.07 at Dodoma, 0.08 at Iringa, 0.32 at Mbeya, 0.24 at Njombe, 0.83 at Rukwa and 0.25 at Ruvuma, and all six counts lie inside their 90% ranges.
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, and 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, which scores how well each model predicts a record that it has not seen, 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, and the common slope is with an interval from to . The simpler model is kept. A check that passes does not prove a model. The records constrain the Weibull only up to day 92, and 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, and Figure 10 draws it for a dipole one standard deviation above the mean index and one below, which are values that 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.
Figure 11 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, and 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 the value of knowing the dipole for the planting date.
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, and the honest advice is to wait for the rain and to plant when it has proved itself. That is the in-season problem of the third post. These results describe what the fitted model believes about the seasons that it was fitted to. They do not say how well it predicts, which the second post tests on seasons that it has not seen.
The steps of this post apply to any problem in which a decision depends on an uncertain quantity that is observed with gaps. The questions at each step are the ones to ask of another problem.
In PyMC the likelihood of a censored record is pm.Censored, partial pooling is a vector of offsets drawn around a common value, and a check by simulation is a draw from the posterior predictive. The functions of this post are in the bayes.climate package of the repository, with tests, 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 uses the onset of the rule as the quantity to be predicted and not the agronomic onset, which the third post approaches by filtering the daily rainfall.
The planting decision fixed what the analysis had to supply, the distribution of the onset day, because the optimum compares the probability that the onset has come with the density with which it arrives and not only a probability. The onset was treated as a time to event, with the 23 seasons without one censored at the end of the window. A Weibull regression on the dipole gave a slope of on the log scale, a median onset 17% earlier for each standard deviation of the index and about 8 days earlier on average, with an interval of 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 it 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, and in the second case 44% of the probability lies beyond the window, so the advice is to wait for the rain. The second post of the series 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 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 onset rule reproduces, season by season, the detector of the project from which the question came. The fits are stored so that a repeat run takes seconds, and setting CLIMATE_FAST=1 runs the whole notebook with a few draws. Behera and colleagues and Gabry and colleagues were read by abstract only, and 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. V. K. Sivakumar, “Predicting rainy season potential from the onset of rains in Southern Sahelian and Sudanian climatic zones of West Africa,” Agric. For. Meteorol., vol. 42, no. 4, pp. 295-305, 1988; R. Marteau, B. Sultan, and V. Moron, “The onset of the rainy season and farmers’ sowing strategy for pearl millet cultivation in Southwest Niger,” Agric. For. Meteorol., vol. 151, no. 10, pp. 1356-1369, 2011. The records were verified on Crossref and the papers were not read, so they are cited for their subject, the onset of the rains and sowing, and not for any constant of the rule.↩︎
[3] C. Funk et al., “The climate hazards infrared precipitation with stations: a new environmental record for monitoring extremes,” Sci. Data, vol. 2, Art. no. 150066, 2015. The record was verified on Crossref and the paper was not read, so its description of the product is not repeated here. The product was validated against gauges over eastern Africa by T. Dinku, C. Funk, and P. Peterson, Q. J. R. Meteorol. Soc., vol. 144, no. S1, pp. 292-312, 2018, doi: 10.1002/qj.3244, whose abstract was read in an earlier session and not in this one.↩︎
[4] N. H. Saji, B. N. Goswami, P. N. Vinayachandran, and T. Yamagata, “A dipole mode in the tropical Indian Ocean,” Nature, vol. 401, pp. 360-363, 1999. The record was verified on Crossref and the paper was not read; it is cited for the name of the pattern.↩︎
[5] S. K. Behera et al., “Paramount impact of the Indian Ocean dipole on the East African short rains: A CGCM study,” J. Clim., vol. 18, no. 21, pp. 4514-4530, 2005. Abstract read, not the full text. The study is a coupled model experiment, so it measures a mechanism in a model and not a correlation in observations.↩︎
[6] 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.↩︎
[7] 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.↩︎
@online{faustine2026,
author = {Faustine, Anthony},
title = {When to {Plant:} {Bayesian} {Survival} {Regression} for the
{Onset} of the {Rains}},
date = {2026-11-29},
url = {https://sambaiga.github.io/pages/blog/posts/2026/11/2026-11-29-onset-of-the-rains.html},
langid = {en}
}