I'm using approx function on 2 identical list :
unlist(fp_st_4_main[[1]],fp_st_4_main_extr[[1]]) 0.02438017
0.03842975 0.04504132 0.07231405 0.08884298 0.09917355 0.11363636 0.12644628 0.13966942 0.15289256 0.16818182 0.17190083 0.23471074 0.25330579 0.26818182 0.29090909
unlist(fp_st_3_main[[1]],fp_st_3_main_extr[[1]]) [1] 0.02438017 0.03842975 0.04504132 0.07231405 0.08884298 0.09917355 0.11363636 0.12644628 [9] 0.13966942 0.15289256 0.16818182 0.17190083 0.23471074 0.25330579 0.26818182 0.29090909
unlist(tp_st_4_main[[1]],tp_st_4_main_extr[[1]])
0.4625 0.4625 0.4625 0.4625 0.4625 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750
unlist(tp_st_3_main[[1]],tp_st_3_main_extr[[1]])
[1] 0.4625 0.4625 0.4625 0.4625 0.4625 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750 0.5750
As the list are absolutely the same I'm expecting R to preform the same interpolation on both of them :
my_out=seq(0,1,0.01)
intrapulation_my=approx(c(0,fp_st_4_main[[1]],fp_st_4_main_extr[[1]],1),c(0,tp_st_4_main[[1]],tp_st_4_main_extr[[1]],1), method = "linear", xout =my_out )
intrapulation_st_4_main_tp_my=intrapulation_my$y
intrapulation_st_4_main_fp_my=intrapulation_my$x
intrapulation_my=approx(c(0,fp_st_3_main[[1]],fp_st_3_main_extr[[1]],1), c(0,tp_st_3_main[[1]],tp_st_3_main_extr[[1]],1), method = "linear", xout =my_out )
intrapulation_st_3_main_tp_my=intrapulation_my$y
intrapulation_st_3_main_fp_my=intrapulation_my$x
But the result Im getting for them is different :
intrapulation_st_4_main_tp_my
[1] 0.0000000 0.1897034 0.3794068 0.4625000 0.4625000 0.4625000 0.4625000 0.4625000 0.4625000
[10] 0.4751000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000
[19] 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000
[28] 0.5750000 0.5750000 0.5750000 0.5833557 0.5925469 0.6017382 0.6109294 0.6201206 0.6293119
[37] 0.6385031 0.6476944 0.6568856 0.6660769 0.6752681 0.6844593 0.6936506 0.7028418 0.7120331
[46] 0.7212243 0.7304155 0.7396068 0.7487980 0.7579893 0.7671805 0.7763718 0.7855630 0.7947542
[55] 0.8039455 0.8131367 0.8223280 0.8315192 0.8407105 0.8499017 0.8590929 0.8682842 0.8774754
[64] 0.8866667 0.8958579 0.9050492 0.9142404 0.9234316 0.9326229 0.9418141 0.9510054 0.9601966
[73] 0.9693878 0.9785791 0.9877703 0.9969616 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[82] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[91] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[100] 1.0000000 1.0000000
intrapulation_st_3_main_tp_my
[1] 0.0000000 0.1897034 0.3794068 0.4625000 0.4625000 0.4625000 0.4625000 0.4625000 0.4625000
[10] 0.4751000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000
[19] 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000 0.5750000
[28] 0.5750000 0.5750000 0.5750000 0.6163717 0.6618805 0.7073894 0.7528982 0.7984071 0.8439159
[37] 0.8894248 0.9349336 0.9804425 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[46] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[55] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[64] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[73] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[82] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[91] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
[100] 1.0000000 1.0000000
What I don't understand is how can it be ? As i understand the interulation works like this :
Given two points (x_1, y_1) and (x_2, y_2), where x_1 < x_2, the equation of the straight line passing through these points can be expressed as:
y=mx+b
where:
\begin{itemize}
\item $m$ is the slope of the line, given by $m = \frac{y_2 - y_1}{x_2 - x_1}$
\item $b$ is the y-intercept of the line, given by $b = y_1 - mx_1$
\end{itemize}
To perform linear interpolation between two points x_1 and x_2, where x_1 < x < x_2, we can substitute x into the equation of the straight line to estimate the corresponding y value. so it is supposed to return the same values for Y but it returns me different values , how can that be ?