我的测量结果看起来像“测量样本”(见代码)。从这些点我试图找到膝盖,在这种情况下是在x = 80和y = 12 (p.corners[2, ])
。 “底层曲线”图显示了我试图自动找到的趋势线。
如何估计膝盖位置的坐标?我有数百条曲线适合,每条约200点。
library(ggplot2)
p.corners <- data.frame(rbind(c(0, 6), c(80, 12), c(100, 100)))
colnames(p.corners) <- c("x", "y")
x.a <- 1:p.corners[2, "x"]
y.a <- (p.corners[2, "y"]-p.corners[1, "y"])/(p.corners[2, "x"]-p.corners[1, "x"])*x.a+p.corners[1, "y"]
x.b <- (p.corners[2, "x"]+1):100
y.b <- (p.corners[3, "y"]-p.corners[2, "y"])/(p.corners[3, "x"]-p.corners[2, "x"])*x.b+p.corners[2, "y"]-(((p.corners[3, "y"]-p.corners[2, "y"])/(p.corners[3, "x"]-p.corners[2, "x"]))*p.corners[2, "x"])
x <- c(x.a, x.b)
y <- c(y.a, y.b)
p.random <- data.frame(cbind(x, y))
p.random$y.random <- y + 20*(runif(20)-0.5)
p <- ggplot(p.random, aes(x=x, y=y.random))
p <- p + geom_point()
p <- p + xlim(0, 100)
p <- p + ylim(0, 100)
p <- p + labs(title="Measured samples")
p
p <- ggplot(p.random, aes(x=x, y=y))
p <- p + geom_line()
p <- p + xlim(0, 100)
p <- p + ylim(0, 100)
p <- p + labs(title="Underlying curve")
p
基础曲线是一条斜率适中的直线,后面是陡峭的直线。与示例图相比,测量值更加分散。
答案 0 :(得分:2)
如果没有实际数据很难说,但也许你应该先看看用diff
计算的差异:
> rle(round(diff(p.random$y, differences = 1), 3))
Run Length Encoding
lengths: int [1:2] 79 20
values : num [1:2] 0.075 4.4
> rle(round(diff(p.random$y, differences = 2), 3))
Run Length Encoding
lengths: int [1:3] 78 1 19
values : num [1:3] 0 4.325 0
> rle(round(diff(p.random$y, differences = 3), 3))
Run Length Encoding
lengths: int [1:4] 77 1 1 18
values : num [1:4] 0 4.325 -4.325 0
(rle
来电只是为了缩短输出。)也许您正在寻找二阶差异的峰值,或三阶差异的符号变化。如果数据有噪音,请考虑使用KernSmooth::ksmooth
或loess
预先平滑数据。