[R] predict.glmmPQL Problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Apr 3 17:23:46 CEST 2006


On Thu, 30 Mar 2006, Simon Blomberg wrote:

> I have found a similar problem when constructing formulae and passing
> them to glmmPQL. My solution was to use do.call(glmmPQL,...). See ?do.call.

This example works in current R!  The quoted R version is very old, and 
the reason I did not reply to the original posting was that the advice in 
the posting guide had been ignored.

The effect of do.call is to substitute in values, in this case including 
the whole data frame.  You can do that just for the formula by

model3 <- eval(substitute(
                glmmPQL(form, ~1 | factor(x2), family=poisson, data=mydata),
                list(form = f)))

and you might want to do that if using a model-fitting function from 
inside a function.

Note that the underlying problem is the non-standard way lme uses 
formulae: the common model-fitting functions use terms(), and

> terms(model2)
y ~ x1
attr(,"variables")
list(y, x1)
...

has captured the formula.


>> Spencer Graves wrote:
>> 	  Please try again after upgrading to the versions of R and MASS.
>>
>> 	  If you still have a problem, PLEASE do read the posting guide!
>> "www.R-project.org/posting-guide.html" before you submit another post.
>> Most of the people who donate their time to answer questions on this
>> listserve are more likely to answer a question if it is simple and
>> completely self contained -- including a very brief toy example that
>> they can copy from an email into R and reproduce the problem.  If they
>> can't do that, they are less likely to understand your question and
>> therefore less likely to produce a useful answer -- and less likely to
>> bother to even read carefully your question.
>>
>> 	  hope this helps,
>> 	  spencer graves
>>
>> rsubcriber wrote:
>>
>>
>>> Dear all,
>>>
>>> for a cross-validation I have to use predict.glmmPQL() , where the
>>> formula of
>>> the corresponding glmmPQL call is not given explicitly, but constructed
>>> using as.formula.
>>> However, this does not work as expected:
>>>
>>> x1<-rnorm(100); x2<-rbinom(100,3,0.5); y<-rpois(100,2)
>>> mydata<-data.frame(x1,x2,y)
>>>
>>> library(MASS)
>>> # works as expected
>>> model1<-glmmPQL(y~x1, ~1 | factor(x2), family=poisson, data=mydata)
>>> predict(model1, newdata=mydata, type="response")
>>>
>>> f<-as.formula(paste("y", "~","x1"))
>>> # predict does not work:
>>> # Error in mCall[["fixed"]][-2] : object is not subsettable
>>> model2<-glmmPQL(f, ~1 | factor(x2), family=poisson, data=mydata)
>>> predict(model2, newdata=mydata, type="response")
>>>
>>> Has anyone an idea what goes wrong?
>>> I am using R 2.0.1 under Windows 2000.
>>>
>>> Thanks,
>>> Anneke

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list