[R] predict lmer

2011-11-01 Thread Natalia VizcaĆ­no Palomar
Dear all,

I've been reading for many days trying to predict with lmer but I haven't
managed to do it.
I've fitted an allometric model for trees where I have included climatic
variables and diameter in the fixed part and
in the random part I've included the experimental sites where trees are and
also their provenance region.
The model is like this :

f431-lmer(log(H05)~log(DN05)*(PwS+ PoS+ PpS+
TpS)+PoP:log(DN05)+PwP:log(DN05)+(log(DN05)-1|P)+(log(DN05)-1|S/B)+(log(DN05)|SP),
data=data)

once I 've  fitted the model  I would like to make predictions for a new
data frame of values.
But i don't know how to do it.
For example I am interested in know how height varies (at a fixed diameter)
for a mean rainfall of a site in each provenance region to contrast with
how height response is for a mean rainfall provenance of each site and
things like this.

If someone can give any suggestion I will be pleased to listen to.

Thanks very much for your time,

The best

Natalia

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] predict lmer

2011-11-01 Thread Ben Bolker
Natalia VizcaĆ­no Palomar natalia.vizcaino.palomar at gmail.com writes:

 I've been reading for many days trying to predict with lmer but I haven't
 managed to do it.
 I've fitted an allometric model for trees where I have included climatic
 variables and diameter in the fixed part and
 in the random part I've included the experimental sites where trees are and
 also their provenance region.

  [snip]

 f431-lmer(log(H05)~log(DN05)*(PwS+ PoS+ PpS+
 TpS)+PoP:log(DN05)+PwP:log(DN05)+(log(DN05)-1|P)+
(log(DN05)-1|S/B)+(log(DN05)|SP),
 data=data)
 
  [snip snip]

  Have you looked at the code on http://glmm.wikidot.com/faq about this ... ?
If you look at it and still can't work it out I would suggest that requesting
help on the r-sig-mixed-models list will be more useful ...

  Ben Bolker

__
R-help@r-project.org 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.


[R] predict lmer

2008-05-10 Thread John Maindonald
The following function is designed to work with a logit link.  It can
easily be generalized to work with any link.  The SEs and CIs are
evaluated accounting for all sources of random variation. The plot
may not be much help unless there is just one explanatory variate.

`ciplot` -
  function(obj=glmm2, data=data.site, xcol=2, nam=litter){
cilim - function(obj, xcol){
  b - fixef(obj)
  vcov - summary(obj)@vcov
  X - unique(model.matrix(obj))
  hat - X%*%b
  pval - exp(hat)/(1+exp(hat))   # NB, designed for logit link
  U - chol(as.matrix(summary(obj)@vcov))
  se - sqrt(apply(X%*%t(U), 1, function(x)sum(x^2)))
  list(hat=hat, se=se, x=X[,xcol])
   }
limfo - cilim(obj, xcol)
hat - limfo$hat
se - limfo$se
x - limfo$x
upper - hat+2*se
lower - hat-2*se
ord - order(x)
plot(x, hat, yaxt=n, type=l, xlab=nam, ylab=)
rug(x)
lines(x[ord], lower[ord])
lines(x[ord], upper[ord])
ploc - c(0.01, 0.05, 0.1, 0.2, 0.5, 0.8, 0.9)
axis(2, at=log(ploc/(1-ploc)), labels=paste(ploc), las=2)
}

## Usage
glmm2 - lmer(rcr ~ litter + (1 | Farm), family=binomial,  
data=data.site)
ciplot(obj=glmm2)

John Maindonald email: [EMAIL PROTECTED]
phone : +61 2 (6125)3473fax  : +61 2(6125)5549
Centre for Mathematics  Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.


