【问题标题】:R Programming nls(): confint() with error singular gradientR Programming nls(): 带有误差奇异梯度的 confint()
【发布时间】:2015-01-28 20:31:34
【问题描述】:

以下表示代码和输出:

library(minpack.lm) #Levenberg-Marquardt 非线性最小二乘算法(支持参数上下界)

library(ggplot2) #Sophisticated combination of base and lattice graphics
DRP <-read.csv(file="NormalizedDRP.csv", header=TRUE)

    attach(DRP)

> # Lysis: 1% Lysed Algae + Seed # 

> LAS1 <-subset(DRP, RunM=="1% LAS ", select=DayM: NormalizedM)

> LAS1
  DayM NormalizedM
1    0         3.7
2    4         3.0
3   10         8.0
4   21         8.3
5   39         8.7

> fmLAS1 <-nlsLM(NormalizedM~A*(1-exp(-k*DayM)), data=LAS1, start=list(A=8, k=0))

> fmLAS1
Nonlinear regression model
  model: NormalizedM ~ A * (1 - exp(-k * DayM))
   data: LAS1
     A      k 
8.9060 0.1496 
 residual sum-of-squares: 15.98

Number of iterations to convergence: 8 
Achieved convergence tolerance: 1.49e-08

> coef(fmLAS1)
        A         k 
8.9060252 0.1495719 

> confint(fmLAS1)
Waiting for profiling to be done...
Error in prof$getProfile() : singular gradient

> deviance(fmLAS1)
[1] 15.97858

Data Set: I grabbed only a subset of the data for the variables Run M and DayM set to 1%LAS; which stands for 1% Lysed autoclaved Seed in anaerobic digestion

【问题讨论】:

  • 您应该发布带​​有完整错误消息的脚本,因为完全不清楚错误来自confint 调用。即使这样可能还不够,因为错误表明您的数据集中存在病态并且仅查看子集可能无法提供智能答案。

标签: r csv nls levenberg-marquardt


【解决方案1】:

如果 confint 尝试计算 NormalizedM > A 的值,您的函数 NormalizedM~A*(1-exp((-k)*DayM)) 将生成一个负数错误日志。

您可以尝试计算 NormalizedM 的对数

log_NormalizedM <- log(NormalizedM)

并为其拟合线性模型。

fit <- lm(log_NormalizedM ~ DayM)

【讨论】:

    猜你喜欢
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 2014-08-27
    • 2017-07-19
    相关资源
    最近更新 更多