1

I would like to do a spline interpolation, but not the general way.

My data is unevenly distributed and filled with gaps.

data to interpolate on

What I would like the spline to do is not take into account a certain number of observations for interpolation but a certain window in time, eg. 10 years.

Does anyone have any idea what function to use, because the following code

name="baradla_l"
data=read.table(file=paste(name,".csv", sep=""), sep=";", header=T)

spline_fun=function(data_column, time_column, n){
x=time_column
y=data_column
splineil=spline(x,y,n)
return(splineil)
}

result=spline_fun(data[,2], data[,1], 100)
plot(result$x,result$y)
plot(result$x,result$y, type="l")
points(data[,1], data[,2],col="red")

does not seem to do the trick an I do not know what to meddle with.

The data as required:

data <- structure(list(date = 1899:2012, d18O = c(NA, NA, NA, NA, NA, 
NA, NA, -7.41784, -7.04786, NA, -7.36332, NA, -8.29839, NA, -8.16167, 
NA, -7.71389, NA, -7.02616, -7.4196, -6.94689, NA, NA, -6.75823, 
-7.77452, NA, NA, -7.67965, -7.38529, NA, -6.83634, -7.69333, 
-7.12526, -8.05093, -7.54384, -7.96867, -7.25356, NA, -7.63551, 
-7.05296, -7.3081, -6.55707, -6.58208, -6.38919, -7.74052, -8.13889, 
NA, -7.34376, -7.09647, -7.18969, -7.27335, NA, -7.50431, NA, 
-7.67371, NA, NA, NA, NA, NA, -7.51227, NA, -7.68565, NA, -7.14066, 
NA, NA, -7.66135, NA, -7.41493, NA, NA, -7.16749, NA, NA, -7.52235, 
NA, NA, -7.57791, NA, NA, -6.83033, NA, -7.63777, NA, NA, -7.62713, 
-7.51122, NA, NA, -7.80703, NA, -7.41753, -8.21293, NA, NA, NA, 
NA, -7.96513, NA, -7.66993, NA, -7.45512, NA, -6.96408, NA, -7.15501, 
NA, -7.87707, -8.28378, NA, -7.75944, NA, NA)), .Names = c("date", 
"d18O"), class = "data.frame", row.names = c(NA, -114L))
chinsoon12
  • 25,005
  • 4
  • 25
  • 35
  • should I try to do something with the xout argument? – Istvan Gabor Hatvani Apr 19 '16 at 14:29
  • you can filter the data before you pass it into spline_fun. you might want to `dput(data)` and insert the result in the question if its not too large – chinsoon12 Apr 20 '16 at 02:10
  • It can be downloaded from the "data to interpolate on" line in blue, but I attached it to the question as well. Thank you! – Istvan Gabor Hatvani Apr 21 '16 at 06:30
  • are you looking to perform spline interpolation for a rolling 10Y window? – chinsoon12 Apr 21 '16 at 07:33
  • The point is that instead of the spline taking n data into account for interpolating it should use a fix window based on the dates. Therefore, If I say that I would like the spline to interpolate the data in a 10 yr window for example, in the first i would only take 8 points into account than 7, than 5, depending on the number of data in the certain window. – Istvan Gabor Hatvani Apr 21 '16 at 08:14
  • you can use `length(x)` instead of passing in a `n` argument – chinsoon12 Apr 21 '16 at 08:48
  • @chinson12 It did not really do the trick. I was thinking about determining the window by a sequence of some sort. The point is that the function should interpolate based on a specified number of values in the first column and using the values attributed to that particular time window in the second column no matter how many there are. – Istvan Gabor Hatvani Apr 21 '16 at 11:06

0 Answers0