Introduction

Coffee is one of the world’s most popular beverages, serving as a vital economic crop in many developing countries and contributing significantly to local livelihoods and economies1,2,3. Variations in temperature, precipitation, and other climatic factors can significantly affect coffee growth, yield, and quality4. These impacts would severely affect smallholder farmers in developing countries, who contribute approximately 60% of the global coffee supply5, and often lack access to advanced farming techniques and financial instruments. Climate change is projected to alter the frequency and intensity of climate extremes6,7,8,9, by imposing stronger heat stress or greater precipitation variability. In response, a geographical shift in coffee growth to higher latitude or altitude areas has been proposed to alleviate future heat stress10,11. However, this shift could bring about other challenges such as increased chill stress12,13. Quantifying the response of coffee yield to various types of climate stressors would, therefore, provide a cornerstone for evaluating future climate impacts on coffee production in various geographical regions.

Arabica coffee has strict climate requirements for growth. It prefers a cool, moist, and (semi-) shaded environment14. The ideal growth temperature ranges from 16 to 24 °C15, and the optimal annual precipitation is 1200–1800 mm16. Coffee growth and yield responses to various types of climate stressors have been well documented through field observations and experimental approaches. Coffee is most sensitive to drought in its vegetative and berry development stages, where even mild drought conditions can lead to reduced photosynthetic rates, decreased biomass, and lower yields2,17. In some non-irrigated areas, extreme droughts can result in yield reductions of up to 80%18. Excessively high temperatures can lead to reduced photosynthesis, leaf scorching, wilting, and increased susceptibility to diseases and pests19. Prolonged exposure to low temperatures can inhibit the growth of coffee plants20,21. Coffee trees grown at higher altitudes may experience fewer pest and disease issues but are more vulnerable to low temperatures due to prolonged development periods12. Coffee is also sensitive to intense sunlight, which can elevate leaf temperature and increase susceptibility to scorch disease14.

The existing literature has developed various models to quantify coffee yield response to climate factors, either to identify key climate factors and their thresholds that critically affect coffee yield or to provide coffee yield prediction/forecasts. Based on the global historical coffee yield dataset documented by the Food and Agricultural Organization of the United Nations, Kath et al.8 revealed the non-linear impact of heat and drought stresses on the national yield of Arabica coffee using generalized additive models (GAMs). Their results suggest that abrupt yield shortfall could occur beyond a growing-season maximum temperature of 29.22 °C and vapor pressure deficit (VPD) of 0.82 kPa. Focusing on Robusta coffee, the hierarchical Bayesian method helped reveal the Robusta coffee yield response to climate variables based on farm-level survey data from Southeast Asia22. Their results confirmed the negative effects of high temperatures and excessive rainfall during the flowering stage. Aiming at yield prediction, Kouadio et al.23 quantified the relationship between farm-level surveyed yields and various agricultural meteorological indicators using an adaptive random forest model. Similar studies have been conducted on coffee production in Brazil18. However, these studies have primarily focused on specific regions or types of climate stressors, mostly for the traditional grown areas within the Tropics, and therefore lack comprehensive quantification of complex climate stresses within marginal growing areas. Consequently, existing quantitative relationships remain limited in terms of region, scale, and hazard type to meet the needs of loss risk assessment and climate change impact projection.

Here we aim at enriching knowledge on coffee yield response to climate stressors, with a special focus on a growing area to the northmost margin of the global coffee belt, Yunnan, southwestern China. Yunnan is China’s primary region for coffee cultivation and export, producing 143,200 tons of coffee beans in 2022, accounting for more than 98% of the total production of China and 1.36% of the global production. Yunnan coffee is mostly harvested between 21° and 26° N, placing it within a marginal cultivation zone with distinct vertical climatic characteristics24. Its high latitude and altitude contribute to the distinctive attributes of local coffee beans25, but it is also prone to chill and drought damage26,27,28. In 2017, frost damaged 10,000 ha of coffee (9.03% of the total harvest area in Yunnan), resulting in estimated losses of approximately US$10 million. Similarly, in 2019, drought led to damage in approximately 40,000 ha (38.3% of the total harvest area), resulting in losses of around US$ 46 million. Therefore, Yunnan’s coffee production is unique worldwide in terms of the combination of climate stressors, which offers us the opportunity to further investigate coffee yield responses to climatic stressors.

