我有以下数据框:
> dput(df_acf)
structure(list(x = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), y = c(1,
0.0595936565187637, 0.0376022880804335, 0.0521100393333187, 0.0720561234389795,
0.0262258507877819, -0.0126644770510529, 0.18604968147151, 0.115018192163521,
-0.0476175556946567, -0.183213245514104)), class = "data.frame", row.names = c(NA,
-11L))
我想使用这个非线性函数来拟合
f <- function(t, coeff_sigma, coeff_alpha,coeff_omega) {
coeff_sigma * exp(-coeff_alpha*t)*cos(coeff_omega*t)
}
但是,当使用nls
时
fit <- nls(y~f(x,coeff_sigma,coeff_alpha,coeff_omega), data=df_acf, start=list(coeff_sigma=0.8, coeff_alpha=0.62, coeff_omega=0.65),control = nls.control(maxiter = 1000))
我收到此错误:nls 中出现错误,步长因子降低至 minFactor 以下
最佳答案
如果您对其他参数模型持开放态度,那么这很容易适合:
fo <- y ~ a * (1 + b * x) ^ -c
fit2 <- nls(fo, df_acf, start = list(a = 1, b = 1, c = 1))
plot(df_acf)
lines(fitted(fit2) ~ x, df_acf, col = "red")
给予:
关于r - nls 中的错误,步长因子降低到 minFactor 以下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73289765/