Error Calculating MVN Likelihood of Time Series with AR(1) Errors in R

Hi all,

I'm having trouble calculating the likelihood of a time series with AR(1) errors. I am generating my covariance matrix according to page 2 of (, using the library mvtnorm and the multivariate normal density function dmvnorm(). Here's some example code:


# Generate a basic time series with AR(1) Errors:

t <- 1:100

error <- as.numeric(arima.sim(n = length(t), list(ar = c(0.8897)), sd = 10))

series <- 5*t + error

# Fit the series using a basic linear model assuming errors are IID Normal

naive.model <- lm(series ~ t -1)

# Examine and model the residuals

residuals <- series - t*coef(naive.model)

residual.model <-  arima(residuals, c(1,0,0), include.mean=F)

# Construct the covariance matrix, assuming the process variance (10^2) is known

sigma <- diag(length(t))

sigma[(abs(row(sigma)-col(sigma)) == 1)] = as.numeric(coef(residual.model))

sigma <- sigma*10^2

# Calculate the MVN density...

dmvnorm(series, t*coef(naive.model) ,sigma, log=T)
Without fail, I get the following error message:

Warning message: In log(eigen(sigma, symmetric = TRUE, only.values = TRUE)$values) : NaNs produced.

It's worth noting that the matrix from the following ( "works", but I think is actually for an MA(1) process rather than an AR(1) process.

I gather the message means the proposed covariance matrix may not be invertible. This said I'm stuck on how to proceed and would be extremely appreciative of any thoughts.

Thank you very much,


Ambassador to the humans
Your covariance matrix isn't actually for an AR(1) process. You might want to reevaluate what it should look like in the AR case.


Ambassador to the humans
I didn't take the take to read the pdf you linked to (plus the link was broken). But the correlation matrix you're using is for an MA model - not an AR model. And the problem is that you're using the parameter estimated for the AR model and pretending like thats the parameter for an MA model - but the estimated parameter is impossible for an MA model.

Thanks again for your help. Clearly the issue is how I'm generating my covariance matrix... I've checked a number of different resources, each of which seem to suggest that the covariance matrix for an AR process should be generated in the manner in which I'm generating it. Are you aware of any more reliable resources on the topic?