What is the R equivalent of matlab's csaps()

佐手、 提交于 2019-12-05 12:57:47

My colleague found the answer: One converts matlab's p to pspline::smooth.Pspline()'s spar not as 1/p, but as (1-p)/p, and then results will agree out to whatever the degree of numerical precision is:

c(predict(pspline::smooth.Pspline(
                          x = age,
                          y = diffs, 
                          norder = 2, 
                          method = 1,
                          spar = (1-0.0005) / 0.0005     # p given in MP and matlab as 
                         ),age))
 [1] -63.46035 -64.04741 -64.61705 -65.13972 -65.61114 -66.01646 -66.31144
 [8] -66.41232 -66.22285 -65.67263 -64.72443 -63.35823 -61.56761 -59.35675
[15] -56.73643 -53.73821 -50.40864 -46.79221 -42.94387 -38.91828 -34.76291
[22] -30.51801 -26.21863 -21.89122 -17.55320

Here is what I found in p. 16 of MATLAB/R Reference by David Hiebeler. [I don't use Matlab,however].

Fit natural cubic spline(S′′(x) = 0 at both endpoints) to points (xi, yi)whose coordinates are in vectors x and y; evaluate at points whose x coordinates are in vector xx, storing corresponding y’s in yy

Matlab:

pp=csape(x,y,’variational’);
yy=ppval(pp,xx) but note that
csape is in Matlab’s Spline
Toolbox

R

tmp=spline(x,y,method=’natural’,
xout=xx); yy=tmp$y
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!