I have s dataset of
x=c(1600L, 1650L, 1675L, 1700L, 1725L, 1775L, 1800L, 1825L, 1850L,
1875L, 1880L, 1885L, 1900L, 1920L, 1925L, 1930L, 1935L, 1940L,
1945L, 1950L, 1955L, 1960L, 1965L, 1975L, 1980L, 1985L, 1990L,
1995L, 2000L, 2005L, 2010L, 2015L, 2020L, 2025L, 2030L, 2035L,
2040L, 2045L, 2050L, 2055L, 2060L, 2065L, 2070L, 2075L, 2080L,
2085L, 2090L, 2095L, 2100L, 2105L, 2110L, 2115L, 2120L, 2125L,
2130L, 2135L, 2140L, 2145L, 2150L, 2155L, 2160L, 2165L, 2170L,
2175L, 2180L, 2185L, 2190L, 2195L, 2200L, 2225L, 2250L, 2275L,
2300L, 2325L, 2350L, 2400L)
y= c(0.294529, 0.285516, 0.240616, 0.275107, 0.275033, 0.236293,
0.240515, 0.229588, 0.20417, 0.20361, 0.203624, 0.204582, 0.195379,
0.187396, 0.185315, 0.182648, 0.18076, 0.178717, 0.176931, 0.173805,
0.171352, 0.169856, 0.170566, 0.166413, 0.164074, 0.162457, 0.160333,
0.158291, 0.156577, 0.154371, 0.152205, 0.150303, 0.148391, 0.146455,
0.144258, 0.142454, 0.139729, 0.137987, 0.135529, 0.133566, 0.131664,
0.129607, 0.127761, 0.125352, 0.123669, 0.121388, 0.119598, 0.117541,
0.11575, 0.113464, 0.111405, 0.109566, 0.107747, 0.105732, 0.104137,
0.102337, 0.100538, 0.099007, 0.097542, 0.096187, 0.095008, 0.094473,
0.094044, 0.093378, 0.093201, 0.093218, 0.093572, 0.094112, 0.094962,
0.102078, 0.111409, 0.120824, 0.128211, 0.137644, 0.144049, 0.16133
)
I am trying to use a spline in R to interpolate a function of y on x and back out some specific points with equal spacing with a range of numbers before and after the boundary of x. So I write:
fineX <- seq(min(x)-500, max(x)+500 , 1)
interp <- spline(x,y , xout= fineX , method = c("natural"))
The interpolation is fine like the image below:
plot(x,y)
lines(interp)
But the extrapolation with this method is stupid as you can see in the picture below:
plot(fineX, interp$y)
In the interpolation, the function before roughly x=2000 is clearly decreasing but you can see that the extrapolation before x=1600 becomes increasing.
The smooth.spline
function gives a better result but it do not let me to choose the xout
points I want (or i don't know how to choose!).
What can I do to have a good interpolation (not linear) beyond the boundary of x and have the xout
points that I need?