[R] newbie problem using Design.rcs

Frank E Harrell Jr f.harrell at vanderbilt.edu
Tue Dec 23 15:41:16 CET 2008


In addition to David's excellent response, I'll add that your problems 
seem to be statistical and not programming ones.  I recommend that you 
spend a significant amount of time with a good regression text or course 
before using the software.  Also, with Design you can find out the 
algebraic form of the fit:

f <- ols(y ~ rcs(x,3), data=mydata)
Function(f)

Frank


David Winsemius wrote:
> 
> On Dec 22, 2008, at 11:38 PM, sp wrote:
> 
>> Hi,
>>
>> I read data from a file. I'm trying to understand how to use 
>> Design.rcs by using simple test data first. I use 1000 integer values 
>> (1,...,1000) for x (the predictor) with some noise (x+.02*x) and I set 
>> the response variable y=x. Then, I try rcs and ols as follows:
>>
> Not sure what sort of noise that is.
> 
>> m = ( sqrt(y1) ~ ( rcs(x1,3) ) ); #I tried without sqrt also
>> f = ols(m, data=data_train.df);
>> print(f);
>>
>> [I plot original x1,y1 vectors and the regression as in
>> y <- coef2[1] + coef2[2]*x1 + coef2[3]*x1*x1]
> 
> That does not look as though it would capture the structure of a 
> restricted **cubic** spline. The usual method in Design for plotting a 
> model prediction would be:
> 
> plot(f, x1 = NA)
> 
>>
>>
>> But this gives me a VERY bad fit:
>> "
> 
> Can you give some hint why you consider this to be a "VERY bad fit"? It 
> appears a rather good fit to me, despite the test case apparently not 
> being construct with any curvature which is what the rcs modeling 
> strategy should be detecting.
> 


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



More information about the R-help mailing list