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. Regards, Jim McDermott
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
The derivative of a quadratic B-spline is the centered finite difference of a linear B-spline, so if you have access to the underlying coefficients of the B-spline expansion you can do this easily. I believe the coefficients are passed as the $coef component of the return value. Reid Huntsinger -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of James McDermott Sent: Tuesday, July 19, 2005 2:54 PM To: r-help at stat.math.ethz.ch Subject: [R] Taking the derivative of a quadratic B-spline 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. Regards, Jim McDermott ______________________________________________ R-help at 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