From: William Valdar <valdar_at_well.ox.ac.uk>

Date: Fri 21 Oct 2005 - 02:13:58 EST

}

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Oct 21 03:38:09 2005

Date: Fri 21 Oct 2005 - 02:13:58 EST

Dear R help,

I've encountered a problem with survreg's anova(). I am currently writing general code to fit a variety of models using different fitting functions. Here's a simple example of what I'm trying to do:

---begin code---

# general function to analyse data

analyse.data <- function(formula, FUN, data, ...)
{

fit <- FUN(formula, data=data, ...) anova(fit)

}

---end code---

In theory I should be able to call analyse.data() specifying FUN as I please. In practice FUN=lm and FUN=glm work but FUN=survreg does not. For example:

---begin code---

library(survival)

data <- data.frame(

y = rexp(100, rate=1), status = rbinom(100,1,prob=0.8), x = rnorm(100))

# analyse as lm

formula <- as.formula("y ~ x")

analyse.data(formula, FUN=lm, data=data)

# works!

# analyse as glm

formula <- as.formula("y ~ x")

analyse.data(formula, FUN=glm, data=data, family="Gamma")

# works!

# analyse as survival

formula <- as.formula("Surv(y, status) ~ x")
analyse.data(formula, survreg, data=data)

# Error in eval(expr, envir, enclos) : couldn't find function "FUN"

# check survival works outside function

fit <- survreg(formula, data)

anova(fit)

# works!

---end code---

I suspect this is something to do with parent frames in anova.survreg(). However, although R mentions anova.survreg on traceback(), the code for this function seems not to be viewable.

I couldn't find any other positings about this. Any suggestions?

Note: I am using R version 2.1.1 and "survival" package version 2.18.

Many thanks,

William

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Dr William Valdar ++44 (0)1865 287 717 Wellcome Trust Centre valdar@well.ox.ac.uk for Human Genetics, Oxford www.well.ox.ac.uk/~valdar ______________________________________________R-help@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 Received on Fri Oct 21 03:38:09 2005

*
This archive was generated by hypermail 2.1.8
: Sun 23 Oct 2005 - 19:13:46 EST
*