可以查看segmented包求拐点的例子。
R中运行:
library(segmented)
?segmented
。。。。。。
#An example using the default method:
# Cox regression with a segmented relationship
## Not run:
library(survival)
data(stanford2)
o<-coxph(Surv(time, status)~age, data=stanford2)
os<-segmented(o, ~age, psi=40) #estimate the breakpoint in the age effect
summary(os) #actually it means summary.coxph(os)
plot(os) #it does not work
plot.segmented(os) #call explicitly plot.segmented() to plot the fitted piecewise lines
如图,拐点已求出。
在网上查到一个R的软件包pracma中有一个fderiv函数可以实现数值求导。 于是可以按照下面办法来操作:1,在linux中安装R很简单,不做介绍。
2,运行R(注意用sudo R 命令),在终端输入install.packages(),会弹出一个对话框。
3,在对话框里面首先要选择的好像是个源地址,我选的china(hefei),然后弹出包的名字列表,选择pracma,点击下方的ok即可。
4,重新运行R后输入require(pracma)后就能使用fderiv()函数了。