Dear All, I've been?searching for?appropriate codes to compute the rate of change and the curvature?of ?nonparametric regression model whish was denoted by a smooth function?but?unfortunately?don't manage to?do?it. I presume that such characteristics from a smooth curve can be determined by the first and second derivative operators. The following are the example of fitting a nonparametric regression model via smoothing spline function from the Help file in R. ####################################################### attach(cars) plot(speed, dist, main = "data(cars)? &? smoothing splines") cars.spl <- smooth.spline(speed, dist) lines(cars.spl, col = "blue") lines(smooth.spline(speed, dist, df=10), lty=2, col = "red") legend(5,120,c(paste("default [C.V.] => df =",round(cars.spl$df,1)),"s( * , df = 10)"), col = c("blue","red"), lty = 1:2, bg='bisque') detach() ####################################################### Could someone please advice me?the?appropriate way to determine such derivatives on the curves which were fitted by the function above and would like to thank you in advance. Cheers Fir?
Please keep in mind this question has absolutely nothing to do with finance, and therefore needs to instead be directed to R-help. Thanks in advance for keeping the R-finance list on topic. Jeff On Fri, Apr 2, 2010 at 3:36 AM, FMH <kagba2006 at yahoo.com> wrote:> > Dear All, > > I've been?searching for?appropriate codes to compute the rate of change and the curvature?of ?nonparametric regression model whish was denoted by a smooth function?but?unfortunately?don't manage to?do?it. I presume that such characteristics from a smooth curve can be determined by the first and second derivative operators. > > The following are the example of fitting a nonparametric regression model via smoothing spline function from the Help file in R. > > ####################################################### > attach(cars) > plot(speed, dist, main = "data(cars)? &? smoothing splines") > cars.spl <- smooth.spline(speed, dist) > lines(cars.spl, col = "blue") > lines(smooth.spline(speed, dist, df=10), lty=2, col = "red") > legend(5,120,c(paste("default [C.V.] => df =",round(cars.spl$df,1)),"s( * , df = 10)"), col = c("blue","red"), lty = 1:2, bg='bisque') > detach() > > ####################################################### > > > Could someone please advice me?the?appropriate way to determine such derivatives on the curves which were fitted by the function above and would like to thank you in advance. > > Cheers > Fir > > > > > > _______________________________________________ > R-SIG-Finance at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions should go. >-- Jeffrey Ryan jeffrey.ryan at insightalgo.com ia: insight algorithmics www.insightalgo.com
Please learn how to use `RsiteSearch' before posting questions to the list: RSiteSearch("derivative smooth function") This should have provided you with plenty of solutions. Ravi. ____________________________________________________________________ Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu ----- Original Message ----- From: FMH <kagba2006 at yahoo.com> Date: Friday, April 2, 2010 4:39 am Subject: [R] Derivative of a smooth function To: r-help at r-project.org Cc: r-sig-finance at stat.math.ethz.ch> Dear All, > > I've been?searching for?appropriate codes to compute the rate of > change and the curvature?of ?nonparametric regression model whish was > denoted by a smooth function?but?unfortunately?don't manage to?do?it. > I presume that such characteristics from a smooth curve can be > determined by the first and second derivative operators. > > The following are the example of fitting a nonparametric regression > model via smoothing spline function from the Help file in R. > > ####################################################### > attach(cars) > plot(speed, dist, main = "data(cars)? &? smoothing splines") > cars.spl <- smooth.spline(speed, dist) > lines(cars.spl, col = "blue") > lines(smooth.spline(speed, dist, df=10), lty=2, col = "red") > legend(5,120,c(paste("default [C.V.] => df > =",round(cars.spl$df,1)),"s( * , df = 10)"), col = c("blue","red"), > lty = 1:2, bg='bisque') > detach() > > ####################################################### > > > Could someone please advice me?the?appropriate way to determine such > derivatives on the curves which were fitted by the function above and > would like to thank you in advance. > > Cheers > Fir? > > > > > > ______________________________________________ > R-help at r-project.org mailing list > > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code.
While this doesn't answer your question, I want to let you know that there is a proposal for a related improvement within R that will let users compute (numerically) the derivatives, of any order, of a given function inside of R. In your case, this means that you will write the smooth spline function, symbolically f(x), that will interpolate between the points. Using Automatic Differentiation, the proposed solution, will automatically let you find f'(x), f''(x), etc.. by using the same function but overloading the meaning of the arithmetic operators and mathematical functions to act upon a special data type. The initial idea <http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2010:adinr>came from Prof. John Nash who suggested bringing the ability of Automatic Differentiation to R. We both have, since, collaborated to bring out adetailed proposal<http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/quantumelixir/t126989852709>outlining the various features to be implemented. Note that, this is being planned to be implemented as part of Google's Summer of Code program for this year. So, should our proposal be selected, much more than simple second derivative computation can be accomplished from within R. Regards, Chillu On Fri, Apr 2, 2010 at 2:06 PM, FMH <kagba2006@yahoo.com> wrote:> > Dear All, > > I've been searching for appropriate codes to compute the rate of change and > the curvature of nonparametric regression model whish was denoted by a > smooth function but unfortunately don't manage to do it. I presume that such > characteristics from a smooth curve can be determined by the first and > second derivative operators. > > The following are the example of fitting a nonparametric regression model > via smoothing spline function from the Help file in R. > > ####################################################### > attach(cars) > plot(speed, dist, main = "data(cars) & smoothing splines") > cars.spl <- smooth.spline(speed, dist) > lines(cars.spl, col = "blue") > lines(smooth.spline(speed, dist, df=10), lty=2, col = "red") > legend(5,120,c(paste("default [C.V.] => df =",round(cars.spl$df,1)),"s( * , > df = 10)"), col = c("blue","red"), lty = 1:2, bg='bisque') > detach() > > ####################################################### > > > Could someone please advice me the appropriate way to determine such > derivatives on the curves which were fitted by the function above and would > like to thank you in advance. > > Cheers > Fir > > > > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hi Fir, you can alternatively use local regression, implemented in the package locfit, which can also estimate derivatives: library(locfit) attach(cars) # main fit fit <- locfit( dist ~ speed ) # fit 1st derivative fitd <- locfit( dist ~ speed , deriv =1) # plots... plot(speed, dist ) lines(fit) lines(fitd, col="red") Hope this helps, Julien On Fri, Apr 2, 2010 at 2:06 PM, FMH <kagba2006@yahoo.com> wrote:> > Dear All, > > I've been searching for appropriate codes to compute the rate of change and > the curvature of nonparametric regression model whish was denoted by a > smooth function but unfortunately don't manage to do it. I presume that such > characteristics from a smooth curve can be determined by the first and > second derivative operators. > > The following are the example of fitting a nonparametric regression model > via smoothing spline function from the Help file in R. > > ####################################################### > attach(cars) > plot(speed, dist, main = "data(cars) & smoothing splines") > cars.spl <- smooth.spline(speed, dist) > lines(cars.spl, col = "blue") > lines(smooth.spline(speed, dist, df=10), lty=2, col = "red") > legend(5,120,c(paste("default [C.V.] => df =",round(cars.spl$df,1)),"s( * , > df = 10)"), col = c("blue","red"), lty = 1:2, bg='bisque') > detach() > > ####################################################### > > > Could someone please advice me the appropriate way to determine such > derivatives on the curves which were fitted by the function above and would > like to thank you in advance. > > Cheers > Fir > > > > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]