Skip to content
Prev 133074 / 398498 Next

Specify a correct formula in R for Piecewise Linear Functions?

On Thu, 3 Jan 2008, zhijie zhang wrote:

            
[volumes of output and gratuitous SAS code deleted]
For the same reason that Thomas replied to my email suggesting a different 
approach than the one I showed you. viz. The spline basis differs from the 
basis vectors he constructed.
Whew! My response would be "don't go there". Fit a richer basis than you 
need and use penalization to damp out unneeded variation in the fit. Or 
use GAMs.

But if you feel you must, you can construct things like

 	bs( pmax( 13, pmin( 25 , x ) )
As above.
You can help youself a lot by taking a few minutes to learn to do in R 
what you did in SAS. Reading the help pages AND running the examples is 
often illuminating. For example,

 	example( pmin )

should give you some helpful hints.

HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901