[英]obtain derivative by spline interpolation
there is a series of x and y values I have (but not the function itself). 我有一系列的x和y值(但函数本身没有)。 I would like to get derivative of the unknown function by spline interpolation of the x and y values (getting the derivat...). 我想通过样条插值x和y值来获得未知函数的导数(获取导数...)。 My example EDITED 我的示例已编辑
x<-c(1,2,3,4,5,6,7,8,9,10)
y<-c(0.1,0.3,0.8,0.9,0.91,0.93,0.95,0.98,0.99,0.999)
is it possible in R to interpolate and to get the functional form of the derivative? R中是否可以插值并获得导数的功能形式? My problem is that I have only x and y values of a cdf function but would need to obtain the probability denisty function..so I want to get the derivative by spline interpolation... 我的问题是我只有cdf函数的x和y值,但需要获得概率密度函数。所以我想通过样条插值来获得导数...
The reason for the question is that I would need to obtain the pdf of that cdf so I am trying to spline interpolate the xy values of the cdf - please note that this is a simple example here and not a real cdf 问题的原因是,我需要获取该cdf的pdf,因此我试图通过样条插值cdf的xy值-请注意,这是一个简单的示例,而不是真正的cdf
I haven't found the functional form of restricted cubic splines to be particularly difficult to grasp after reading the explanation by Frank Harrell in his book: "Regression Modeling Strategies". 阅读弗兰克·哈雷尔(Frank Harrell)在他的书“回归建模策略”中的解释后,我还没有发现很难限制三次样条的功能形式。
require(rms)
df <- data.frame( x = c(1,2,3,4,5,6,7,8,9,10),
y =c(12,2,-3,5,6,9,8,10,11,10.5))
ols( y ~ rcs(x, 3), df)
#--------------
Linear Regression Model
ols(formula = y ~ rcs(x, 3), data = df)
Model Likelihood Discrimination
Ratio Test Indexes
Obs 10 LR chi2 3.61 R2 0.303
sigma 4.4318 d.f. 2 R2 adj 0.104
d.f. 7 Pr(> chi2) 0.1646 g 2.811
Residuals
Min 1Q Median 3Q Max
-8.1333 -1.1625 0.5333 0.9833 6.9000
Coef S.E. t Pr(>|t|)
Intercept 5.0833 4.2431 1.20 0.2699
x 0.0167 1.1046 0.02 0.9884
x' 1.0000 1.3213 0.76 0.4738
#----------
The rms
package has an odd system for storing summary information that needs to be done for some of its special rms
软件包有一个奇怪的系统,用于存储摘要信息,某些特殊信息需要完成
dd <- datadist(df)
options(datadist="dd")
mymod <- ols( y ~ rcs(x, 3), df)
# cannot imagine that more than 3 knots would make sense in such a small example
Function(mymod)
# --- reformatted to allow inspection of separate terms
function(x = 5.5) {5.0833333+0.016666667* x +
1*pmax(x-5, 0)^3 -
2*pmax(x-5.5, 0)^3 +
1*pmax(x-6, 0)^3 }
<environment: 0x1304ad940>
The zeros in the pmax
functions basically suppress any contribution to the total from the term when the x value is less than the knots ( 5, 5.5 and 6 in this case) 当x值小于节(在这种情况下为5、5.5和6)时, pmax
函数中的零基本上抑制了该项对总数的任何贡献。
Compare three versus four knots (and if you wanted smooth curves then include a finer grained ...-
data argument to Predict
): 比较三个结与四个结(如果需要平滑的曲线,则可以包括更细的...-
Predict
data参数):
png()
plot(df$x,df$y )
mymod <- ols( y ~ rcs(x, 3), df)
lines(df$x, predict(mymod) ,col="blue")
mymod <- ols( y ~ rcs(x, 4), df)
lines(df$x, predict(mymod) ,col="red")
dev.off()
Take a look at monotone cubic splines, which are nondecreasing by construction. 看一下单调三次样条曲线,它们在构造上不会减少。 A web search for "monotone cubic spline R" turns up some hits. 在网络上搜索“单调三次样条R”会发现一些问题。 I haven't used any of the packages mentioned. 我没有使用任何提到的软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.