In this study, we analyze the response of Yunnan Arabica coffee production to climate stressors during key growth periods and quantify the relative contribution of each key climate stress to coffee yield in historical periods. We use site-specific climate data and statistical coffee yield data of the major coffee-producing counties in Yunnan Province, covering more than 90% of Yunnan’s production and more than 80% of China’s. We perform a full permutation of 13 climatic predictors in three growth stages and use them to fit GAMs to explain yield variation. Predictors with the highest frequency of significant performance in the fits then help identify critical growth stages and corresponding climate stressors that affect coffee yield the most. Then, we select the best-performing GAM to quantify how Yunnan’s coffee yield responds to those key climatic stressors. Finally, based on the response curves and historical climate, we evaluate the relative contribution of key climatic stressors to historical yield losses.

Results

Critical climate stressors and growth stages that impact on coffee yield

We divide climate factors into four groups, (basic factors, drought stress, chill stress, and heat stress) and use the full combination of predictors (one from each group every time and avoiding highly correlated predictors) to fit a suite of competing GAMs to identify the key growth periods and key climate stressors that affect yield. In total, 18,679 GAM models are fit. By using the AIC and \({R}_{adjusted}^{2}\) metrics, the top 2% best performing models are selected. All four groups have predictors that have relatively higher frequency of appearance in the models (Fig. 1).

Fig. 1: The frequency of occurrence of each predictor in the top 2% best performing GAMs.
figure 1

the horizontal axis represents various climate indicators, and the vertical axis represents three typical growth periods. the darker the color of the corresponding grid, the higher the frequency of occurrence in the selected model.

Our results show that climate stressors can be more directly linked to interannual fluctuations in coffee yield in Yunnan than basic climatic factors. For drought stress, standardized precipitation index (SPI; quantifies precipitation anomalies relative to long-term averages) shows a slightly higher frequency of inclusion than vapor pressure deficit (VPD; atmospheric dryness measured by vapor pressure gap) and standardized precipitation evapotranspiration index (SPEI, integrates precipitation and evapotranspiration for water balance assessment.), and the flowering stage (fl) is identified as the most critical stage. For chill stress, minimum of daily minimum air temperature (TNn) and cold degree days (CDD; cumulative cold stress) have a much higher frequency of inclusion than mean daily minimum air temperature (Tmin), and the maturity stage (mt) is reported to be critical for the chill stress impact. For heat stress, all three predictors show some importance, and the flowering stage is suggested to be the critical stage rather than the fruit-sitting stage (fs) when the annual maximum temperature appeared. However, when compared to drought and chill stress, the frequency of inclusion of heat stress predictors, including mean daily maximum air temperature (Tmax), maximum daily maximum air temperature (TXx), and heat degree days (HDD; cumulative heat stress) may be relatively minor (the frequency of inclusion is low), although it is still a critical factor to consider in understanding the overall climatic influences on coffee yield.

Yield response to critical climate stressors

Following Fig. 1, we carefully select three sets of predictors that representing drought stress for the flowering stage, chill stress for the fruit-sitting stage, and heat stress for the flowering stage. We consider TNn and CDD for chill stress and Tmax and HDD for heat stress. For drought stress, we initially consider SPI and SPEI. Nevertheless, model fits consistently derived “U”-shaped response curves with respect to SPI. Consequently, we use VPD instead of SPI in light of the performance of VPD highlighted in Kath et al.8, and the results are promising.

After controlling for highly correlated predictors, that is, Tmaxfl and CDDmt, and carefully investigating the response curves, we focus on six models (Table 1). In our results, VPD is slightly superior to SPEI in capturing yield responses to drought stress, which is in agreement with the findings reported by Kath et al.22. In contrast, SPEI consistently derive a nearly flat response curve, which is insignificant. TNn and CDD consistently demonstrate a significant impact of chill stress on coffee yields. Regarding heat stress, Tmax and HDD exhibited comparable capabilities, with Tmax marginally outperforming HDD. Nevertheless, for most models, neither Tmax nor HDD significantly explained the variation in yield. This insignificance may have stemmed from the fact that in Yunnan Province, the duration of the growing season that reaches the high temperature threshold of 30 °C is relatively short, and the effect of heat stress detected from historical data is quite subtle and contains large uncertainty.

