[R-sig-ME] corSymm in lme model returns error

Julia Dechamps julia.dechamps at jesus.ox.ac.uk
Thu Aug 18 19:28:47 CEST 2011


I have added more detail as follows in order for my problem to be quickly reproducible, in the hope that somebody might be able to help me more easily:

I have given the code with which to reproduce my dataframe, as well as the correlation matrix and correlation structure that I would like to incorporate into my lme model. 

The main issue I struggle to understand is the following: I have 22 observations on the variable "avg", where these observations fall into 4 groups (geographical districts, the factor being called "Level3Name"). I believe that the 22x22 correlation matrix "mycorrII" roughly describes the (spatial) correlation between my 22 observations. I succeed in fitting an lme model which models "avg" as the sum of a grand mean (i.e. intercept), a random effect at district level (i.e. at "Level3Name") and a residual random effect at observation level. But as soon as I introduce my correlation structure "mycorrstrucII" into the model, I obtain an error saying that the "Covariate must have unique values within groups for corSymm objects".

I would be extremely grateful for any advice!

Thank you!


# data: ------------------------------------------------------------------------------------------------

regIIsp <- cbind(Level3Name, avg)

where:

Level3Name <- c(rep("DI4",2), rep("DI5",3), rep("DI6",5), rep("DI7",12))
Level3Name <- as.factor(Level3Name)
avg <- c(2943, 2267, 3027, 2515, 3178, 2301, 2398, 2503, 2843, 2508, 2373, 1384, 1805, 2783, 
2205, 1717, 1338, 1971, 2733, 2666, 2268, 1603)


# correlation matrix: ---------------------------------------------------------------------------------

mycorrII <- diag(x=1,nrow=22,ncol=22)
mycorrII[cbind(col1,col2)] <- 0.28

where:

col1 <- c( 1 , 1,  1,  2,  2,  2,  3,  3,  3,  4,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  8,  8,
8,  9,  9,  9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16,
16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22,  2,  3,  3,
 4,  4,  5,  5,  5 , 5 , 6,  6,  7,  7,  8,  8,  9,  9,  9,  9, 10, 10, 11, 11, 12, 12, 12,
12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 18, 18, 18,
18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22)

col2 <- c(2,  7,  8,  1,  7,  8,  4,  5, 19,  3,  5, 19,  3,  4, 19,  7,  9, 10 , 6,  8,  9,  6,  7,
9,  6,  7,  8,  6,  9, 11, 13, 18, 20, 15, 21, 22, 11, 18, 20, 15, 19, 20, 14, 16, 21, 15,
21, 22, 12, 13, 18, 11, 13, 17,  5, 14, 20, 13, 14, 19, 15, 16, 22, 12, 16, 21,  1,  4,  5,
3,  5,  3,  4, 14, 19,  9, 10,  8,  9,  7,  9,  6, 7,  8, 10,  6,  9, 13, 18, 14, 15, 17,
18, 21, 22, 11, 18, 20,  5, 12, 15, 19, 20, 12, 14, 16, 21, 15, 21, 22, 12, 18, 11, 12, 13,
17,  5, 14, 20, 13, 14, 19, 12, 15, 16, 22, 12, 16, 21)


# correlation structure: ------------------------------------------------------------------------------

mycorrstrucII <- corSymm(value=mycorrII[col(mycorrII)<row(mycorrII)], form=~coordsII, fixed=TRUE)


# model to be fitted: ---------------------------------------------------------------------------------

lme(avg ~ 1, data=regIIsp, random= ~1 | Level3Name, correlation=mycorrstrucII)





________________________________________
From: Julia Dechamps
Sent: 18 August 2011 14:17
To: r-sig-mixed-models at r-project.org
Subject: corSymm in lme model returns error

Dear list,

I am trying to fit a two-level random effects model with a fixed general correlation structure to my data (22 observations in total occurring in 4 groups), using lme.

Without the correlation structure, the model can be fitted as follows: lme(avg ~ 1, data=regIIsp, random= ~1 | Level3Name).

The correlation matrix I now want to use for my 22 random effects (at the lower level) is a positive definite 22x22 matrix which has the values 0 and 0.28 as off-diagonal elements in a certain arrangement. I called the matrix mycorrII. I created my correlation structure using the corSymm class as follows (where I don´t want to specify any groups for now):

mycorrstrucII <- corSymm(value=mycorrII[col(mycorrII)<row(mycorrII)], form=~1, fixed=TRUE)

Since I supplied the value argument and set fixed=TRUE, I believe I do not need to initialize the matrix?
When trying to initialize nevertheless, I get the following error:
Error in getClass(Class) :
  c("\"corSymm\" is not a defined class", "\"corStruct\" is not a defined class")
In addition: Warning message:
In if (!is.na(match(Class, .BasicClasses))) return(newBasic(Class,  :
  the condition has length > 1 and only the first element will be used

When trying to retrieve my correlation matrix using corMatrix(mycorrstrucII), I get the following error:
Error in getCovariate.corStruct(object) :
  Need data to calculate covariate of corStruct object

I do not understand what is meant by calculating a covariate of the corStruc object.

When I try to fit my lme model with the specified correlation structure via: lme(avg ~ 1, data=regIIsp, random= ~1 | Level3Name, correlation=mycorrstrucII), I get the following error:
Error in Initialize.corSymm(X[[2L]], ...) :
  Initial value for corSymm parameters of wrong dimension

But my (initial) value, i.e. mycorrII[col(mycorrII)<row(mycorrII)], has length 231 which should be the right dimension (all elements below the main diagonal in the 22x22 matrix mycorrII).

Could anyone help me understand where I have gone wrong?
I greatly appreciate any advice, thank you so much in advance!!

Kind Regards,
Julia




More information about the R-sig-mixed-models mailing list