找到拐点时的变量结果

时间:2014-01-17 03:14:20

标签: r

我试图找到大量模拟曲线的拐点。我的长链代码(下面)估计一些看起来是正确的,其他非常相似的形状曲线产生NAs(我的代码暂时删除),而其他曲线产生看起来像正确的x值,但是y值非常错误。

我需要我的代码自动化,以便它可以计算可变数量的曲线,我想知道是否有更好的方法来做到这一点,或者我的代码是错误的,所以它只是偶尔有效。

有什么建议吗?

我的数据集DF,看起来像这样(这只是它的一小部分):

x<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,27,28,29,30,31,32)
y<-c(1.7059375,2.758991935,3.483247984,4.012146552,4.413616866,4.727241214,4.977991426,5.182440247,5.35198822,5.494697224,5.616398242,5.721391107,5.812901462,5.893386918,5.964746453,6.028466191,6.085722524,6.137456196,6.184426351,6.227250551,6.266434874,6.302396877,6.335483374,6.365984367,6.394144099,6.420169887,6.444239234,6.444239234,6.466505562,6.487102823,6.506149194,6.52375,6.54)
z<-c(0.477678571428571,0.820808224021978,1.09325815289011,1.32282267252747,1.52251766094506,1.69934927065934,1.85777050481319,2.00100176757143,2.13153994808791,2.25137549883517,2.36210750327473,2.46502115583516,2.56114799125275,2.65131522820879,2.73618659159341,2.81629595210989,2.89207483297802,2.96387470608791,3.0319848903956,3.09664676591209,3.15806493720879,3.21641589107692,3.27185461785714,3.32451960396703,3.37453653517582,3.42202100093407,3.46708044257143,3.46708044257143,3.50981554595604,3.55032125138462,3.58868752218681,3.625,3.65934065934066)
a<-c(1.8675,2.96570564514,3.71683064516,4.26843464957,4.68914974972,5.01828098232,5.28097147347,5.49425603662,5.67008117781,5.81702979619,5.94138532758,6.04782071663,6.13985944211,6.22019159576,6.29089474025,6.353590662,6.40955813944,6.45981506069,6.5051789032,6.54631176154,6.58375422193,6.61795110405,6.64927121301,6.67802263389,6.70446467411,6.72881725945,6.7512683736,6.7512683736,6.77197997771,6.79109274195,6.80872983873,6.825,6.84)
b<-c(0.873125,1.55108871,2.091183468,2.531716908,2.898629231,3.209766727,3.477640716,3.711211289,3.9170445,4.100067219,4.264063299,4.412002921,4.546263829,4.66878207,4.781156398,4.884721951,4.980603366,5.069753972,5.152985441,5.230990827,5.304362919,5.373609212,5.439164364,5.501400716,5.560637279,5.617147448,5.67116563,5.67116563,5.722892937,5.772502016,5.820141129,5.8659375,5.91)

DF<-cbind(x,y,z,a,b)

和我的代码:

library(inflection)
library("reshape2")
out<-c()
out1<-c()
days_x<-cbind(DF[,1])
for (i in 2:length(colnames(DF))-1) {
  #browser()
  level<-cbind(DF[,i])
  iter<-findiplist(days_x,level,0)
  out1<-rbind(out1,iter[2,3])
  out<-cbind(out1,iter[1,3])
  out
}

out<-out[,1]

outs<-rbind(DF,out)
outs<-t(outs)
outs<-na.omit(outs)
outs<-t(outs)

outDF<-outs[1:(length(rownames(outs))-1),]
inf<-as.vector(outs[length(rownames(outs)),])
cms<-outDF[,1]
outDF<-outDF[,-1]

x<-c()
for (i in 1:length(colnames(outDF)))  {
    iter<-spline(cms,outDF[,i],xout=inf[i])
    iters<-cbind(iter$x,iter$y)
    x<-rbind(x,iters)
    x 
}

0 个答案:

没有答案