Solved – How to specify in r spatial covariance structure similar to SAS sp(pow) in a marginal model

generalized-least-squarespanel datarsasspatial

I'm currently translating existing code from SAS to R. I'm working on longitudinal data (CD4 count over time). I have the following SAS code :

Proc mixed data=df;
class NUM_PAT;
model CD4t=T /s ;
repeated / sub=NUM_PAT type=sp(pow)(T);

The SAS spatial power covariance structure is useful for unequally spaced longitudinal measurements where the correlations decline as a function of time (as shown by the picture below).
Spatial Power Covariance Structure

I think I have to use gls( ) from {nlme} since I don't have any random effects. As R 'only' provides "spherical", "exponential", "gaussian", "linear", and "rational" as correlation spatial structures, my guess is that I need to use corSpatial plus a weights argument.

I tried the following code, but it doesn't work :

gls(CD4t~T, data=df, na.action = (na.omit), method = "ML",
corr=corCompSymm(form=~1|NUM_PAT), weighhts=varConstPower(form=~1|T))

What am I doing wrong ?

Thanks for any help.

Best Answer

The spatial power covariance structure is a generalization of the first-order autoregressive covariance structure. Where the first-order autoregressive structure assumes the time points are equally spaced, the spatial power structure can account for a continuous time point. In reality, we could just forget the first-order autoregressive structure entirely, because if we fit the spatial power structure when the data are equally spaced we'll get the same answer as when using the first-order autoregressive structure.

All that aside, the correlation function you're looking for is corCAR1(), which is the continuous first-order autoregressive structure. If you're looking to duplicate what you fit in SAS, then the code you're looking for is:

gls(CD4t~T, data=df, na.action = (na.omit), method = "REML",
    corr=corCAR1(form=~T|NUM_PAT))

Of course, you don't need to specify method = "REML", since, as in SAS, the default method in gls() is already restricted maximum likelihood.

Related Question