estimated growth curves from lme4
On 7/14/07, Afshartous, David <afshart at exchange.sba.miami.edu> wrote:
All,
The archive email below mentions the lack of general predict methods in
lme4. I would like to plot the estimated growth curves for
treatment/placebo
groups (or the estimated patient growth curves that augment the former
w/ the patient estimated
random effects).
I obtained the plot manually by constructing the appropriate functions
from the fixed effects output and plotting using curve() (sample code
below).
For those that have transitioned from lme, do you suggest sticking w/
such an approach
(and possibly automating it w/ additional code, but this would be
dependent on the type
of model that is estimated each time), or going back to lme where I
recall that this was relatively
simple given the nesting mentioned by Douglas Bates below.
Thanks,
David
sample code:
## assume growth curve is quadratic, and coefficeints for placego group
are 10, 50, -20:
quad.fun.Placebo <- function(t) {
y = 100 + 50*t - 20*t^2
y}
## plot from t=0 to t=5
curve(quad.fun.Placebo, 0,5, xlab="Time", ylab="Dependent Variable",
col="red")
ps - why don't the methods show up below?
library(lme4)
Loading required package: Matrix Loading required package: lattice
methods(class="lme4")
no methods were found
I think you meant class = "lmer" (there is no class called "lme4"). Even that won't show any methods, however, because the lme4 package uses S4 classes and methods, which is the reason for the "4" in the name of the package. The methods function only shows S3 methods. To see the listing of methods defined in the lme4 package use library(lme4) showMethods(where = "package:lme4")
From: Douglas Bates <bates_at_stat.wisc.edu <mailto:bates_at_stat.wisc.edu?Subject=Re:%20%5BR%5D%20Predicted%20value s%20in%20lmer%20modeling> > Date: Tue 28 Nov 2006 - 13:53:23 GMT On 11/28/06, Fucikova, Eva <E.Fucikova at nioo.knaw.nl> wrote:
Dear All,
I am working with linear mixed-effects models using the lme4 package
R. I created a model with the lmer function including some main
effects,
a two-way interaction and a random effect. Now I am searching for a
way
to save the predicted values for this model.
As far as I can see, there is no command in lme4 to save the predicted
values (like the predict(model) function in e.g. glm).
If you want the predictions at the observed values of the covariates you can use fitted(model)
This gives the following R output: Error in predict(lmer(model)) no
applicable method for "predict"
I found the same question in the R forum archives, but no answer.
Could anybody please give me an advice how to solve this problem?
<http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6158.html#6180qlink5> I haven't written a general method for predict applied to an lmer object because it is difficult to define what it should do. It is clear what the predictions based on the fixed effects only should be and perhaps it is clear what the standard errors of those predictions are (although that would be a case where my favorite topic of the degrees of freedom associated with a standard error would rear its ugly head again). It is trickier to define the predictions should be when you want to incorporate the random effects. If you incorporate all the "levels" of the random effects I think it is clear what the prediction should be. Defining a standard error for that prediction could be difficult - I'm not sure. However, I don't know what the answer should be if you only incorporate some of the random effects. We could define that unambiguously for lme models because the grouping factors were required to be nested. Because lmer allows for fully crossed or partially crossed grouping factors the concept of levels is lost. That is, there is no strict hierarchy in the grouping factors and we can't levels to define predictions. The bottom line is that I won't be able to write a predict method for lmer objects until I can decide what it should do, what options should be allowed and what the calling sequence should be.
________________________________ 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. Received on Wed Nov 29 18:44:37 2006 * This message: [ Message body <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6180.html#start> ] * Next message: Guenther, Cameron: "[R] Counting zeros in a matrix" <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6181.html> * Previous message: Liaw, Andy: "Re: [R] automatic cleaning of workspace" <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6179.html> * In reply to Fucikova, Eva: "[R] Predicted values in lmer modeling" <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6158.html> * Next in thread: Benilton Carvalho: "[R] predict on biglm class" <http://tolstoy.newcastle.edu.au/R/e2/help/07/02/10349.html> * Reply: Benilton Carvalho: "[R] predict on biglm class" <http://tolstoy.newcastle.edu.au/R/e2/help/07/02/10349.html> * Contemporary messages sorted: [ By Date <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/date.html#6180> ] [ By Thread <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/index.html#6180> ] [ By Subject <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/subject.html#6180> ] [ By Author <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/author.html#6180> ] [ By messages with attachments <http://tolstoy.newcastle.edu.au/R/e2/help/06/11/attachment.html> ] [[alternative HTML version deleted]] _______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models