Original question
I want to smooth my explanatory variable, something like Speed data of a vehicle, and then use this smoothed values. I searched a lot, and find nothing that directly is my answer.
I know how to calculate the kernel density estimation (density()
or KernSmooth::bkde()
) but I don't know then how to calculate the smoothed values of speed.
Re-edited question
Thanks to @ZheyuanLi, I am able to better explain what I have and what I want to do. So I have re-edited my question as below.
I have some speed measurement of a vehicle during a time, stored as a data frame vehicle
:
t speed
1 0 0.0000000
2 1 0.0000000
3 2 0.0000000
4 3 0.0000000
5 4 0.0000000
. . .
. . .
1031 1030 4.8772222
1032 1031 4.4525000
1033 1032 3.2261111
1034 1033 1.8011111
1035 1034 0.2997222
1036 1035 0.2997222
Here is a scatter plot:
I want to smooth speed
against t
, and I want to use kernel smoothing for this purpose. According to @Zheyuan's advice, I should use ksmooth()
:
fit <- ksmooth(vehicle$t, vehicle$speed)
However, I found that the smoothed values are exactly the same as my original data:
sum(abs(fit$y - vehicle$speed)) # 0
Why is this happening? Thanks!