Solved – User-defined correlation matrix in R package nlme with negative values

autocorrelationlme4-nlmenonlinear regressionr

I have a nonlinear model with residuals that are negatively autocorrelated at short distances.

I can find no spatial correlation structures in nlme that can easily handle negative autocorrelation as most have bounds on parameter values so that the correlation is between 0 and 1.

First, is there something I am missing?

I tried to roll my own by calculating a correlation matrix with some negative values off the diagonal and then setting the correlation structure as follows within the function gnls:

correlation=corSymm(corr9x[lower.tri(corr9x)]) 

where corr9x is the $n \times n$ matrix of correlations that I set up based upon distances between points in the data set. Some of these correlations are positive and some are negative. They are based on a Moran's I correlogram that I calculated from the residuals returned from a gnls model fit with NO spatial correlation employed.

I get the following error:

Initial values for corSymm do not define a positive-definite correlation structure 

I am unsure if the matrix is rejected out of hand because it contains negative values or if there is something I can do to coerce it. I have checked the lower triangle matrix returned and it matches what I intended.

Any input is appreciated.

Best Answer

I was having the same problem. I'm not sure if it's correct - but I was able to get past the positive definite problem by using the command nearPD(), which computes the nearest positive definite matrix.

I am now running into the problem that @wvguy8258 mentioned about the wrong dimensions.