Table 1 Summary of the selected promising models

After careful consideration, we select the model depicted in Fig. 2 as our primary model, with additional outcomes included in the Supplementary Materials (Supplementary Figs. 2-6). Our results revealed a pronounced negative effect of drought on coffee yield during the flowering stage. The monotonic decrease in the response curve indicates that a higher VPD will lead to greater negative impacts on coffee yield. On average, coffee yield dropped by about 4.0% for each 0.1 kPa increase in VPD. For chill stress, as TNn during the maturity stage decreased, there was a clear monotonic drop in yield, and the slope is equivalent to about 18.9% coffee yield loss per 1 °C decrease in TNn. Additionally, the yield drop associated with TNn is the largest among the three stress predictors. Heat stress, represented by Tmax, has a monotonically negative impact on the coffee yield. However, the impact is not significant, possibly because of an insufficient sample size of high temperature in Yunnan, and there is a slight uptick at the tail end of this response curve.

Fig. 2: Response curves of Arabica coffee yield to major predictors in Yunnan.
figure 2

The solid black line represents the average effect, while the shading indicates 95% confidence intervals. Points are partial residuals. a year, representing the increase in yield brought about by technological progress. b Multi-year average of VPDfl. c Multi-year average of TNnmt (°C). d Multi-year average of Tmaxfl (°C).

Contribution of historical climate stressors to coffee yield loss

To better understand the relative contribution of each climate stressor to the historical yield loss, we mapped the spatial distribution of each stressor. For each stressor, the two predictors listed in Table 1 are mapped by taking their multi-annual average values during the historical period (1992–2022). For SPEI, we use its average below -1, following29, owing to its standardized values. Climatic stressors exhibited pronounced spatial differences (Fig. 3). Drought stress, represented by VPDfl (Fig. 3a), is much stronger in the central part of the growing regions than in other regions, mostly in Lincang and western Pu’er. For some counties, the multi-annual average VPDfl can reach 1.1 kPa, and in extreme years, its value can reach 1.72 kPa. However, the drought pattern reflected by SPEIfl differed from that reflected by VPDfl. Drought stress denoted by SPEIfl is mainly concentrated in the southwest and northeast of the study area, with an average SPEI of -1.46 in drought years (SPEI < −1), and it can reach −2.62 in extremely dry conditions.

Fig. 3: Spatial distribution of climate stressors identify from the model.
figure 3

a Multi-year average of VPDfl. b Multi-year average of SPEIfl < −1. c Multi-year average of TNnmt (°C). d Multi-year average of CDDmt (°C·day). e Multi-year average of Tmaxfl (°C). f Multi-year average of HDDfl (°C·day).

The spatial distribution pattern of chill stress is highly consistent when TNnmt and CDDmt are used (Fig. 3c, d). The strength of the chill stress exhibited a descending gradient from the northwest to the southeast, with Baoshan along the Salween River valley suffering the most. The annual average TNn of the maturity period can reach −2.5 °C, and in extreme years, the value can be −4.5 °C. As for CDDmt, The multi-annual average value in the study area is approximately 136 °C·day, and the maximum value reached 449 °C·day.

The spatial pattern of heat stress is also consistent between Tmaxfl (Fig. 3e) and HDDfl (Fig. 3f). In contrast to chill stress, heat stress is the most threatening in the southeastern corner of the study area, especially in Xishuangbanna. The threat in counties at the junction of Lincang and Pu’er is also high. Among them, the multi-annual average Tmax of the flowering stage is 28 °C, and it can reach 35.1 °C in extreme years. The multi-annual average HDDfl in the study area is approximately 13 °C· d, and the maximum value reached 138 °C· d.

