R中的信号包在interp1中是否存在错误?

时间:2019-03-07 20:06:46

标签: r interpolation

我一直在使用信号R包中的interp1一段时间;但是,今天我注意到了一些可能是错误的东西。真的是错误,还是我犯错了?

让我们从一个很好的例子开始。假设:

x_interp = seq(1, 5, 0.5)
x_base=1:5
y_base=2:6

然后,interp1函数返回正确的值,其中结果中的每个条目对应于x_interp中的每个条目:

interp1( x=x_base, y=y_base, xi= x_interp, method="linear"  )
[1] 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0

但是,当我对较大的向量执行相同操作时,interp1的输出顺序似乎不正确(值正确):

x_interp2 = c(147.25, 147.00, 146.75, 146.50, 145.25, 145.00, 144.75, 144.50, 143.25, 143.00, 142.75, 142.50
, 141.25, 141.00, 140.75, 140.50, 139.25, 139.00, 138.75, 138.50, 137.25, 137.00, 136.75, 136.50
, 136.25, 135.25, 135.00, 134.75, 134.50, 133.25, 133.00, 132.75, 132.50, 131.25, 131.00, 130.75
, 130.50, 129.25, 129.00, 128.75, 128.50, 127.25, 127.00, 126.75, 126.50, 126.25, 125.25, 125.00
, 124.75, 124.50, 123.25, 123.00, 122.75, 122.50, 121.25, 121.00, 120.75, 120.50, 119.25, 119.00
, 118.75, 118.50, 117.25, 117.00, 116.75, 116.50, 116.25, 115.25, 115.00, 114.75, 114.50, 113.25
, 113.00, 112.75, 112.50, 111.25, 111.00, 110.75, 110.50, 109.25, 109.00, 108.75, 108.50, 107.25
, 107.00, 106.75, 106.50, 105.25, 105.00, 104.75, 104.50, 103.25, 103.00, 102.75, 102.50, 101.25
, 101.00, 100.75, 100.50, 99.25, 99.00, 98.50, 97.25, 97.00, 96.75, 96.50, 95.25, 95.00
, 94.75, 94.50, 93.25, 93.00, 92.75, 92.50, 91.25, 91.00, 90.75, 90.50, 89.25, 89.00
, 88.75, 88.50, 88.25, 87.00, 86.75, 86.50, 85.25, 85.00, 84.50, 83.25, 83.00, 82.75
, 82.50, 81.00, 80.75, 80.50, 79.25, 79.00, 78.75, 78.50, 77.00, 76.75, 76.50, 75.25
, 75.00, 74.75, 74.50, 73.25, 73.00, 72.75, 72.50, 71.00, 70.75, 70.50, 69.25, 68.75
, 68.50, 67.25, 66.75, 66.50, 65.25, 65.00, 64.50, 63.25, 63.00, 62.75, 62.50, 61.25
, 61.00, 60.75, 60.50, 59.25, 59.00, 58.75, 58.50, 57.00, 56.75, 56.50, 55.00, 54.75
, 54.50, 53.00, 52.75, 52.50, 51.25, 51.00, 50.75, 50.50, 49.25, 49.00, 48.75, 48.50
, 48.25, 47.00, 46.75, 46.50, 45.25, 45.00, 44.75, 44.50, 43.00, 42.75, 42.50, 41.00
, 40.75, 40.50, 40.25, 39.00, 38.50, 37.25, 36.75, 36.50, 35.00, 34.75, 34.50, 33.25
, 33.00, 32.50, 31.00, 30.75, 30.50, 29.25, 29.00, 28.75, 28.50, 28.25, 27.00, 26.75
, 26.50, 25.25, 24.75, 24.50, 23.25, 23.00, 22.75, 22.50, 21.25, 21.00, 20.75, 20.50
, 19.25, 19.00, 18.75, 18.50, 17.25, 17.00, 16.75, 16.50, 15.25, 15.00, 14.75, 14.50
, 13.25, 13.00, 12.75, 12.50, 11.25, 11.00, 10.50, 9.25, 9.00, 8.50, 7.25, 7.00
, 6.50, 5.25, 4.75, 4.50, 3.00, 2.75, 2.50, 1.75, 1.50, 1.00, 0.25, 0.00)

x_base2 = c(147.25, 144.50, 142.50, 140.50, 138.50, 136.50, 134.50, 132.50, 130.50, 128.50, 126.50, 124.50
, 122.50, 120.50, 118.50, 116.50, 114.50, 112.50, 110.50, 108.50, 106.50, 104.50, 102.50, 100.50
, 98.50, 96.50, 94.50, 92.50, 90.50, 88.50, 86.50, 84.50, 82.50, 80.50, 78.50, 76.50
, 74.50, 72.50, 70.50, 68.50, 66.50, 64.50, 62.50, 60.50, 58.50, 56.50, 54.50, 52.50
, 50.50, 48.50, 46.50, 44.50, 42.50, 40.50, 38.50, 36.50, 34.50, 32.50, 30.50, 28.50
, 26.50, 24.50, 22.50, 20.50, 18.50, 16.50, 14.50, 12.50, 10.50, 8.50, 6.50, 4.50
, 2.50, 1.00, 0.00)

y_base2 = c(20.96, 20.96, 19.96, 16.77, 13.71, 11.23, 9.41, 8.16, 7.32, 6.76, 6.38, 6.10, 5.89, 5.74, 5.62
, 5.53, 5.46, 5.41, 5.38, 5.37, 5.36, 5.34, 5.34, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33
, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33
, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33
, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33, 5.33)

interp1( x=x_base2, y=y_base2, xi= x_interp2, method="linear"  )

[1]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000 20.96000 21.15625
 [10] 20.75750 20.35875 19.96000 17.91750 17.53500 17.15250 16.77000 14.64000 14.33000
 [19] 14.02000 13.71000 11.91250 11.68500 11.45750 11.23000 10.50375  9.87875  9.72250
 [28]  9.56625  9.41000  8.47500  8.37000  8.26500  8.16000  7.53000  7.46000  7.39000
 [37]  7.32000  6.90250  6.85500  6.80750  6.76000  6.48500  6.45000  6.41500  6.38000
 [46]  6.28375  6.17875  6.15250  6.12625  6.10000  5.94625  5.92750  5.90875  5.89000
 [55]  5.78500  5.77000  5.75500  5.74000  5.65375  5.64250  5.63125  5.62000  5.55625
 [64]  5.54750  5.53875  5.53000  5.50375  5.47875  5.47250  5.46625  5.46000  5.42125
 [73]  5.41750  5.41375  5.41000  5.38375  5.38250  5.38125  5.38000  5.37375  5.37250
 [82]  5.37125  5.37000  5.36750  5.36500  5.36250  5.36000  5.34000  5.34000  5.34000
 [91]  5.34000  5.34375  5.34250  5.34125  5.34000  5.33000  5.33000  5.33000  5.33000
[100]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[109]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[118]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[127]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[136]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[145]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[154]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[163]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[172]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[181]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[190]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[199]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[208]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[217]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[226]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[235]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[244]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[253]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[262]  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000  5.33000
[271]  5.33000  5.33000  5.33000  5.33000 20.96000 20.96000

如果我使用另一个插值函数(例如,近似值)执行相同的操作,则没有问题。我查看了interp1的文档,并且没有有关输出条目顺序的详细信息。感谢您的帮助。

0 个答案:

没有答案