[R] Formula parsing and updating

Johannes Huesing johannes at huesing.name
Thu Dec 4 22:00:07 CET 2008


Hi all,
I can't come over a problem with formula. Suppose I have a coxmod model
with the following formula:

> somemod$formula
Surv(lebzeit, tot == 1) ~ sex + (alter >= 65) + diff3k + zelltyp_k_c + 
    q_nuc_3k + kar_k80_g80 + stadium

and I want to drop the stadium explanatory variable from the model with

> update(somemod, ". ~ . - stadium")

I get the following messages:

Fehler in coxph(formula = Surv(lebzeit, tot == 1) ~ sex + alter >= 65 +  : 
  No (non-missing) observations
Zusätzlich: Warning messages:
1: In Ops.factor(sex, alter) : + not meaningful for factors
2: In Ops.factor(65, diff3k) : + not meaningful for factors
3: In Ops.factor(65 + diff3k, zelltyp_k_c) : + not meaningful for factors
4: In Ops.factor(65 + diff3k + zelltyp_k_c, q_nuc_3k) :
  + not meaningful for factors
5: In Ops.factor(65 + diff3k + zelltyp_k_c + q_nuc_3k, kar_k80_g80) :
  + not meaningful for factors

What seems to happen is that "alter >= 65" is not parsed as an entity.

It does not look as a problem with the environment to me, as is outlined 
in http://developer.r-project.org/nonstandard-eval.pdf, rather a parsing 
problem.

By contrast, the following works like a charm:

> x <- runif(50)
> y <- rnorm(50)+x
> regmod <- lm(y ~ x)
> update(regmod, " . ~ . + (ifelse(x>.5, 0, x))")

Could anybody give me a hint on my wrongdoings?

-- 
Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes at huesing.name  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")



More information about the R-help mailing list