Skip to content

Formula parsing and updating

3 messages · Johannes Hüsing, Charles C. Berry

#
Hi all,
I can't come over a problem with formula. Suppose I have a coxmod model
with the following 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
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:
Could anybody give me a hint on my wrongdoings?
#
On Thu, 4 Dec 2008, Johannes Huesing wrote:

            
You need to give us something to reproduce. I get an error when I try
Error in model.matrix.default(newTerms, m) :
   model frame and formula mismatch in model.matrix()

so I do not see how you obtained 'somemod'.

When I protect with I(quant>0), I have no problems obtaining 'fit' nor 
update()ing it:
Call:
coxph(formula = Surv(time, status) ~ I(quant > 0) + strata(sex),
     data = test1)


                    coef exp(coef) se(coef)      z    p
I(quant > 0)TRUE -0.746     0.474     1.27 -0.589 0.56

Likelihood ratio test=0.37  on 1 df, p=0.545  n=6 (1 observation deleted 
due to missingness)


HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
1 day later
#
Charles C. Berry <cberry at tajo.ucsd.edu> [Fri, Dec 05, 2008 at 01:21:41AM CET]:
Odd, since I had no problem entering the formula in this naive way.
I was unaware of I(), and this did the trick for me. Thank you!