I asked this question in stackoverflow, with no success. I am hoping that i might get some suggestions here.

I am trying to generate non-zero mean AR(2) samples using statsmodels package. But it seems , by default we can't generate non-zero mean samples.

Is there any workaround. I want to generate only positive samples. I am fine with R too.

My current code is

import numpy as np
from statsmodels.tsa.arima_process import ArmaProcess

rng = np.random.default_rng(12345)
ar_1 = np.array([1, -0.25, -0.25])    
ar_2 = np.array([1, -0.5, -0.25])  
ma1 = np.array([1])
ar1_proc = ArmaProcess(ar_1, ma1)
ar1_dat = ar1_proc.generate_sample(nsample=2*60*60, distrvs=rng.lognormal)
ar2_proc = ArmaProcess(ar_2, ma1)
ar2_dat = ar2_proc.generate_sample(nsample=2*60*60, distrvs=rng.lognormal)
  • $\begingroup$ The question is ambiguous. Is the target a non-zero mean or a positive valued time series? The former can be achieved by just adding a mean to the simulated series as in Hardy's answer. I don't see a way to create a stationary linear AR process that has only positive values. For example log transforming a gaussian linear AR process creates a multiplicative lognormal AR process. GLM type autoregressive models for positive valued data would require a nonlinear link function. $\endgroup$
    – Josef
    Commented Feb 13 at 22:40

1 Answer 1


You can add any mean you like after having simulated a zero-mean AR(2) process. (I do not use statsmodels so I am not providing code, but adding a constant to a simulated time series should be super easy.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.