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

Peter Ehlers ehlers at ucalgary.ca
Fri Jul 2 14:28:54 CEST 2010


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
>>



More information about the R-help mailing list