r - 如何从 `nls`获取估计参数

标签 r regression non-linear-regression nls

我有以下数据:

x <- 0:10
y <- c(1, 0.0296734797447216, -0.115268522114696, 0.0685634237231258, 
0.0462346454015914, 0.016874511238053, -0.00870738489741311, 
0.0356310001815887, 0.0558631035027085, -0.116810154142989, -0.0460902529547028)

我的非线性函数是:

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),
           start=list(coeff_sigma=2, coeff_alpha=2, coeff_omega=2),
           control = nls.control(maxiter = 1000))

拟合模型打印:

Nonlinear regression model
  model: y ~ f(x, coeff_sigma, coeff_alpha, coeff_omega)
   data: df_acf
coeff_sigma coeff_alpha coeff_omega 
     0.9996      1.0482      1.5588 
 residual sum-of-squares: 0.02705

Number of iterations to convergence: 10 
Achieved convergence tolerance: 2.309e-06

问题:

我应该在后面的步骤中使用参数值(coeff_sigmacoeff_alphacoeff_omega),但我唯一能做的就是现在是从屏幕上复制它们。有什么方法可以从 fit 获取这些值吗?

最佳答案

你可以做到

fit$m$getPars()
#coeff_sigma coeff_alpha coeff_omega 
#   0.999570    1.048175    1.558793 

基本上,fit$m 中的这些函数可以让您访问各种内容。

您还可以使用泛型函数coef,因为它有一个“nls”方法。

coef(fit)
#coeff_sigma coeff_alpha coeff_omega 
#   0.999570    1.048175    1.558793 

summary() 更全面。但除非您想要估计系数的标准误差、p 值等,否则没有必要使用它。

关于r - 如何从 `nls`获取估计参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73268142/

相关文章:

statistics - 统计测试 : how do (perception; actual results; and next) interact?

r - 如何在数据表的每一行上有效地应用可归约函数

r - 基表 :split() implementation - faster options within R/data.

algorithm - 这个回归算法是否原创且有效?

machine-learning - 分类或回归算法模型的相关系数或特征重要性

R:如何计算 rpart 树的敏感性和特异性

r - 在不影响箱线图所依据的数据的情况下限制ggplot中箱线图中y轴的范围

Reorder() 未正确重新排序 ggplot 中的因子变量

R: Optim() 拟合参数限制

r - R 中具有多个解释变量的细菌生长曲线(逻辑/S 形)