We map the multi-year average relative contribution to historical loss of different climate stressors by county 1990 to 2022 (for the details of computing relative contributions, please refer to the method section). Historical coffee yield loss associated with stressors is more pronounced in northwestern counties (Fig. 4). The summation of the single-stressor-associated yield loss is greater than 50%, with 15 out of the 29 counties, mostly in Dehong, Baoshan, and Lincang. Note that the summation of the loss rate is different from the actual relative yield loss rate because the positive yield effect of other favorable climate factors is not considered. Regarding the relative contribution (RC) of climate stressors, chill stress exerted the largest RC, followed by drought stress, and the RC from heat stress is the least (Fig. 4). Eighteen out of the 29 counties have a relatively larger RC from chill stress (>40%), including those in Baoshan, central Dehong, central Lincang, and southeastern Pu’er. A relatively high RC (>40%) from drought stress only appeared in six counties, two each in Pu’er and Lincang, and one each in Dehong and Xishuangbanna. RCs for heat stress are high in only a few counties, including Ruili County in southwestern Dehong, Menglian County in southwestern Pu’er, and Mengla County in the southernmost Xishuangbanna (which is also the most severely affected by heat stress).

Fig. 4: Combined coffee yield loss rates and the relative contribution of climate stressors at the county-level.
figure 4

Orange Sector: relative size of yield reduction due to drought stress among losses from three stresses. Blue sector: relative size of yield reduction due to chill stress. Red sector: relative size of yield reduction due to heat stress. Sector size represents absolute size of total loss from three stresses.

We also plotted the trends in the losses of coffee yield loss rate caused by different climate stressors in each county from 1990 to 2022 (Fig. 5). The trend was obtained by regressing yield loss rate associated to each stress on year. We found that, overall, yield loss rate caused by drought and heat mainly showed an upward trend, while the yield loss rate caused by chill mainly showed a downward trend. Among all 29 counties, the yield loss rate induced by flowering-stage drought showed an increasing trend in 87.10% of the counties, with 58.06% of them statistically significant (p < 0.05). For yield loss caused by flowering-stage heat stress, 51.61% of the counties exhibited increasing trend, but only 22.58% were statistically significant (p < 0.05).

Fig. 5: Trends in yield loss rate associated with each climate stressor.
figure 5

The orange bar: The variation range of the yield loss rate caused by drought stress. The blue bar: The variation range of the yield loss rate due to chill stress. The red bar: The variation range of the yield loss rate due to heat stress.

Discussion

In this study, we identify the critical growth stages and climate stressors that can best explain the yield loss of Arabica coffee in Yunnan, China, by mobilizing GAMs analysis of historical county-level yield and climate data. Most importantly, our results add new knowledge regarding the significant impact of chill stress, which has been under-addressed in previous statistical analyses. We find that chill stress is the primary contributor to coffee yield loss in Yunnan during the period of 1992–2022, followed by drought stress, with heat stress having the least impact. This can be attributed to Yunnan’s marginal climate suitability for coffee cultivation, which is situated at the northern border of the tropics. The annual minimum temperature for some counties can reach as low as −2.59 °C, which is significantly different from the tropical plateaus of major coffee-producing regions. However, this latitudinal position and climate also mitigated a considerable portion of the risk associated with heat stress, as our data only suggested high relative contributions of heat stress in 10.34% of counties.

Our results indicate that chill stress in the maturity stage and drought stress in the flowering stage are the key climate stressors and critical growth stages. Our fitting of the GAMs indicated that the impact of chill stress can be comparably denoted by both TNn and CDD, showing a monotonic relationship with the natural logarithm of coffee yield. Both TNn and CDD are widely recognized metrics for quantifying crop exposure to chill stress30,31. There is subtle difference between the two indicators. TNn can capture extreme minimum temperature values, monitoring abrupt cold damage events such as frost. CDD focuses on the cumulative effects of low temperatures, quantifying the comprehensive impacts of continuous cold exposure. In Yunnan, massive damage to coffee yield was mostly due to frost weather that had produced “frozen fruits”. In this occasion, TNn should a better reflection of chill damage to coffee as a measure of sudden extreme low temperature.

We tried to compare our quantitative response curve with existing studies, but there is a lack of evidence from other regions around the world. Only a few experimental studies have mentioned that temperatures below 18 °C may inhibit the growth and photosynthesis of coffee20,21,32. But our finding is well supported by Yunnan’s local knowledge. According to the local standards in Yunnan Province33, when the daily minimum temperature is below 1.0 °C or when the daily average temperature is below 8.0 °C, Arabica coffee will be subject to chill stress. In the study of chill damage to other crops.

