Trend analysis determines whether a time series shows a statistically significant long-term increase or decrease. This guide covers both parametric (linear regression) and non-parametric (Sen's slope) methods.
Linear regression fits a straight line to the data and tests if the slope is significantly different from zero.
python
from scipy import stats
slope, intercept, r_value, p_value, std_err = stats.linregress(years, values)
print(f"Slope: {slope:.2f} units/year")
print(f"p-value: {p_value:.2f}")
Sen's slope is robust to outliers and does not assume normality. Recommended for environmental data.
python
import pymannkendall as mk
result = mk.original_test(values)
print(result.slope) # Sen's slope (rate of change per time unit)
print(result.p) # p-value for significance
print(result.trend) # 'increasing', 'decreasing', or 'no trend'
MethodProsConsLinear RegressionEasy to interpret, gives R²Sensitive to outliersSen's SlopeRobust to outliers, no normality assumptionSlightly less statistical power
p-valueInterpretationp < 0.01Highly significant trendp < 0.05Significant trendp < 0.10Marginally significantp >= 0.10No significant trend
python
import pandas as pd
import pymannkendall as mk
# Load annual precipitation data
df = pd.read_csv('precipitation.csv')
precip = df['Precipitation'].values
# Run Mann-Kendall test
result = mk.original_test(precip)
print(f"Sen's slope: {result.slope:.2f} mm/year")
print(f"p-value: {result.p:.2f}")
print(f"Trend: {result.trend}")
IssueCauseSolutionp-value = NaNToo few data pointsNeed at least 8-10 yearsConflicting resultsMethods have different assumptionsTrust Sen's slope for environmental dataSlope near zero but significantLarge sample sizeCheck practical significance