[R-sig-ME] help with plotting fitted values
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?
> My model is: mod <- lmer(gene1 ~ Treatment + Tissue + (1|Rat))
Then the simplest way to plot the results would be
plot(gene1 ~ fitted(mod))
> 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
Loading required package: Matrix
Loading required package: lattice
Attaching package: 'Matrix'
The following object(s) are masked from package:stats :
> 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,
> > sessionInfo()
> R version 2.7.0 Under development (unstable) (2008-03-05 r44683)
> attached base packages:
>  tools stats graphics grDevices datasets utils methods
>  base
> other attached packages:
>  hints_1.0.1 lme4_0.99875-9 Matrix_0.999375-4
>  lattice_0.17-6 affy_1.17.8 preprocessCore_1.1.5
>  affyio_1.7.14 Biobase_1.99.1
> loaded via a namespace (and not attached):
>  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)
> R-sig-mixed-models at r-project.org mailing list
More information about the R-sig-mixed-models