[R] newbie problem using Design.rcs
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Tue Dec 23 23:49:05 CET 2008
sp wrote:
> Dr. Harrell,
>
> Thanks for your patient replies. I've two more questions:
>
> 1) Is your book appropriate for beginners or is it more for advanced users?
It is in the middle of those two.
>
> 2) f <- ols(y ~ rcs(x,3), data=mydata)
> Function(f)
> does not produce anything for me (i.e.) it's empty.
Here's a test I just ran
> y <- rnorm(100)
> x <- runif(100)
> f <- ols(y ~ rcs(x,3))
> Function(f)
function(x = NA) {-0.18307779+0.91343138*
x-2.1908543*pmax(x-0.10568075,0)^3+3.8312836*pmax(x-0.45620427,0)^3-1.6404293*pmax(x-0.92434146,0)^3
}
<environment: 0x2ca30a8>
If you are doing this inside { } you will need to do print(Function(f))
Note this is a simplified version of the rcs with 2 redundant terms to
avoid writing in terms of differences in cubes.
Frank
>
> Sincerely,
> sp
>
>
> --- On Tue, 12/23/08, Frank E Harrell Jr <f.harrell at vanderbilt.edu> wrote:
>
>> From: Frank E Harrell Jr <f.harrell at vanderbilt.edu>
>> Subject: Re: [R] newbie problem using Design.rcs
>> To: to_rent_2000 at yahoo.com
>> Cc: "David Winsemius" <dwinsemius at comcast.net>, r-help at r-project.org
>> Date: Tuesday, December 23, 2008, 4:57 PM
>> sp wrote:
>
>>> 2. I didn't have x^3 b/c that co-efficient happens
>> to be zero in this fitting.
>>
>> That's strange.
>>
>>> Also, I'm forced to call win.graph() before my
>> first plot() to see the first plot. Is that normal?
>>
>> no
>>
>>> I started with testing it on just x,y dimensions so
>> that I can visually evaluate the fitting. I tried y=x, y=x^2
>> etc, adding Gaussian noise each time (to the y).
>>> I plot original x,y and x,y' where y' is
>> calculated using the co-efficients returned by rcs. I find
>> that the regression curve differs from the actual points by
>> as high as 10^5 with 3 knots and roughly -10^5 with 4 knots
>> as I make y=x^2, y=x^3....
>>
>> wait until you have studied regression
>>
>> Frank
>>
>>
>>> If this is NOT a good way to test fitting, could you
>> pls tell me a better way?
>>> Respectfully,
>>> sp
>
>
>
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list