矢量投影以确定拟合曲线中的弯头

控制论

我有一个已拟合非线性回归的图。我想计算拟合曲线中的弯头。大多数第二种微分方法无法准确地捕捉到这一点,并且目视检查似乎是唯一的手段(对自动化没有用)。与自动“可视”方法最接近的事情是使用矢量投影从连接数据集的第一个点和最后一个点的线计算最远的数据点(请参见下面的问号)。可以使用R计算垂直于连接第一个点和最后一个点的线的那条线吗?

我的非线性函数是:结果<-lm(y〜x + I(x ^ 2)+ I(x ^ 3)+ I(x ^ 4)+ I(x ^ 5),data = myData)

在此处输入图片说明

让·V·亚当斯

试试看。查看它是否适用于您的真实数据。

library(MASS)

# fake data
x <- 5:300
y <- (x - 0.03*x^2 + 0.02*x^3 + rnorm(length(x), sd=5000))/1000
myData <- data.frame(x, y)

# fitted curve (I used a simpler example)
result <- lm(y ~ x + I(x^2) + I(x^3), data=myData)
p <- fitted(result)

# line connecting endpoints of fitted curve
i1 <- which.min(x)
i2 <- which.max(x)
slope <- (p[i2] - p[i1]) / (x[i2] - x[i1])
int <- p[i1] - slope*x[i1]

# for every point on the predicted curve (xi, pi), the perpendicular line that goes through that point has
perpslope <- -1/slope
perpint <- p - perpslope*x

# the intersection of the perp line(s) with the connecting line is
xcross <- (int - perpint) / (perpslope - slope)
ycross <- slope*xcross + int

# the distance between the intersection and the point(s) is
dists <- sqrt((x - xcross)^2 + (y - ycross)^2)

# the index of the farthest point
elbowi <- which.max(dists)

# plot the data
eqscplot(x, y)
lines(x[c(i1, i2)], p[c(i1, i2)])
points(x[elbowi], p[elbowi], pch=16, col="red")
lines(x[order(x)], p[order(x)], col="blue")
lines(c(x[elbowi], xcross[elbowi]), c(p[elbowi], ycross[elbowi]), col="red")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ValueError:无法确定拟合参数的数量。“曲线拟合中的问题”

来自分类Dev

R中的曲线/直线拟合

来自分类Dev

使用熊猫矢量化曲线拟合数据

来自分类Dev

SciPy中的指数曲线拟合

来自分类Dev

如何定义曲线拟合中的函数?

来自分类Dev

在Python中拟合正弦余弦曲线

来自分类Dev

R中的非线性曲线拟合

来自分类Dev

循环绘制ggplot中的几个拟合曲线?

来自分类Dev

在gnuplot中拟合曲线:重复拟合会产生不同的结果

来自分类Dev

动态mongo投影-使用文档中的字段确定投影的投影

来自分类Dev

将直线拟合到matplotlib中的对数-对数曲线

来自分类Dev

对R中的经验数据进行曲线拟合

来自分类Dev

从ImageJ中的拟合曲线中提取方程式

来自分类Dev

如何判断SciPy中的指数曲线拟合程度如何?

来自分类Dev

如何在曲线拟合中强制特定点

来自分类Dev

Ggplot2中最佳拟合曲线的Y坐标

来自分类Dev

gnuplot中的功率曲线拟合获得冗余值

来自分类Dev

Matlab中的n维非线性曲线拟合

来自分类Dev

对R中的经验数据进行曲线拟合

来自分类Dev

将高斯曲线拟合到python中的数据

来自分类Dev

如何判断SciPy中的指数曲线拟合程度如何?

来自分类Dev

如何在MATLAB中仅绘制拟合曲线?

来自分类Dev

曲线拟合工具箱中的时间向量

来自分类Dev

使用 scipy.optimize.curve_fit 在 python 中拟合曲线

来自分类Dev

简单的曲线拟合

来自分类Dev

在点中拟合曲线

来自分类Dev

曲线拟合分布

来自分类Dev

拟合生存曲线的分布

来自分类Dev

拟合指数曲线误差