Re: [R] Re: [S] Labels wrong with lrm

About this list Date view Thread view Subject view Author view Attachment view

From: Thomas Lumley (
Date: Sun 29 Jul 2001 - 05:12:04 EST

Message-id: <>

On Sat, 28 Jul 2001 wrote:

> Dear Jan,
> Thank you very much for your excellent description of the
> problem and the self-contained test code. This is a
> problem that I've been meaning to either document better
> or solve for some time. The root of the problem is with
> the builtin S-Plus terms.inner function:
> > attr(terms.inner(asthma ~ pol(age,kx) + smok),'variables')
> expression(age, kx, smok)
> You can see that terms.inner inappropriately includes kx
> as an independent variable as it does not know that
> the first argument to pol is the special variable.
> When a constant replaces kx, all is well.

I think this can't be fixed in general. There is simply no way to know
whether pol(age,kx) contains two variables (like interaction(age,kx)) or
one variable, and if so, which is the variable and which the parameter.

The termplot() function has a function carrier.names() that guesses that
the first argument is the only variable, which is a useful heuristic until
you have log(0.5+x) as a term.

You can get the results of all.vars broken down by term like

> f
I(log(0.5 + x)) ~ pol(age, kx) + ns(sbp, df) + factor(race, labels =
races) +
> av<-all.vars(f)
> sapply(attr(terms(f),"term.labels"),function(term)
$"pol(age, kx)"
[1] "age" "kx"

$"ns(sbp, df)"
[1] "sbp" "df"

$"factor(race, labels = races)"
[1] "race" "races"

[1] "sex"

(actually you only get the RHS of the formula, but that shouldn't be hard
to fix)

You might also look at how nlme and Jim Lindsey's nonlinear models
functions solve the question of whether a name refers to a a variable or a


Thomas Lumley Asst. Professor, Biostatistics University of Washington, Seattle

r-help mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:

About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:04 EST