Matlab: Calculating inverse of covariance matrix for time series model -

is univariate autoregressive ar model of order p = 2 , data samples n excited u gaussian 0 mean noise , variance sigma_u^2.
i aware of function cov(x) how use pxp covariance matrix c(n) , inverse, s(n) = c(n) coefficients of ar model. mathematical formula inverse covariance matrix, s(n) expressed
where a_1 , a_2 lower triangular toeplitz matrices.

can directly pinv(cov(coefficients))? unsure how pass arguments ar coefficients function.
how implement formula? thank help
your question entirely ill posed, others have noted, encourage reading , think what want do first. nonetheless, can provide guidance, has more straightening out concepts programming. based on question , comments, question should re-phrased as, "how 1 estimate covariance matrix parameters of ar(n) model in parameters obtained via maximum likelihood estimation?" in case can answer follows.
- for sake of discussion let's first generate test data.
>> rng(0); >> n = 10000; >> x = rand(n,2); - first obtain initial conditions smartly running ols. how people estimate autoregressions anyway (nearly entire literature on vector autoregressions) , ols , mle asymptotically equivalent under conditions. include column of zeros if want include constant (which want if working non-demeaned data). in output
bparameter estiamte vector ,ccorresponding vector of standard errors.
>> x = [x,ones(n,1)]; >> [b,c]=lscov(x,y) b = 4.9825 9.9501 20.0227 c = 0.0347 0.0345 0.0266 - before can maximum likelihood need likelihood first. can construct 1 composition of couple of simple anonymous functions. need construct initial conditions vector includes standard deviation of prediction error because 1 of things going estimate using mle. in case going assume distributed error, , base example on that, didn't , of course choose (not having distributed error typically motivation not doing ols). also, build negative log likelihood since using minimization routines.
>> err = @(b) y - x*b err = @(b)y-x*b >> std(err(b)) ans = 0.9998 >> b0 = [b; std(err(b))]; >> nll = @(b) (n/2)*log(2*pi*b(end)^2) + (1/(2*b(end)^2))*sum(err(b(1:end-1)).^2); - next use type of minimization routine (e.g.,
fminsearch,fminunc, etc.) mle.
>> bmle = fminsearch(nll,b0) bmle = 4.9825 9.9501 20.0227 0.9997 unsurprisingly, estimates identical obtained under ols, expect when errors distributed, , why people opt doing ols unless there compelling reason think errors non-normal. covariance matrix can estimated outer product of scores, particularly simple expression in normal case.
>> inv(x'*x/bmle(end)) ans = 0.0012 0.0000 -0.0006 0.0000 0.0012 -0.0006 -0.0006 -0.0006 0.0007 finally, standard errors match obtained in least squares case.
>> sqrt(diag(inv(x'*x/bmle(end)))) ans = 0.0347 0.0345 0.0266 edit: sorry, realized test data cross sectional instead of time series data. fix time. methodology estimating models stays same.
Comments
Post a Comment