Finding the elbow/knee in a curve

前端 未结 2 1658
一个人的身影
一个人的身影 2021-01-07 10:54

I have these data:

x <- c(6.626,6.6234,6.6206,6.6008,6.5568,6.4953,6.4441,6.2186,6.0942,5.8833,5.702,5.4361,5.0501,4.744,4.1598,3.9318,3.4479,3.3462,3.108         


        
相关标签:
2条回答
  • 2021-01-07 11:13

    You can now find the knees/elbows with different methods by using the maxcurv function in the soilphysics package.

    0 讨论(0)
  • 2021-01-07 11:15

    I think you want to find the points where the derivative of the function y=f(x) has a huge jump in value. you can try the following, as you can see there can be one or many such points depending on the threshold (for huge jump) we choose:

    get.elbow.points.indices <- function(x, y, threshold) {
      d1 <- diff(y) / diff(x) # first derivative
      d2 <- diff(d1) / diff(x[-1]) # second derivative
      indices <- which(abs(d2) > threshold)  
      return(indices)
    }
    
    # first approximate the function, since we have only a few points
    ap <- approx(x, y, n=1000, yleft=min(y), yright=max(y))
    x <- ap$x
    y <- ap$y
    
    indices <- get.elbow.points.indices(x, y, 1e4) # threshold for huge jump = 1e4
    x[indices]
    #[1] 6.612851 # there is one such point
    plot(x, y, pch=19)
    points(x[indices], y[indices], pch=19, col='red')
    

     indices <- get.elbow.points.indices(x, y, 1e3) # threshold for huge jump = 1e3
     x[indices]
     #[1] 0.3409794 6.4353456 6.5931286 6.6128514 # there are 4 such points
     plot(x, y, pch=19)
     points(x[indices], y[indices], pch=19, col='red')
    

    0 讨论(0)
提交回复
热议问题