﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
662	ARMAProcess::Eval.Almagro fails sometimes	Víctor de Buen Remiro	Víctor de Buen Remiro	"In [https://www.tol-project.org/browser/tolp/trunk/tol_tests/tol/random_generation/test_0005/test.tol tol_tests/tol/random_generation/test_0005/test.tol] there is a test for random generation of parameters of a linear regression with ARMA noise.

[[LatexEquation(Y = X \beta + z $$)]][[BR]]
[[LatexEquation(\phi\left(B\right) z_t = \theta\left(B\right) e_t $$)]][[BR]]
[[LatexEquation(e \sim N\left(0,\sigma^{2} I\right) $$)]][[BR]]

It generates a set of independent vectors [[LatexEquation(\beta $$)]] and it calculates their logarithm of density.

First, the generalized linear regression is normalized by means of Cholesky decomposition of ARMA covariance

[[LatexEquation( \Sigma_{\phi,\theta} = L_{\phi,\theta} L_{\phi,\theta}^{T} $$)]][[BR]]

[[LatexEquation(Y' = \frac{1}{\sigma} L_{\phi,\theta}^{-1} Y $$)]][[BR]]
[[LatexEquation(X' = \frac{1}{\sigma} L_{\phi,\theta}^{-1} X $$)]][[BR]]
[[LatexEquation(z' = \frac{1}{\sigma} L_{\phi,\theta}^{-1} z \sim N\left(0,\sigma^{2} I\right) $$)]][[BR]]

[[LatexEquation(Y'  = X' \beta + z' $$)]][[BR]]

Calculating Cholesky decomposition 

[[LatexEquation( X'^{T} X' = L L^{T} $$)]][[BR]]

we have that 

[[LatexEquation( \mu = L^{-T}L^{-1}X'^{T} Y' $$)]][[BR]]
[[LatexEquation( \epsilon \sim N\left(0,I\right) $$)]][[BR]]
[[LatexEquation( \beta = \mu + L^{-T} \epsilon $$)]][[BR]]

Obviously, logarithm of density of [[LatexEquation(\beta | \phi,\theta $$)]] is the same than for [[LatexEquation(\epsilon | \phi,\theta $$)]]

[[LatexEquation( logDens\left(\beta| \phi,\theta\right) = logDens\left(\epsilon | \phi,\theta\right) = \sum_{k=1}^n{ \frac{1}{\sqrt{2\pi}}exp\left(\frac{\epsilon_k^2}{2}\right)} $$)]]

Now, if we calculate ARMA noise corresponding for simulated [[LatexEquation(\beta $$)]]

[[LatexEquation(z = Y - X \beta $$)]][[BR]]

From Bayes theorem, logarithm of density of [[LatexEquation( z | \beta,\phi,\theta $$)]] matches

[[LatexEquation( logDens\left(z | \beta,\phi,\theta\right) = cte + logDens\left(\beta| \phi,\theta\right) $$)]]

TOL has two methods to calculate likelihood of an ARMA noise, ARIMALevinsonEval and ARIMAAlmagroEval (or alternatively ARMAProcess::Eval.Almagro). Well, ARIMALevinsonEval matches perfectly the given relation but ARIMAAlmagroEval fails sometimes.

"	defect	closed	highest	Numerical methods	Math	1.1.7	blocker	fixed	ARMA, likelihood evaluation, BSR	
