r - 非线性总最小二乘/戴明回归

标签 r regression

我一直在使用nls()来将自定义模型拟合到我的数据中,但我不喜欢模型的拟合方式,并且我想使用一种可以最大限度地减少残差的方法x 轴和 y 轴。

我进行了大量搜索,并找到了拟合线性模型的解决方案,例如 deming 包 ( http://cran.r-project.org/web/packages/deming/index.html ) 和这些 stackoverflow 帖子: Total Least Square method using R , How to calculate Total least squares in R? (Orthogonal regression) 。我还找到了 matlab 解决方案 ( https://stats.stackexchange.com/questions/110772/total-least-squares-curve-fit-problem ),但这些解决方案适合二阶多项式,而不是自定义的用户定义模型。

我想要的是类似于 nls() 的东西,它可以执行 x 和 y 残差最小化。这将允许我输入我的自定义模型。有人知道 R 中的任何解决方案吗?

非常感谢!

编辑

这是一个示例,但请注意,我正在寻求有关非线性总最小二乘回归的通用解决方案的建议,而不是特定于此数据集的建议(这只是基于 Modifying a curve to prevent singular gradient matrix at initial parameter estimates 的示例数据):

df <- structure(list(x = c(3, 4, 5, 6, 7, 8, 9, 10, 11), y = c(1.0385, 
1.0195, 1.0176, 1.01, 1.009, 1.0079, 1.0068, 1.0099, 1.0038)), .Names = c("x", 
"y"), row.names = c(NA, -9L), class = "data.frame")

(nlsfit <- nls(y ~ a^b^x, data = df, start = c(a=0.9, b=0.6)))

library(ggplot2)
ggplot(df, aes(x=x, y=y)) + 
    geom_point() + 
    geom_smooth(method="nls", formula = y ~ a^b^x, se=F, start = list(a=0.9, b=0.6))

最佳答案

G. CrossValidated 的 Grothendieck 和 Brian Borchers 建议使用 onls 包,这正是我正在寻找的。谢谢大家,非常感谢您的帮助。请参阅此处了解更多信息:http://www.r-bloggers.com/introducing-orthogonal-nonlinear-least-squares-regression-in-r/

这是一个使用上面相同数据的示例 - 这提供了与常规 nls() 相同的拟合参数,但它确实对我的实际数据产生了影响。但这至少显示了如何进行操作。

df <- structure(list(x = c(3, 4, 5, 6, 7, 8, 9, 10, 11), y = c(1.0385, 
1.0195, 1.0176, 1.01, 1.009, 1.0079, 1.0068, 1.0099, 1.0038)), .Names = c("x", 
"y"), row.names = c(NA, -9L), class = "data.frame")

library(onls)
(onlsfit <- onls(y ~ a^b^x, data = df, start = c(a=0.9, b=0.6)))

# define function containing onls fitted parameters for plotting
fit.model <- function(x) {1.0934^0.7242^x}

library(ggplot2)
ggplot(df, aes(x=x, y=y)) + 
    geom_point() + 
    stat_function(fun=fit.model, color="black")

关于r - 非线性总最小二乘/戴明回归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29054412/

相关文章:

正则表达式,R 中的多行提取

r - 堆叠条形图与 R 中的线

arrays - 找到成本函数比率的最佳方法

python - 蛮力是使用 Python 进行多元回归的最佳选择吗?

r - 在 Shiny 的 renderUi 中使用 renderDataTable

r - R 中的 URL 问题

python - 机器学习神经网络: Can Training Error and Testing Error be equal?

matlab - Fminsearch Matlab(非线性回归)

r - 如何在 R 中创建迭代 lm() 公式

r - 按周计算每日观察次数