The impact of drought stress can be best represented by VPD during the flowering stage. The natural logarithm of yield dropped from 0.25 to −0.63 monotonically in response to VPD’s increase from 0.31 to 1.71 kPa. This relationship generally agreed with the one derived based on FAO’s national Arabica coffee yield8. They found VPD a key indicator of global coffee productivity, and there had been an abrupt change point of damage (VPD > 0.82 kPa), beyond which coffee yield declined even more rapidly. As for the selection of predictor, our results suggest that the VPD performs better than SPEI. VPD is a measure of air dryness that incorporates temperature and humidity and reflects the driving force behind plant transpiration. During the flowering period, even without soil drought, an increase in VPD can lead to severe hydraulic dysfunction in trees34, resulting in water stress that affects pollen vitality and transport, leading to pollination failure, and ultimately reducing coffee bean formation and yield. Previous studies have also used precipitation35 and SPEI36 to denote drought stress in coffee. SPEI is frequently used as an alternative indicator of soil moisture-based drought indices in its role as a meteorological drought index37. Such a localized relative measure might not exactly denote the physiological stress imposed on coffee plants, which can instead be managed by VPD, which may be the reason why VPD performs better than SPEI here.

Our results find weak evidence of heat stress impact, for which earlier studies believed it to be the largest threat to coffee yield38, particularly under a warming climate39. Relatively high temperatures during the flowering stage, especially if prolonged in the early seasons, can frequently lead to abnormal flower development and even completely inhibit flowering when sudden and severe6. Air temperatures greater than 30 °C can result in deficient floral development and a large number of flower abortions40, and temperatures greater than 35 °C inhibit germination41. The subtle relationship between coffee yield and Tmax in our case is mainly due to Yunnan’s unique tropical and subtropical plateau monsoon climate, as its temperature rarely exceeded the heat stress thresholds suggested in the literature. In our data records, only 27% of the samples have a Tmax greater than the threshold of 30 °C. Consequently, our results regarding heat stress are not robust. As future climate change can bring more frequent and intensive heat stress to Yunnan42, the projection of future heat stress on coffee yield will therefore require further extension of the analysis regarding heat stress impacts.

Our study shows clear regional variations in the RC, with the northwestern area being predominantly affected by chill stress, the central area by drought stress, and the southeastern area by heat stress. This distribution corresponds to the regional climate and terrain variations in southwestern Yunnan. In the northwest part (Baoshan and Dehong), the high-elevation Gaoligong Mountains (average altitude >1500 m) create cool summers with sporadic winter frosts, maintaining relatively low mean annual temperatures. Additionally, the areas of Baoshan and Dehong have been used for the cultivation of high-altitude (1200–2000 m) speciality coffee, which can have correspondingly increased the risk of chill damage43. The central region (Puer and Lincang), characterized by lower-elevation hills and montane monsoon climate, demonstrates pronounced vertical climatic zonation and distinct wet-dry seasonality. Persistent cloudless conditions during winter, driven by dry warm westerly airflows, exacerbate atmospheric aridity and soil moisture deficits, resulting in severe winter-spring droughts. Elevated surface temperatures coupled with reduced humidity amplify VPD44, making drought more likely to occur. In contrast, the southeastern low-altitude zone (<1000 m) (Xishuangbanna) exhibits tropical monsoon climate with homogeneous thermal conditions (mean annual temperature: 18–22 °C) and absence of distinct seasons. However, the dry season precipitation in this region is more abundant than in parts of the central areas such as Pu’er and Lincang45, thus the risk of drought is not as high.

This study has several limitations. The lack of farm-level yield data led to the choice of modeling at the county level, which ignored the divergent production conditions in local places (hilly regions with micro-climate)—the relationship between regional aggregated variables may not apply to farm-level variation. Our limited county-level data size also constrained the analysis of the impact of other minor stressors such as excessive rainfall and compound climate extremes. Although our results enrich the knowledge of coffee yield to chill stress, in addition to drought stress, the derived yield response to heat stress is subject to large uncertainty. Therefore, the response relationship regarding heat stress must be used with caution when applied to loss risk assessments and climate change impact projections.

