Ullrich Ecker
2009-Jan-05 06:03 UTC
[R] getResponse(model.lme) yields incorrect number of dimensions error
Dear R experts, I would like to get an R^2 - like value for a multilevel regression using lme. I followed an archived suggestion by José Pinheiro to use the squared correlation between fitted and observed values, i.e., (cor(fitted(model.lme), getResponse(model.lme))^2 but getResponse returns the error message Error in val[, level] : incorrect number of dimensions The same happens with residuals(model.lme) and summary(model.lme) but not other generic functions such as predict, coef, or fitted, which (seem to) work fine. I have searched the archives but could not find a solution--I don't really understand what dimensions R is referring to. Any comments or suggestions would be greatly appreciated! Thanks for your time, and happy new year, Ullrich Below is part of the dataframe and the code: > WMUCTrim Subj Cond Acc S R T 1 1 1 0.6666667 1 1 1 2 1 2 0.8095238 1 0 1 4 1 4 1.0000000 1 0 0 6 1 6 0.9523810 0 0 1 7 1 7 0.8571429 0 1 0 8 1 8 1.0000000 0 0 0 209 2 1 0.3809524 1 1 1 210 2 2 0.9047619 1 0 1 212 2 4 1.0000000 1 0 0 214 2 6 0.8571429 0 0 1 215 2 7 0.6666667 0 1 0 216 2 8 1.0000000 0 0 0 > mlr2 <- summary(lme(Acc ~ R + T + S, random = ~1 | Subj)) > mlr2 Linear mixed-effects model fit by REML Data: NULL AIC BIC logLik -1140.414 -1113.778 576.2068 Random effects: Formula: ~1 | Subj (Intercept) Residual StdDev: 0.07069723 0.08233792 Fixed effects: Acc ~ R + T + S Value Std.Error DF t-value p-value (Intercept) 0.9843537 0.008937809 522 110.13367 0.0000 R1 -0.1139456 0.006958824 522 -16.37426 0.0000 T1 -0.1012472 0.006958824 522 -14.54946 0.0000 S1 -0.0137188 0.006958824 522 -1.97143 0.0492 Correlation: (Intr) R1 T1 R1 -0.260 T1 -0.260 0.000 S1 -0.260 0.000 -0.333 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -4.21190127 -0.46318153 0.02715579 0.58591808 2.57708969 Number of Observations: 630 Number of Groups: 105 > class(mlr2) [1] "summary.lme" "lme" > cor(fitted(mlr2), getResponse(mlr2))^2 Error in val[, level] : incorrect number of dimensions Dr Ullrich Ecker | Postdoctoral Research Fellow | Cognitive Science Laboratories | Room 211 Sanders Building | * School of Psychology | M304 | The University of Western Australia | 35 Stirling Highway | Crawley WA 6009 | Australia | ( 08 6488 3266 | Ê 08 6488 1006 | À 04 5822 0072 | @ ullrich.ecker@uwa.edu.au | i www.cogsciwa.com | [[alternative HTML version deleted]]