On 8 May 2008, at 8:00 PM, [EMAIL PROTECTED] wrote:
 From: May, Roel [EMAIL PROTECTED]
 Date: 8 May 2008 12:23:15 AM
 To: r-help@r-project.org
 Subject: [R] predict lmer


 Hi,

 I am using lmer to analyze habitat selection in wolverines using the
 following model:

 (me.fit.of -
 lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1| 
 ID:TRKPT2),data=vdata,
 control=list(usePQL=TRUE),family=poisson,method=Laplace))

 Here, the habitat selection is calaculated using a so-called discrete
 choice model where each used location has a certain number of
 alternatives which the animal could have chosen. These sets of  
 locations
 are captured using the TRKPT2 random grouping. However, these sets are
 also clustered over the different individuals (ID). USED is my binary
 dependent variable which is 1 for used locations and zero for unused
 locations. The other are my predictors.

 I would like to predict the model fit at different values of the
 predictors, but does anyone know whether it is possible to do this? I
 have looked around at the R-sites and in help but it seems that there
 doesn't exist a predict function for lmer???

 I hope someone can help me with this; point me to the right  
 functions or
 tell me to just forget it

 Thanks in advance!

 Cheers Roel

 Roel May
 Norwegian Institute for Nature Research
 Tungasletta 2, NO-7089 Trondheim, Norway


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] predict lmer

2008-05-07 Thread May, Roel
Hi,
 
I am using lmer to analyze habitat selection in wolverines using the
following model:
 
(me.fit.of -
lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1|ID:TRKPT2),data=vdata,
control=list(usePQL=TRUE),family=poisson,method=Laplace))
 
Here, the habitat selection is calaculated using a so-called discrete
choice model where each used location has a certain number of
alternatives which the animal could have chosen. These sets of locations
are captured using the TRKPT2 random grouping. However, these sets are
also clustered over the different individuals (ID). USED is my binary
dependent variable which is 1 for used locations and zero for unused
locations. The other are my predictors.
 
I would like to predict the model fit at different values of the
predictors, but does anyone know whether it is possible to do this? I
have looked around at the R-sites and in help but it seems that there
doesn't exist a predict function for lmer???
 
I hope someone can help me with this; point me to the right functions or
tell me to just forget it
 
Thanks in advance!
 
Cheers Roel
 
Roel May
Norwegian Institute for Nature Research
Tungasletta 2, NO-7089 Trondheim, Norway


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] predict lmer

2008-05-07 Thread Bert Gunter
?fixef

gets you the coefficient vector, from which you can make your predictions.

-- Bert Gunter
Genentech

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of May, Roel
Sent: Wednesday, May 07, 2008 7:23 AM
To: r-help@r-project.org
Subject: [R] predict lmer

Hi,
 
I am using lmer to analyze habitat selection in wolverines using the
following model:
 
(me.fit.of -
lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1|ID:TRKPT2),data=vdata,
control=list(usePQL=TRUE),family=poisson,method=Laplace))
 
Here, the habitat selection is calaculated using a so-called discrete
choice model where each used location has a certain number of
alternatives which the animal could have chosen. These sets of locations
are captured using the TRKPT2 random grouping. However, these sets are
also clustered over the different individuals (ID). USED is my binary
dependent variable which is 1 for used locations and zero for unused
locations. The other are my predictors.
 
I would like to predict the model fit at different values of the
predictors, but does anyone know whether it is possible to do this? I
have looked around at the R-sites and in help but it seems that there
doesn't exist a predict function for lmer???
 
I hope someone can help me with this; point me to the right functions or
tell me to just forget it
 
Thanks in advance!
 
Cheers Roel
 
Roel May
Norwegian Institute for Nature Research
Tungasletta 2, NO-7089 Trondheim, Norway


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] predict lmer

2008-05-07 Thread Bert Gunter
Sorry, my reply below may be too terse. You'll need to also construct the
appropriate design matrix to which to apply the fixef() results to.

If newDat is a data.frame containing **exactly the same named regressor and
response columns** as your original vdata dataframe, and if me.fit.of is
your fitted lmer object as you have defined it below, then

 model.matrix(terms(me.fit.of),newDat) %*% fixef(me.fit.of)

gives your predictions. Note that while the response column in newDat is
obviously unnecessary for prediction (you can fill it with 0's,say), it is
nevertheless needed for model.matrix to work. This seems clumsy to me, so
there may well be better ways to do this, and **I would appreciate
suggestions for improvement.*** 


Cheers,
Bert



-Original Message-
From: bgunter 
Sent: Wednesday, May 07, 2008 9:53 AM
To: May, Roel; r-help@r-project.org
Subject: RE: [R] predict lmer

?fixef

gets you the coefficient vector, from which you can make your predictions.

-- Bert Gunter
Genentech

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of May, Roel
Sent: Wednesday, May 07, 2008 7:23 AM
To: r-help@r-project.org
Subject: [R] predict lmer

Hi,
 
I am using lmer to analyze habitat selection in wolverines using the
following model:
 
(me.fit.of -
lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1|ID:TRKPT2),data=vdata,
control=list(usePQL=TRUE),family=poisson,method=Laplace))
 
