[R] lme error: Error in getGroups.data.frame(dataMix, groups)

John Sorkin jsorkin at grecc.umaryland.edu
Mon Feb 28 17:42:45 CET 2011


R 2.10.0
Windows XP

I am trying to run lme. I receive the following error message:
My lme code is: 
fitRandom <- lme(values ~ factor(subject),
data=withindata)

Below I have printed the console output, and at the bottom of this message, I have printed my code. 
I hope someone can tell my what I am doing wrong.
Thank you,
John
 
> print(withindata)
   subject      values
1        1   2.3199639
2        1  -8.5795802
3        1  -4.1901241
4        1   0.4588128
5        1  16.9128232
6        1   8.9856358
7        1   1.9303254
8        1  -1.4320313
9        1 -15.4225123
10       1   5.9293529
11       2 -29.2014153
12       2  -8.9684986
13       2 -11.9062170
14       2  13.2133887
15       2   1.2491941
16       2  -8.0613768
17       2  -5.6340179
18       2   3.1916857
19       2  -7.7447932
20       2   2.2316354
21       3   0.6444938
22       3   4.6912677
23       3  20.9135073
24       3   2.1433533
25       3  -0.8057022
26       3 -13.0187979
27       3   8.9634065
28       3  13.4815344
29       3   4.6148061
30       3 -18.4781373
31       4  15.5263564
32       4  -2.1993412
33       4   5.1830260
34       4  16.2311097
35       4  -2.5781897
36       4  -3.0167290
37       4  -0.1119353
38       4   1.1983126
39       4  -8.8212143
40       4   3.8895263
> fitRandom <- lme(values ~ factor(subject),
+ data=withindata)
Error in getGroups.data.frame(dataMix, groups) : 
  Invalid formula for groups
> summary(fitRandom)
Error in summary(fitRandom) : object 'fitRandom' not found
> 

My code:

library(nlme)

# Define essential constants.
# Number of subject studied.
NSubs <- 4
# Number of observations per subject.
NObs <- 10 
# Between study SD
tau <- 4 
# Within study SD.
sigma <- 8 
# END Define essential constants.

# Define between subject variation
between <- matrix(nrow=10,ncol=1)
between <- rnorm(NSubs,0,tau)
between
# END Define between subject variation.
 
# Define within subject varation.
within <- matrix(nrow=NObs*NSubs,ncol=2)
for (subject in 1:NSubs) {
  # Create a variable defining subject.
  within[c(1:NObs)+((subject-1)*NObs),1] <- subject
  # Create within subject variation.
  within[c(1:NObs)+((subject-1)*NObs),2] <- rnorm(NObs,between[subject],sigma)
}
# END Define within subject variation.

# Create a dataframe to hold values.
withindata <- data.frame(subject=within[,1],values=within[,2])
print(withindata[1:4,])

print(withindata)
fitRandom <- lme(values ~ subject,
data=withindata)
summary(fitRandom)



John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}



More information about the R-help mailing list