# How can I incorporate spatially correlated data into linear mixed effect model which is fitlmematrix method I am trying to use?

1 view (last 30 days)
Mithun Ghosh on 14 Jan 2018
Commented: Mithun Ghosh on 19 Feb 2018
lme = fitlmematrix(X,y,Z,G,'CovariancePattern','isotrophic','FitMethod','REML')
Here the covariance pattern is for random effect as much as I know. But I want to incorporate spatially correlated data into the model where my error variance would be ~N(0,R). Here R may b Gaussian Correlation function. The model fitlme assumed that error~N(0,sigma^2). So how can I incorporate Gaussian correlation function as error variance matrix here?

Gautam Pendse on 6 Feb 2018
Hi Mithun,
One way to approach this problem would be to use fitrgp but with a kernel function that combines Z and R. So if your model is y = X*beta + Z*b + epsilon, you could define Z*b + epsilon as a combined error term with covariance function Z*D*Z' + R which can be coded as a custom kernel function.
I am attaching an example that illustrates this using D = sigmaB^2*I and R as the squared exponential covariance.
Hope this helps,
Gautam
Mithun Ghosh on 19 Feb 2018
Hi I think I got your answer but I have one more question how can I incorporate grouping variables here?

Bernhard Suhm on 26 Jan 2018
The covariance matrix of the response in a linear mixed effects model has 2 components – a random effects component ( sigma^2)*sum_i{ Z_i*D_i*Z_i’} and an error component (sigma^2)*R, where D_i and R are typically block diagonal. These two components can compete in the sense that the same overall covariance can result from a complex random effects component + a simpler error component or a simpler random effects component + a complex error component. In fitlmematrix and fitlme, correlation between groups and observations is modelled by specifying Z_i and D_i whereas R is assumed to be the identity matrix. Depending on the structure of R, the same model could be obtained by selecting appropriate Z_i and D_i. Can you say more about the structure of R in the model? An alternative to modeling spatially correlated data would be to use Gaussian processes (see function fitrgp).

### Categories

Find more on Gaussian Process Regression in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by