[Rd] Bootstrapping stepAIC() with glm.nb()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 23 14:14:58 CET 2007


On Fri, 23 Feb 2007, Dimitris Rizopoulos wrote:

>
> ----- Original Message ----- From: "Prof Brian Ripley" 
> <ripley at stats.ox.ac.uk>
> To: "Dimitris Rizopoulos" <dimitris.rizopoulos at med.kuleuven.be>
> Cc: <r-devel at r-project.org>
> Sent: Friday, February 23, 2007 1:40 PM
> Subject: Re: [Rd] Bootstrapping stepAIC() with glm.nb()
>
>
>> You did not say what the problem was!
>> 
>> But you are asking that an object which is not in scope (index) be found a 
>> few levels down.  You should be able to fix this by substituting in the 
>> values in fn.  Here is one way:
>>
>>         up.obj <- update(object, data = data[index[, i], ])
>>         Call <- up.obj$call
>>         Call$data <- data[index[, i], ]
>>         up.obj$call <- Call
>> 
>> (there are others).
>
>
> thanks very much for your reply and workaround. However, could you please 
> explain me (or point me to the right direction) why it *does* work, without 
> the workaround, for 'lm', 'glm' and 'aov' objects.

They have dropterm methods that make use of the model frame that is stored 
with the objects (by default).

>
> Thanks in advance,
> Dimitris
>
>
>
>
>> 
>> On Fri, 23 Feb 2007, Dimitris Rizopoulos wrote:
>> 
>>> Dear all,
>>> 
>>> I would like to Boostrap the stepAIC() procedure from package MASS for
>>> variety of model objects, i.e.,
>>> 
>>> fn <- function(object, data, B = 2){
>>>    n <- nrow(data)
>>>    res <- vector(mode = "list", length = B)
>>>    index <- sample(n, n * B, replace = TRUE)
>>>    dim(index) <- c(n, B)
>>>    for (i in 1:B) {
>>>        up.obj <- update(object, data = data[index[, i], ])
>>>        res[[i]] <- stepAIC(up.obj, trace = FALSE)
>>>    }
>>>    res
>>> }
>>> 
>>> ####################
>>> 
>>> library(MASS)
>>> 
>>> 
>>> # 'glm' objects
>>> x1 <- runif(100, -4, 4)
>>> x2 <- runif(100, -4, 4)
>>> y <- 1 + 2 * x1 + rnorm(100, sd = 3)
>>> dat <- data.frame(y, x1, x2)
>>> glmFit <- glm(y ~ x1 + x2, data = dat)
>>> fn(glmFit, data = dat)
>>> 
>>> # 'aov' objects
>>> quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)
>>> fn(quine.hi, data = quine)
>>> 
>>> 
>>> However, for "negbin" objects returned by glm.nb() the following
>>> problem occurs:
>>> 
>>> quine.nb <- glm.nb(Days ~ .^4, data = quine)
>>> fn(quine.nb, data = quine)
>>> 
>>> 
>>> Any hints to overcome this are greatly appreciated.
>>> 
>>> Thanks in advance,
>>> Dimitris
>>> 
>>> ----
>>> Dimitris Rizopoulos
>>> Ph.D. Student
>>> Biostatistical Centre
>>> School of Public Health
>>> Catholic University of Leuven
>>> 
>>> Address: Kapucijnenvoer 35, Leuven, Belgium
>>> Tel: +32/(0)16/336899
>>> Fax: +32/(0)16/337015
>>> Web: http://med.kuleuven.be/biostat/
>>>     http://www.student.kuleuven.be/~m0390867/dimitris.htm
>>> 
>>> 
>>> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> 
>> 
>> -- 
>> 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
>> 
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>

-- 
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-devel mailing list