I'm trying to code up some plots for Autocorrelation Functions in Time Series Analysis, which can often be defined recursively. The goal is then to have Manipulate sliders that allow you to dynamically change the controlling parameters. Here's an example of the sort of plots I'm trying to emulate:
(here, $\phi_1$ and $\phi_2$ are the parameters I want to manipulate.)
For this $AR(2)$ model, the ACF, denoted $\rho_k$, can be defined recursively as follows:
$\rho_0 = 1$
$\rho_1 = \frac{\phi_1}{1-\phi_2}$
$\rho_k = \phi_1 \rho_{k-1} + \phi_2 \rho_{k-2}$
How do I implement this recursion and ListPlot in Mathematica?
I've tried doing:
ρ[0,φ1_,φ2_]:= 1
ρ[1,φ1_,φ2_]:= φ1/(1-φ2)
ρ[k,φ1_,φ2_]:= φ1 * ρ[k-1,φ1,φ2] + φ2 * ρ[k-2,φ1,φ2]
But then the ListPlot, even when plotted for e.g. {k, 0, 10}, only shows $ρ[0]$ and $ρ[1]$. I'm still a bit new to coding larger projects in Mathematica (only basic ODE StreamPlots in the past), so I think I'm misunderstanding the proper way to handle defining functions.
\[Rho][k_, phi1_, phi2_] := If[k == 0, 1, If[k == 1, phi1/(1 - phi2), phi1*\[Rho][k - 1, phi1, phi2] + phi2*\[Rho][k - 2, phi1, phi2]]]
$\endgroup$φ1=1/2; φ2=1/4; ρ[0,φ1_,φ2_]:= 1; ρ[1,φ1_,φ2_]:= φ1/(1-φ2); ρ[k_,φ1_,φ2_]:= φ1 * ρ[k-1,φ1,φ2] + φ2 * ρ[k-2,φ1,φ2]; ListPlot[Table[ρ[k,φ1,φ2],{k, 0, 10}]]
plots just fine $\endgroup$