# Determining the distribution and other characteristics of a variable defined by a recurrence relation

I want to determine the distribution and some other characteristics of a recursive defined variable and need hereby some help/advice.

I have the recurrence relation

$\qquad X_t = X_{t-1} + \phi (\mu - X_{t-1}) + \lambda e_t$

I tried to solve this recurrence relation in the following way

FullSimplify[RSolve[{Subscript[X, t] ==
Subscript[X, t - 1] + \[Phi] (\[Mu] - Subscript[X,  t - 1] + \[Lambda] Subscript[e, t]) && Subscript[X, 0] == \[Mu]}, Subscript[X, t], t]]


Question 1:

Mathematica seems unable to simplify the solution adequately, especially with regards to constants in the sum:

Collect[(1 - \[Phi])^(-1 + t) (\[Mu] - \[Mu] \[Phi] + \!$$\*UnderoverscriptBox[\(\[Sum]$$, $$K[1] = 0$$, $$\(-1$$ + t\)]$$\*SuperscriptBox[\((1 - \[Phi])$$, $$-K[1]$$]\ \[Phi]\ $$(\[Mu] + \[Lambda]\\*SubscriptBox[\(e$$, $$1 + K[1]$$])\)\)\)), \[Mu]]


Is there a way to refine the command such that Mathematica is able to further simplify it? A more simplified version would be

$\qquad X_t = \mu + \sum_{j=1}^{t}(1-\phi)^{t-j} \lambda e_j$

Question 2:

I want to determine the distribution of $X_t$. Therefore, I found TransformDistribution. Is there anyway to tell Mathematica that all $e_j \sim$ iid $N(0,\sigma^2)$?

I tried the following for a specified sum

TransformedDistribution[a x + \!$$\*UnderoverscriptBox[\(\[Sum]$$, $$t = 1$$, $$2$$]\*SubscriptBox[$$e$$, $$t$$]\), Join[Table[Subscript[e, t] \[Distributed] NormalDistribution[0, se], {t, 2}], {x \[Distributed] NormalDistribution[\[Mu], sx]}]]


However, generalising the sum doesn't work. Any ideas?

TransformedDistribution[\[Mu] (1 - \[Phi])^ t + (1 - \[Phi])^(-1 + t) \!$$\*UnderoverscriptBox[\(\[Sum]$$, $$K[1] = 0$$, $$\(-1$$ + t\)]$$\*SuperscriptBox[\((1 - \[Phi])$$, $$-K[1]$$]\ \[Phi]\ $$(\[Mu] + \[Lambda]\\*SubscriptBox[\(e$$, $$1 + K[1]$$])\)\)\), Table[Subscript[e, j] \[Distributed] NormalDistribution[0, se], {j, t}]]


Question 3:

I want to determine the autocorrelation of $X_t$.

• Please post copyable code, not images of the code, so that people may copy-paste it into MMA and play with it. This way you are likely to get more attention and help. Feb 27, 2018 at 6:36
• thx for the comment, I tried to add some code. Hope that's ok so. If not I would be happy about any advice on how to add code right - sorry I'm a first time user... Feb 28, 2018 at 22:08

The recurrence equation that is specified in the question is not the same as the one that Mathematica has simplified in the code screen-shot$^{*}$; nevertheless, it is true that-for either specification-further simplification needs a different approach; the one pursued here is to explicitly perform the implied recurrence for a limited number of steps; subsequently, we define inductively the recurrence solution (see Code block 1 & 2). The simplified solution to the recursion is $X_t=μ+\sum_{s=0}^{t}(-1)^{t-s}λ(1-φ)^{t-s}e_t$.

The reason that that the second Table does not evaluate as expected and produces an error is due to the fact that t is not a number (See Code Block 3).

Unless the $e_t$'s are jointly distributed, using Correlation to get the autcorrelations of $X_t$ at different lags returns 0 (See Code Block 4 & 5).

$^{*}$ please insert actual code, do not post screenshots of code

Code block 1: Identify the recursion