Our analysis can explicitly provide important information to support Yunnan’s initiatives in improving disaster prevention infrastructure for the protection of coffee yields. According to our results, chill stress remains the dominant cause of coffee yield loss in Yunnan. To cope with this, early warnings and forecasts of frost and low-temperature stress would help local farmers prepare in advance, even if it’s just 12 h ahead. Farmers can reduce losses through measures such as proper covering and smoking. Drought stress has been the second largest source of yield loss for coffee in Yunnan, and its impact has been increasing. An immediate and effective measure is to provide irrigation facilities. Currently, nearly 95% of the coffee plots are completely reliant on rainfall, and they are actually located on the hilly slopes at altitudes ranging from 800 to 2000 m above sea level. In the face of the continuously rising risk of heat stress, it is recommended to increase the coverage rate of shade trees, whose effectiveness in successfully regulating the microclimate within the coffee agroforestry system has been proven46. In fact, the Yunnan provincial government has been advocating the use of shade trees since 201247, and demonstrative projects have been launched. Currently, the adoption rate of shade trees in Yunnan is approximately 30–40%, a proportion that still needs to be improved.

Methods

Data

Our study focuses on the major Arabica coffee production counties in China (Supplementary Fig. 1), southwestern Yunnan Province, which spans approximately 21° to 26° N and 97° to 102° E. In 2020, this region had a harvest area of approximately 100,000 ha, contributing more than 99% of the total coffee plantation area in China, accounting for 1% of the global total coffee plantation area. The predominant Arabica coffee variety cultivated in this region is Catimor7963, a hybrid of the “Caturra” and “Timor” varieties, occupying approximately 90% of the total planting area48. The unique combination of altitude, rainfall, and temperature creates a suitable environment for coffee cultivation but also increases the production risk for coffee growers in the region26,27.

