Re: [R] Taking the derivative of a quadratic B-spline

From: James McDermott <jp.mcdermott_at_gmail.com>
Date: Thu 21 Jul 2005 - 09:31:33 EST

Thanks a lot for the input on this Professor Murdoch. I really appreciate all the help.

Regards,
Jim

On 7/20/05, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> James McDermott wrote:
> > Would the unique quadratic defined by the three points be the same
> > curve as the curve predicted by a quadratic B-spline (fit to all of
> > the data) through those same three points?
>
> Yes, if you restrict attention to an interval between knots. You'll
> need to re-evaluate it for each such interval (but since quadratic
> splines are continuous, you can reuse evaluations at the knots, and you
> just need one new point in each interval).
>
> From a practical point of view, you need to make sure that COBS really
> is giving you a quadratic spline and really is reporting all of the
> knots correctly. Watch out for coincident knots (zero length
> intervals); you don't care about the derivative on those, but they might
> cause overflows in some calculations.
>
> Duncan Murdoch
> >
> > Jim
> >
> > On 7/19/05, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> >
> >>On 7/19/2005 3:34 PM, James McDermott wrote:
> >>
> >>>I wish it were that simple (perhaps it is and I am just not seeing
> >>>it). The output from cobs( ) includes the B-spline coefficients and
> >>>the knots. These coefficients are not the same as the a, b, and c
> >>>coefficients in a quadratic polynomial. Rather, they are the
> >>>coefficients of the quadratic B-spline representation of the fitted
> >>>curve. I need to evaluate a linear combination of basis functions and
> >>>it is not clear to me how to accomplish this easily. I was hoping to
> >>>find an alternative way of getting the derivatives.
> >>
> >>I don't know COBS, but doesn't predict just evaluate the B-spline? The
> >>point of what I posted is that the particular basis doesn't matter if
> >>you can evaluate the quadratic at 3 points.
> >>
> >>Duncan Murdoch
> >>
> >>
> >>>Jim McDermott
> >>>
> >>>On 7/19/05, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> >>>
> >>>>On 7/19/2005 2:53 PM, James McDermott wrote:
> >>>>
> >>>>>Hello,
> >>>>>
> >>>>>I have been trying to take the derivative of a quadratic B-spline
> >>>>>obtained by using the COBS library. What I would like to do is
> >>>>>similar to what one can do by using
> >>>>>
> >>>>>fit<-smooth.spline(cdf)
> >>>>>xx<-seq(-10,10,.1)
> >>>>>predict(fit, xx, deriv = 1)
> >>>>>
> >>>>>The goal is to fit the spline to data that is approximating a
> >>>>>cumulative distribution function (e.g. in my example, cdf is a
> >>>>>2-column matrix with x values in column 1 and the estimate of the cdf
> >>>>>evaluated at x in column 2) and then take the first derivative over a
> >>>>>range of values to get density estimates.
> >>>>>
> >>>>>The reason I don't want to use smooth.spline is that there is no way
> >>>>>to impose constraints (e.g. >=0, <=1, and monotonicity) as there is
> >>>>>with COBS. However, since COBS doesn't have the 'deriv =' option, the
> >>>>>only way I can think of doing it with COBS is to evaluate the
> >>>>>derivatives numerically.
> >>>>
> >>>>Numerical estimates of the derivatives of a quadratic should be easy to
> >>>>obtain accurately. For example, if the quadratic ax^2 + bx + c is
> >>>>defined on [-1, 1], then the derivative 2ax + b, has 2a = f(1) - f(0) +
> >>>>f(-1), and b = (f(1) - f(-1))/2.
> >>>>
> >>>>You should be able to generalize this to the case where the spline is
> >>>>quadratic between knots k1 and k2 pretty easily.
> >>>>
> >>>>Duncan Murdoch
> >>>>
> >>
> >>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 21 09:42:03 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:53 EST