How to calculate first derivative of time series

眉间皱痕 提交于 2019-12-03 05:57:08

问题


I would calculate the first derivative (dpH/dtime) of time series using two variables, time and pH.

Are there any kind of functions to do this in R or should I compute an extra function to do this?


回答1:


Assuming pH and time are plain vectors try this:

library(pspline)
predict(sm.spline(time, pH), time, 1)



回答2:


You might want to start with stats::deriv or diff.ts as Matt L suggested. Just keep in mind what a professor of mine used to tell all his students: numeric differentiation is known as "error multiplier."

EDIT: To clarify -- what he was warning about was that any noise in your data can throw the derivative estimate way off. It's been said that integration is a low-pass filter and differentiation is a high-pass filter. So, the important thing is to do some smoothing on your data before calculating a derivative. Hence Gabor's excellent suggestion to use predict.spline . But keep in mind that modifying the spline parameters will smooth your data to different levels, so always look at the results to make sure you removed apparent noise but not desired features.




回答3:


Here's a link to "Numerical Differentiation".

http://en.wikipedia.org/wiki/Numerical_differentiation

Here's a link describing a method based on Taylor Series Expansions:

http://ocw.usu.edu/civil_and_environmental_engineering/numerical_methods_in_civil_engineering/ODEsMatlab.pdf



来源:https://stackoverflow.com/questions/14082525/how-to-calculate-first-derivative-of-time-series

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!