![](/img/trans.png)
[英]Nonlinear least squares regression of skewed normal distribution in R (or any language)
[英]Nonlinear total least squares/Deming regression
我一直在使用nls()
將自定義模型擬合到我的數據中,但是我不喜歡模型的擬合方式,並且我想使用一種方法來最大限度地減少x和y軸上的殘差。
我進行了很多搜索,找到了適合線性模型的解決方案,例如戴明包( http://cran.r-project.org/web/packages/deming/index.html )和這些stackoverflow帖子: 使用R的總最小二乘法 , 如何計算R中的總最小二乘法? (正交回歸) 。 我還找到了matlab解決方案( https://stats.stackexchange.com/questions/110772/total-least-squares-curve-fit-problem ),但是它們適合二階多項式,而不是用戶定義的自定義模型。
我想要的是類似於nls()
,它可以將x和y殘差最小化。 這將允許我輸入我的自定義模型。 有人知道R中的任何解決方案嗎?
非常感謝!
編輯
這是一個示例,但是請注意,我正在尋求有關非線性總最小二乘回歸的一般解決方案的建議,而不是該數據集的特定建議(這只是基於修改曲線以防止初始時使用奇異梯度矩陣的示例數據參數估算值 ):
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))
CrossValidated的G. 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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.