Here, the habitat selection is calaculated using a so-called discrete
choice model where each used location has a certain number of
alternatives which the animal could have chosen. These sets of locations
are captured using the TRKPT2 random grouping. However, these sets are
also clustered over the different individuals (ID). USED is my binary
dependent variable which is 1 for used locations and zero for unused
locations. The other are my predictors.
 
I would like to predict the model fit at different values of the
predictors, but does anyone know whether it is possible to do this? I
have looked around at the R-sites and in help but it seems that there
doesn't exist a predict function for lmer???
 
I hope someone can help me with this; point me to the right functions or
tell me to just forget it
 
Thanks in advance!
 
Cheers Roel
 
Roel May
Norwegian Institute for Nature Research
Tungasletta 2, NO-7089 Trondheim, Norway


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] predict lmer

2008-05-07 Thread Kingsford Jones
One question that arises is: at what level is the prediction desired?
Within a given ID:TRKPT2 level?  Within a given ID level?  At the
marginal level (which Bert's code appears to produce).  Also, there is
the question:  how confident can you be in your predictions.  This
thread discusses possible ways to get prediction intervals:

https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q2/thread.html#841

Finally, why assume a Poisson error distribution for a binary response?

Kingsford Jones

On Wed, May 7, 2008 at 10:13 AM, Bert Gunter [EMAIL PROTECTED] wrote:
 Sorry, my reply below may be too terse. You'll need to also construct the
  appropriate design matrix to which to apply the fixef() results to.

  If newDat is a data.frame containing **exactly the same named regressor and
  response columns** as your original vdata dataframe, and if me.fit.of is
  your fitted lmer object as you have defined it below, then

   model.matrix(terms(me.fit.of),newDat) %*% fixef(me.fit.of)

  gives your predictions. Note that while the response column in newDat is
  obviously unnecessary for prediction (you can fill it with 0's,say), it is
  nevertheless needed for model.matrix to work. This seems clumsy to me, so
  there may well be better ways to do this, and **I would appreciate
  suggestions for improvement.***


  Cheers,
  Bert




  -Original Message-
  From: bgunter
  Sent: Wednesday, May 07, 2008 9:53 AM
  To: May, Roel; r-help@r-project.org
  Subject: RE: [R] predict lmer

  ?fixef

  gets you the coefficient vector, from which you can make your predictions.

  -- Bert Gunter
  Genentech

  -Original Message-
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
  Behalf Of May, Roel
  Sent: Wednesday, May 07, 2008 7:23 AM
  To: r-help@r-project.org
  Subject: [R] predict lmer



 Hi,

  I am using lmer to analyze habitat selection in wolverines using the
  following model:

  (me.fit.of -
  lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1|ID:TRKPT2),data=vdata,
  control=list(usePQL=TRUE),family=poisson,method=Laplace))

  Here, the habitat selection is calaculated using a so-called discrete
  choice model where each used location has a certain number of
  alternatives which the animal could have chosen. These sets of locations
  are captured using the TRKPT2 random grouping. However, these sets are
  also clustered over the different individuals (ID). USED is my binary
  dependent variable which is 1 for used locations and zero for unused
  locations. The other are my predictors.

  I would like to predict the model fit at different values of the
  predictors, but does anyone know whether it is possible to do this? I
  have looked around at the R-sites and in help but it seems that there
  doesn't exist a predict function for lmer???

  I hope someone can help me with this; point me to the right functions or
  tell me to just forget it

  Thanks in advance!

  Cheers Roel

  Roel May
  Norwegian Institute for Nature Research
  Tungasletta 2, NO-7089 Trondheim, Norway


 [[alternative HTML version deleted]]

  __
  R-help@r-project.org 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.

  __
  R-help@r-project.org 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.


__
R-help@r-project.org 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.