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

Otto Kässi otto.kassi at gmail.com
Fri Jul 2 12:51:47 CEST 2010


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.
>
>
>
> DISCLAIMER:
> Sample Disclaimer added in a VBScript.
>



More information about the R-help mailing list