[R] plotting all subgroups with augPred

Spencer Graves spencer.graves at pdf.com
Fri Sep 29 17:30:34 CEST 2006


      You want an 'augPred' plot with multiple lines per panel, from 
multiple factors in the model?  Because you provided such a simple, 
self-contained example, I can offer much more substantive comments than 
I might have otherwise.  First the bad news:  I don't see an easy way to 
get what you want.  Good news:  I think I can outline for you a 
moderately simple but still not trivial way to get it -- though I 
haven't completed the exercise myself. 

      The 'augPred' documentation includes an example with two lines per 
panel, but one of the lines is just the 'fixed' model, which is the same 
in all frames.  That's not what you want. 

      To dig deeper, I typed 'augPred' at a command prompt:  It's a one 
line function consisting of 'UseMethod("augPred")'.  This pushed me to 
do the following: 

 > methods("augPred")
[1] augPred.gls*    augPred.lme*    augPred.lmList*

      This led me to try "getAnywhere(augPred.lme)", which listed out 
the function.  I decided I wanted to walk through the function line by 
line, so I tried the following: 

 > debug(augPred.lme)
Error: object "augPred.lme" not found

      Since 'augPred' is in library(nlme), I refined this as follows: 

 > debug(nlme:::augPred.lme)

      This worked.  Next I tried to execute your command 
'augPred(fm1Pixel)', which put me into 'augPred.lme'.  From there, one 
can walk through the function line by line, looking at what they do, 
etc.  Later, you can do the execute your own modification to that code 
outside of a call to 'augPred'.  If you get 'object ... not found', try 
adding 'nlme:::' as a prefix to '...'.  If you do this, you will find 
that 'augPred' basically does three things: 

      1.  Creates a data.frame 'value' containing the explanatory 
variables for which predictions are needed.  You need to add a column 
for 'Side' to 'value';  I don't see a way to do this in the function call. 

      2.  Call 'pred <- predict(...)' to get the numbers required for 
the lines. 

      3.  Reorganize things so 'plot.augPred' knows what to do. 

      After you get 'pred' with all the numbers you need, you can plot 
them any way you want. 

      Hope this helps. 
      Spencer Graves

Afshartous, David wrote:
> All,
>
> I have a question RE plotting the prediction lines of a random effects
> model via augPred.  I'll illustrate via the Pixel dataset within the
> nlme package: 
>
> library(nlme)
> attach(Pixel)
> fm1Pixel = lme(pixel ~ day + I(day^2), data = Pixel, random = list(Dog =
> ~ 1))
> plot(augPred(fm1Pixel))   ### 10 fitted lines since there are 10 dogs
>
> fm2Pixel = update(fm1Pixel, . ~ . + Side)
> plot(augPred(fm2Pixel))    ## also produces 10 fitted lines
>
> For the second plot, shouldn't we have 2 fitted lines per dog, one for
> each level
> of the fixed effect Side?  
>
> 1) How does one plot insure that this is plotted accordingly?
>
> 2) How does one plot say only the first 5 dogs?
>
>
> Thanks!
> Dave
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list