Hi:

On Mon, Feb 28, 2011 at 8:42 AM, John Sorkin <jsor...@grecc.umaryland.edu>wrote:

> 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)
>

Where's the random factor? Perhaps you mean

lme(values ~ 1, random = ~ 1 | subject, data = withindata)

or in lme4,

lmer(values ~ 1 + (1 | subject), data = withindata)

HTH,
Dennis

PS: Use of dput() output is more helpful than copying from the console, as
it retains the same classes you have on your end.


> dput(withindata)
structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L),
    values = c(2.3199639, -8.5795802, -4.1901241, 0.4588128,
    16.9128232, 8.9856358, 1.9303254, -1.4320313, -15.4225123,
    5.9293529, -29.2014153, -8.9684986, -11.906217, 13.2133887,
    1.2491941, -8.0613768, -5.6340179, 3.1916857, -7.7447932,
    2.2316354, 0.6444938, 4.6912677, 20.9135073, 2.1433533, -0.8057022,
    -13.0187979, 8.9634065, 13.4815344, 4.6148061, -18.4781373,
    15.5263564, -2.1993412, 5.183026, 16.2311097, -2.5781897,
    -3.016729, -0.1119353, 1.1983126, -8.8212143, 3.8895263)), .Names =
c("subject",
"values"), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40"))

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 ...{{dropped:13}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to