[R-sig-ME] help with plotting fitted values

Douglas Bates bates at stat.wisc.edu
Mon Mar 10 16:31:14 CET 2008


On Sat, Mar 8, 2008 at 3:42 PM, Mark W Kimpel <mwkimpel at gmail.com> wrote:
> I would like to plot fitted values from a model vs. the original values.
>  Is this possible?

Yes.

>  My model is: mod <- lmer(gene1 ~  Treatment + Tissue + (1|Rat))

Then the simplest way to plot the results would be

plot(gene1 ~ fitted(mod))

wouldn't it?

>  In Pinheiro and Bates, pg. 178, there is code to do this for nlme and on
>  pg. 179 is the resulting graph.

>  When I do:
>  plot(mod, gene1 ~ fitted(.))

>  I get:
>   > plot(mod, gene1 ~ fitted(.))
>  Error in xy.coords(x, y, xlabel, ylabel, log) :
>    'x' and 'y' lengths differ

Well, the nlme package uses S3 classes and methods which must dispatch
on the first argument, which is why the first argument is the fitted
model.  That is not the style for S4 classes and methods on which the
lme4 package is based.

In your case it doesn't look as if you are using the data argument in
the call to lmer, which is the preferred style, so your gene1 vector
is apparently accessible in the global environment.  If so, it is
simplest just to use the name directly as I showed above.  The model
general style of using the . and having access to variables in the
model frame is implemented using methods for the with generic so you
could use

> library(lme4)
Loading required package: Matrix
Loading required package: lattice

Attaching package: 'Matrix'


	The following object(s) are masked from package:stats :

	 xtabs

> fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
> with(fm1, xyplot(Reaction ~ fitted(.)))

As I said in response to another inquiry, there is no guarantee that
all code for the nlme package will work with the lme4 package.
Because lme4 extends the range of the mixed-effects models that can be
fit and because it is based on S4 classes and methods some things will
be done differently in lme4.

>  On a more general note, how does one get help for an overloaded function
>  like plot? help("plot", package = "lme4") yields "no documentation", I
>  could not find any info in the lme4 manual, and help(package = "lme4")
>  did not list any plot methods.
>
>  Session info follows. Thanks,
>  Mark
>
>   > sessionInfo()
>  R version 2.7.0 Under development (unstable) (2008-03-05 r44683)
>  x86_64-unknown-linux-gnu
>
>  locale:
>  LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
>
>  attached base packages:
>  [1] tools     stats     graphics  grDevices datasets  utils     methods
>  [8] base
>
>  other attached packages:
>  [1] hints_1.0.1          lme4_0.99875-9       Matrix_0.999375-4
>  [4] lattice_0.17-6       affy_1.17.8          preprocessCore_1.1.5
>  [7] affyio_1.7.14        Biobase_1.99.1
>
>  loaded via a namespace (and not attached):
>  [1] grid_2.7.0
>  --
>
>  Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
>  Indiana University School of Medicine
>
>  15032 Hunter Court, Westfield, IN  46074
>
>  (317) 490-5129 Work, & Mobile & VoiceMail
>  (317) 204-4202 Home (no voice mail please)
>
>  mwkimpel<at>gmail<dot>com
>
>  _______________________________________________
>  R-sig-mixed-models at r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>




More information about the R-sig-mixed-models mailing list