[R] rms::ols & I(.) in formulas

Frank E Harrell Jr f.harrell at Vanderbilt.Edu
Fri Jul 2 15:36:38 CEST 2010


ols has always been fussy about this.  And don't use poly; use pol with 
rms/Design.

Frank

On 07/02/2010 07:28 AM, Peter Ehlers wrote:
> Otto,
>
> The current version of ols() is fairly fussy about the
> way the predictors are used. I'm not fond of the I()
> construction anyway and so I would either use poly()
> or define a new predictor as you suggest in your
> original post.
>
> See also this thread:
>
> https://stat.ethz.ch/pipermail/r-help/2010-June/241587.html
>
>
> -Peter Ehlers
>
>
> On 2010-07-02 4:51, Otto Kässi wrote:
>> Hi, Lexi!
>>
>> I am aware that lm() is the standard way to do ols regression in R.
>> The reason why I opted for rms::ols() is that later on in my work I
>> need some rms functions which are not available for lm().
>>
>> In retrospect, I should have mentioned this already in my original
>> post. Nonetheless, thanks for a good suggestion :-)
>>
>> Br,
>> OK
>>
>>
>> On Fri, Jul 2, 2010 at 1:35 PM, Setlhare
>> Lekgatlhamang<SetlhareL at bob.bw> wrote:
>>> Try this
>>> Lm(y~X + I(X^2)), data=dd) # this runs OLS regression and it worked
>>> for me
>>>
>>> Hope it helps
>>>
>>> Lexi
>>>
>>> -----Original Message-----
>>> From: r-help-bounces at r-project.org
>>> [mailto:r-help-bounces at r-project.org] On Behalf Of Otto Kässi
>>> Sent: Thursday, July 01, 2010 3:28 PM
>>> To: r-help at r-project.org
>>> Subject: [R] rms::ols& I(.) in formulas
>>>
>>> Dear R-helpers,
>>>
>>> To start I would like to thank Prof. Harrell for package rms. It is
>>> one of the most useful packages for R that I have encountered.
>>>
>>> Turning to my problem, I encountered a surprising problem when working
>>> with rms::ols. It seems that insulating terms in a formula by using
>>> I() to insulate terms in a formula seems to occasionally create a bug.
>>> See the example below:
>>> library(rms)
>>> x<- rnorm(100)
>>> y<- rnorm(100)
>>> dd<- data.frame(cbind(x,y))
>>> ols(y ~ x + I(x^2), data=dd)
>>>
>>> ols() function gives the error:
>>> Error in if (!length(fname) || !any(fname == zname)) { :
>>> missing value where TRUE/FALSE needed
>>>
>>> Has anyone else encountered something similar? Is this a bug or does
>>> this behavior have a reason?
>>>
>>> There are of course trivial workarounds: one can either use poly(x, 2)
>>> or save x^2 as a new column to dd, but trying to debug this was a
>>> pain.
>>>
>>> With kind regards,
>>> Otto Kassi
>>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Frank E Harrell Jr   Professor and Chairman        School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list