generate_ar1_series#
- causalpy.data.simulate_data.generate_ar1_series(n, phi=0.9, scale=1.0, initial=0.0)[source]#
Generate an AR(1) autoregressive time series.
- The AR(1) process is defined as:
x_{t+1} = phi * x_t + eta_t, where eta_t ~ N(0, scale^2)
- Parameters:
n (int) – Length of the time series to generate.
phi (float) – Autoregressive coefficient controlling persistence. Values closer to 1 produce smoother, more persistent series. Must be in (-1, 1) for stationarity. Default 0.9.
scale (float) – Standard deviation of the innovation noise. Default 1.0.
initial (float) – Initial value of the series. Default 0.0.
- Returns:
Array of length n containing the AR(1) time series.
- Return type:
np.ndarray
Example
>>> from causalpy.data.simulate_data import generate_ar1_series >>> np.random.seed(42) >>> series = generate_ar1_series(n=10, phi=0.9, scale=0.5) >>> len(series) 10