County-level coffee production data for Yunnan Province from 1992 to 2022 are collected from Provincial and Prefectural agricultural yearbooks and statistical yearbooks (available at the official website of the Yunnan Provincial Bureau of Statistics, https://stats.yn.gov.cn/). The data collected encompassed the annual coffee production, coffee cultivation area, and coffee harvesting area for each county. We focus on 29 primary coffee-producing counties, which together accounted for over 90% of Yunnan Province’s total coffee production. To ensure the accuracy and reliability of our analysis, we removed outliers that exceeded three standard deviations from the mean. This resulted in a final dataset that contained 377 valid coffee yield records.

Climate data from 29 meteorological stations, one for each county, are obtained from the Yunnan Provincial Climate Center, covering the period of 1991-2022. The dataset includes the station-observed daily mean, maximum, and minimum air temperatures, sunshine hours, precipitation, and relative humidity.

Climate predictors for modeling coffee yield response

The selection of potential predictors employed a comprehensive approach that integrated field surveys, expert consultations, and a thorough review of existing literature. The process suggested that drought and chills are the top climate-related risks to coffee production, followed by relatively minor threats from high temperatures, hail, and strong winds. Accordingly, a list of potential predictors is prepared to quantify coffee yield response to climate stressors (Table 2). We have eight temperature predictors, four precipitation predictors, and one solar radiation predictor. For temperature, we considered positive heat accumulation, chill stress, and heat stress. For heat accumulation, we use growing-degree-days (GDD) and mean daily average temperature (Tm). For chill stress, we used mean daily minimum temperature (Tmin), minimum of daily mean temperature (TNn), and cold degree days (CDD). For heat stress, we considered mean daily maximum temperature, (Tmax), maximum daily maximum temperature (TXx), and heat degree days (HDD). For precipitation, P and three drought predictors, including vapor pressure deficit (VPD), standardized precipitation index (SPI), and standardized precipitation evapotranspiration index (SPEI) are considered. For solar radiation, we use the total sunshine hours (SH).

Table 2 Climate predictors used for modeling coffee yield response

For each predictor, we considered the values for the three growth stages. The division of growth stages is based on the physiological characteristics of the different phenological stages of coffee growth and the advice of local agricultural and meteorological experts: flowering stage (fl) from March to May, fruit-sitting stage (fs) from June to October, and maturity stage (mt) from November to February of the following year. Some predictors are believed to cause little damage to coffee during certain growth stages, such as heat stress in winter. These factors are included at the beginning but are eventually filtered out in subsequent model-fitting iterations.

Model

GAMs are employed as the primary model to derive the yield response curves. GAMs allow for the use of smooth functions instead of linear terms, enabling the modeling of complex relationships between variables49. This approach is particularly advantageous when dealing with the nonlinearities often observed in ecological and environmental data50. The model equation used in this study is:

$${\mathrm{ln}}({y}_{it})={\beta }_{0}+s(t)+\mathop{\sum }\limits_{k=1}^{K}s({x}_{k,it})+{\varepsilon }_{{\rm{it}}}$$
(1)

Our model formulation considered the natural logarithm of coffee yield (\({y}_{it}\)) for county (i) and year (t) as a linear combination of splines for the chosen predictors \({x}_{k}\). The spline functions \(s({x}_{k,it})\) are employed to accommodate potential nonlinear effects, while \(s(t)\) represented a time trend term to account for technological advancements that may have contributed to increased coffee production. The model’s residual error, \({\varepsilon }_{it}\), is included to capture any unexplained variance. \({\beta }_{0}\) is a constant in this model.

Predictor and model selection

We employed a strategy that involved fitting a suite of competing models with various combinations of predictor variables to navigate the challenge of predictor selection51. Prior to model fitting, Pearson correlation analyses are conducted to evaluate the relationships between all predictors. Predictors with high correlations (|p | ≥ 0.6) are not simultaneously included in the model fitting to mitigate multicollinearity52. Subsequently, we randomly select four climate factors with correlation coefficients |p | < 0.6, besides the year term, to construct a GAM. We then explored all possible combinations of models and compared them using goodness-of-fit metrics. We employed the generalized cross-validation method53 to extract as much useful information as possible from the limited data while minimizing overfitting. Model performance is assessed using the Akaike Information Criterion (AIC)54 and adjusted R-squared (\({R}_{adjusted}^{2}\); Wood, 55). The top 2% of the models with the highest \({R}_{adjusted}^{2}\) are retained, from which the frequency of each predictor is summarized. Based on the frequency counts, we identify the critical predictors and growth stages that have the greatest influence on coffee yield.

The derivation of the final model is contingent upon a comprehensive evaluation of model-fitting statistics and the statistical significance of the predictors. We select the top two predictors for each type of stress (chill, drought, and heat) with the highest frequency in the previous step and then fit the model with all possible combinations of them again while avoiding highly correlated predictors. The model that best-balanced model simplicity and predictive power is selected using the highest \({R}_{adjusted}^{2}\), together with the response curves of each predictor56.

Assessing climate stressor impacts

We are interested in the magnitude of the yield loss claimed by each climate stressor. After deriving the best-fitting GAM, the variation in yield claim by a certain climate stressor k can be derived from the difference between yields with and without the impact of the corresponding stressor:

$$\begin{array}{c}\Delta {{\rm{y}}}_{k,it}=({y}_{k,it}-{y}_{it})/{y}_{k,it}\\\quad\quad\quad\quad\,=1-\exp \{{\mathrm{ln}}({y}_{it})-\,{\mathrm{ln}}({y}_{k,it})\}\\ =1-\exp \{s({x}_{k,it})\}\end{array}$$
(2)

\({y}_{k,it}\) is the coffee yield by assuming that the climate stressor \({x}_{k}\) has no impact on yield, \(s({x}_{k})=0\), and \({y}_{it}\) is the model-predicted coffee yield with the impact of the stressor.

Given the above yield variation, the yield loss claimed by the climate stressor \({x}_{k}\) in year t will be \({L}_{k,it}=\,\max [0,\Delta {{\rm{y}}}_{k,it}]\). We computed the multi-annual average loss for each stressor over the study period (1992–2022), and the relative contribution of climate stressor k is:

$$R{C}_{k,i}={\bar{L}}_{k,i}/\mathop{\sum }\limits_{k=1}^{3}{\overline{L}}_{k,i}$$
(3)

Where \({\bar{L}}_{k,i}\) is the multi-annual average of \({L}_{k,it}\).