0

I am trying to fit a linear mixed model in the R package nlme, using the lme function. There are a number of commonly-used correlation structures available to be used as values for the correlation argument. However, I would like to define a custom correlation structure. Based on the documentation, I believe that this is possible, but I don't understand their instructions well enough to implement it. As an example, suppose I want to use the following correlation structure:

enter image description here

How would I set the correlation argument of lme to this structure?

I provide a toy data set below, in case setting the correlation argument requires it.

# independent variable
x <- rnorm(3)

# effect of independent variable on dependent variable
slope <- 2

# error term
error <- rnorm(3, sd = 1/4)

# making successive independent variable observations correlated
alpha <- 0.5
y <- c()
y[1] <- slope * x[1] + error[1]
for (i in 2:length(x)){
  y[i] <-  (1 - alpha) * (slope * x[i] + error[i]) + alpha * y[i-1]
}
BioBroo
  • 613
  • 1
  • 7
  • 21
  • Please remove the "duplicate" tag. The previous question does not answer my question. It's certainly related, but that example uses pre-existing covariance structures, rather than user-created structures, which is what I'd like to do. – BioBroo Nov 23 '19 at 00:14
  • Your question refers to an AR(1) covariance structure. That is exactly what the duplicate target discusses. I fail to see how this is sufficiently different. It might help if you were to provide a reproducible example including code and sample data. At the moment your question is unclear/too broad without any actual code nor data. – Maurits Evers Nov 23 '19 at 00:16
  • The whole point is that I *don't* want to use the AR(1) correlation structure, but something that is similar to it, a structure that is not pre-existing. At the risk of explaining something you already know, AR(1) is one of a number of commonly used correlation structures. These commonly used structures are pre-programmed for ease of use. I'm pretty sure that the package allows for user-defined structures, but I can't figure out how to define them. – BioBroo Nov 23 '19 at 00:20
  • 1
    Ok I've re-opened your question. I urge you to rephrase the question though (you are *explicitly* asking for an AR(1) covariance structure) and include code. I can guarantee that this will increase the probability of getting a good answer. I for one am happy to take a look, provided you give us some code and data to work with. – Maurits Evers Nov 23 '19 at 00:23
  • 1
    Thanks. I rephrased the sentence that included AR(1) to remove the confusion that I was interested in using exactly AR(1). I also included some code. I usually do, but I have the feeling that the answer doesn't depend on data, which is why I didn't include it in the first place. Still, I could be wrong, so I included it. – BioBroo Nov 23 '19 at 00:40
  • Thanks for updating your model. I'm a bit confused about your data/model. You say you'd like to fit a mixed effect model, but the sample data you give is not consistent with such a model as it doesn't contain a random effect variable. To follow up from that: the `correlation` parameter in `nlme::lme` allows you to specify a correlation structure of the within-group measurements (which your sample data does not have); in other words, the `correlation` parameter does not describe the correlation between the model coefficients. Can you clarify which correlation structure you like to specify? – Maurits Evers Nov 23 '19 at 12:54
  • It is perhaps an unusual situation. I have only one group in my real data set as well. The data consists of measurements taken in a river and its tributaries. Upstream values influence downstream values, for obvious reasons, and that's what the data models. I have more than three data points, but I don't want to enlarge the question—I like to keep them as minimal as possible. Even though the correlation structure I gave as an example is not exactly what I'd do (it would be 18x18), if someone answers it, I'll be able to do what I want, and the question will be readable for others. – BioBroo Nov 23 '19 at 13:49
  • Sorry @BioBroo I’m not following at all. From a statistics and `lme` point of view `correlation`specifies the correlation structure of the within-group residuals. You can define your own correlation structure by creating a new `corStruct` class and specifying methods for `corMatrix` and `coef`. I don’t see how any of this is applies to your data/model based on the information you’ve provided so I will leave it at that. Perhaps somebody else can help. – Maurits Evers Nov 23 '19 at 14:41
  • I believe that what you said regarding `corStruct`, `corMatrix` and `coef` is exactly what I'm looking for. I just can't find a worked example. If you understand how to do this, can you make one? – BioBroo Nov 23 '19 at 20:06
  • As I explained you don’t provide a clear example with code&data that are *representative* of your problem. Writing a new `corStruct` can be somewhat tricky (you can find examples and discussions on the web that demonstrate that point); providing representative sample data including some details of what you expect for testing is particularly important in this case. I’ve asked you which correlation structure you want to specify (that of the fixed or random effects) and you still haven’t clarified on this point. Don’t get me wrong but this is not a very clear nor well presented question. – Maurits Evers Nov 24 '19 at 00:42

0 Answers0