Dirk Enzmann
2006-Jul-24 11:55 UTC
[R] conflict of package "Matrix" and summary of lme object
After loading the package "Matrix" (version 0.995-12), using the summary function with an lme (package nlme version 3.1-75) object results in an error message saying Fehler in dim(x) : kein Slot des Namens "Dim" f?r dieses Objekt der Klasse "correlation" (translated: 'Error in dim(x) : no slot of the name "Dim" for this object of class "correlation")'. Without loading "Matrix" this error message does not occur. Any ideas? ------------------------------ R version: 2.3.1 Patched (2006-06-21 r38367) Operating system: Windows XP (5.1 (Build 2600)) CPU: Pentium Model 2 Stepping 9 ************************************************* Dr. Dirk Enzmann Institute of Criminal Sciences Dept. of Criminology Edmund-Siemers-Allee 1 D-20146 Hamburg Germany phone: +49-(0)40-42838.7498 (office) +49-(0)40-42838.4591 (Billon) fax: +49-(0)40-42838.2344 email: dirk.enzmann at uni-hamburg.de www: http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
Martin Maechler
2006-Jul-24 13:41 UTC
[R] conflict of package "Matrix" and summary of lme object
>>>>> "Dirk" == Dirk Enzmann <dirk.enzmann at uni-hamburg.de> >>>>> on Mon, 24 Jul 2006 13:55:44 +0200 writes:Dirk> After loading the package "Matrix" (version 0.995-12), Dirk> using the summary function with an lme (package nlme Dirk> version 3.1-75) object results in an error message Dirk> saying Dirk> Fehler in dim(x) : kein Slot des Namens "Dim" f?r Dirk> dieses Objekt der Klasse "correlation" Dirk> (translated: 'Error in dim(x) : no slot of the name Dirk> "Dim" for this object of class "correlation")'. Dirk> Without loading "Matrix" this error message does not Dirk> occur. Dirk> Any ideas? Yes. Thank you for the report. The error happens when PRINTing a summary.lme object, i.e., ssl <- summary(<lme> ) ## works fine ssl ##-> gives the error The short answer: Don't use 'Matrix' together with 'nlme' for the time being (but rather use 'lme4' and lmer() if possible) A long answer: The problem happens because 'Matrix' defines a (S4) class "correlation" (which inherits from "dpoMatrix"). Hence dim( <correlation> ) is accessing the 'Dim' slot of the <correlation> object --- which obviously must fail for that part of a "summary.lme" object which is not a proper S4 object at all. Here is reproducible example of showing the problem without even doing an nlme related thing: > x <- round(cor(matrix(rnorm(100), 20,5)),2); class(x) <- "correlation" ; x [,1] [,2] [,3] [,4] [,5] [1,] 1.00 -0.29 -0.07 -0.11 0.03 [2,] -0.29 1.00 0.10 -0.02 0.20 [3,] -0.07 0.10 1.00 0.05 0.13 [4,] -0.11 -0.02 0.05 1.00 -0.21 [5,] 0.03 0.20 0.13 -0.21 1.00 attr(,"class") [1] "correlation" > dim(x) [1] 5 5 > library(Matrix) Loading required package: lattice > dim(x) Error in dim(x) : no slot of name "Dim" for this object of class "correlation" > dim .Primitive("dim") > showMethods(dim) Function "dim": x = "ANY" x = "Matrix" x = "correlation" (inherited from x = "Matrix") > showClass("correlation") Slots: Name: sd x Dim Dimnames uplo factors Class: numeric numeric integer list character list Extends: Class "dpoMatrix", directly Class "dsyMatrix", by class "dpoMatrix" Class "ddenseMatrix", by class "dpoMatrix" Class "symmetricMatrix", by class "dpoMatrix" Class "dMatrix", by class "dpoMatrix" Class "denseMatrix", by class "dpoMatrix" Class "Matrix", by class "dpoMatrix" Class "Matrix", by class "dpoMatrix" Class "compMatrix", by class "dpoMatrix" Class "Matrix", by class "dpoMatrix" > A workaround -- not for you but the authors of 'Matrix' and/or 'nlme' -- is for one of the two packages to call the class differently. At the moment, I tend to do the change in 'nlme', since there, the "correlation" class has been almost entirely hidden from the user. A workaround for you: Redefine print.summary.lme, e.g., by commenting the line class(corr) <- "correlation" Regards, Martin
Seemingly Similar Threads
- standardized random effects with ranef.lme()
- skewness and kurtosis in e1071 correct?
- Problem with read.spss() and as.data.frame(), or: alternative to subset()?
- How to reply to a thread if receiving R-help mails in digest form
- using argument names (of indeterminate number) within a function