[R] panel ordering in nlme and augPred plots
Spencer Graves
spencer.graves at pdf.com
Fri Jul 7 20:42:54 CEST 2006
I'm not sufficiently familiar with 'trellis' / 'lattice' to provide
an easy, complete answer to your question, but I can explain the current
behavior and provide a hack to get you what you want. With luck,
someone else will suggest an improvement.
First, let's decompose your lovely, self-contained example in a more
informative way:
fm <- lme(Orthodont)
ap <- augPred(fm, level = 0:1)
plot(ap, skip = rep(c(F,T), c(16, 2)))
Next, let's examine the structure of 'ap':
str(ap)
Classes augPred and `data.frame': 2862 obs. of 4 variables:
$ age : num 8 10 12 14 8 10 12 14 8 10 ...
$ .groups : Ord.factor w/ 27 levels "M16"<"M05"<"M02"<..: 15 15 15 15
3 3 3 3 7 7 ...
..- attr(*, "label")= chr "Subject"
<snip ...>
The key here is that 'ap$.groups' is of class Ord.factor with levels
as follows:
> levels(ap$.groups)
[1] "M16" "M05" "M02" "M11" "M07" "M08" "M03" "M12" "M13" "M14" "M09"
"M15"
[13] "M06" "M04" "M01" "M10" "F10" "F09" "F06" "F01" "F05" "F07" "F02" "F08"
[25] "F03" "F04" "F11"
These names appear in the same order here that they appear in the
trellis display, reading the display from left to right and bottom to
top -- NOT top to bottom.
This also tells you one way to get around this: Change the order of
the levels. We can do this as follows:
ap2 <- ap
ap2$.groups <- with(ap,
ordered(as.character(.groups),
sort(levels(.groups))))
plot(ap2, skip = rep(c(F,T), c(11, 1)))
Hope this helps.
Spencer Graves
Nathaniel Derby wrote:
> Hi,
>
> I'm new at this, I'm very confused, and I think I'm missing something
> important here. In our pet example we have this:
>
>> fm <- lme(Orthodont)
>> plot(Orthodont)
>> plot(augPred(fm, level = 0:1))
>
> which gives us a trellis plot with the females above the males,
> starting with "F03", "F04", "F11", "F06", etc. I thought the point of
> this was to create an ordering where the females are ordered ("F01",
> "F02", "F03", etc -- followed by the males being ordered). However,
> the solution given ...
>
>> fm <- lme(Orthodont)
>> plot(Orthodont)
>> plot(augPred(fm1, level = 0:1), skip = rep(c(F,T), c(16, 2)))
>
> ... doesn't solve it -- although it does do all the females before
> starting on the males. That is, it starts with "F02", "F08", "F03",
> ... which isn't in order either.
>
> Running Petr's code also gave output which wasn't ordered by the subjects.
>
> Could someone please explain to me how to order the panels of the
> trellis plot by the subjects?
>
>
> thanks,
>
> Nandor
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list