Block[{φ, x, λ, e, expr, expr0, t, make, show},

expr = #1 + φ (x[0] - #1) + λ e[#2] &;
expr0 = x[0] + λ e[0];

make = MapIndexed[{Rule @@ {t, First[#2] - 1}, Rule @@ {x[t], #1}} &, #] &;
show = Grid[# // Prepend[#, {t, x[t]}] &, Alignment -> Left, Dividers -> {{False, True}, {False, True}}] &;

With[{Ts = 4},
With[{ts = Range[Ts]},
FoldList[expr, expr0, ts] // Collect[#, Thread[e[ts - 1]], Simplify] &
] // make // show
]
]


Evaluation output for up to $t=4$:

It seems plausible, that $X_t$ satisfies the following reduced form solution

Clear[x]
x[0]=μ;
x[t_] := Sum[(-1)^(t - s) e[s] λ (φ - 1)^(t - s), {s, 0, t}] + x[0]


Code block 2: Verify

Block[{φ, x, λ, e, expr, expr0, short, t, make, show, Test},

expr = #1 + φ (x[0] - #1) + λ e[#2] &;
expr0 = x[0] + λ e[0];

make = MapIndexed[{Rule @@ {t, First[#2]}, Rule @@ {x[t], First[#1]}, Simplify[Equal @@ #1]} &, #] &;
show = Grid[# // Prepend[#, {t, x[t], Test}] &, Alignment -> Left, Dividers -> {{False, True}, {False, True}}] &;

With[{Ts = 4},
short[t_] := Sum[(-1)^(t - s) e[s] λ (φ - 1)^(t - s), {s, 0, t}] + x[0];

With[{ts = Range[Ts]},
{FoldList[expr, expr0, ts] // Collect[#, Thread[e[ts - 1]], Simplify] &, Join[{expr0}, short /@ ts]}] // Transpose // make // show
]
]


The last column verifies that the proposed solution (short in the code block) produces the same result as the recursion defined in FoldList.

Code Block 3: Distributions for $X_t$, when the $e_t$'s are not jointly distributed

Block[{φ, x, λ, e, μ, short, xdist, edists, σ},

With[{Ts = 4},
short[t_] := Sum[(-1)^(t - s) e[s] λ (φ - 1)^(t - s), {s, 0, t}];
xdist[t_, eds_] := TransformedDistribution[short[t] + x[0], eds, Assumptions -> {σ > 0, λ > 0}];

edists[0] = {Distributed[e[0], NormalDistribution[0, σ^2]]};
edists[t_] := Flatten[{edists[t - 1], Distributed[e[t], NormalDistribution[0, σ^2]]}];

With[{ts = Range[Ts]},
With[{c = #},
Distributed[x[c], MapAt[Factor, xdist[c, edists[c]] /. x[0] -> μ // Simplify, {{2, 1}}]]
] & /@ Prepend[ts, 0]

]
]
]

lengthy output; not reproduced here


Code Block 4: Autocovariances for $X_t$ when the $e_t$'s are not jointly distributed

Block[{φ, x, λ, e, μ, short, xdist, edists, σ, xdists},

With[{Ts = 4},
short[t_] := Sum[(-1)^(t - s) e[s] λ (φ - 1)^(t - s), {s, 0, t}];
xdist[t_, eds_] := TransformedDistribution[short[t] + x[0], eds, Assumptions -> {σ > 0, λ > 0}];

edists[0] = {Distributed[e[0], NormalDistribution[0, σ^2]]};
edists[t_] := Flatten[{edists[t - 1], Distributed[e[t], NormalDistribution[0, σ^2]]}];

With[{ts = Range[Ts]},
xdists = With[{c = #},
Distributed[x[c],
MapAt[Factor, xdist[c, edists[c]] /. x[0] -> μ // Simplify, {{2, 1}}]]
] & /@ Prepend[ts, 0];

Outer[With[{dist1 = #1, dist2 = #2, var1 = #1[[1]], var2 = #2[[1]]},
Expectation[(var1 - Expectation[var1, dist1]) (var2 - Expectation[var2, dist2]), Union@{dist1, dist2}] // Simplify
] &, xdists, xdists, 1] // MatrixForm

]
]
]

lengthy output; not reproduced here


It is a diagonal matrix with the variances of the $X_t$'s on the main diagonal.

Code Block 5: Pairwise autocorrelations for $X_t$ when the $e_t$'s are jointly distributed

Block[{x, λ, φ, μ, e, mus, es, sigma, σ, edist, ρ, xijDist},
x[t_] := Sum[(-1)^(t - s) e[s] λ (φ - 1)^(t - s), {s, 0, t}];
With[{T = 4},
mus = Array[μ, T];
es = Array[e, T];
With[{diag = Array[If[#1 < #2, σ[#1, #2], 0] &, {T, T}]},
sigma = DiagonalMatrix[Array[σ[#, #]^2 &, T]] + diag + Transpose[diag];
edist = MultinormalDistribution[mus /. μ[_] -> μ, sigma /. σ[i_, j_] :> ρ σ^2];
xijDist = TransformedDistribution[{x[#1], x[#2]}, es \[Distributed] edist, Assumptions -> {σ > 0, λ > 0, ρ > 0}] &;
With[{ts = Range[T]},
Outer[
MatrixForm[Correlation[xijDist[##]]] &, ts, ts, 1] // Simplify
]
]
]
]

lengthy output; not reproduced here


It is a matrix with the correlation matrices for each $X_t$ with all the rest per row.