【问题标题】:Positive coefficients for lm() or gls()lm() 或 gls() 的正系数
【发布时间】:2014-02-08 08:53:16
【问题描述】:

我想知道是否有人知道如何将lmgls 中的某些系数限制为正数?

例如,我希望lm(y ~ x1 + x2 + ... + xn)gls(y ~ x1 + x2 + ... + xn) 并且我希望x1x2 的系数为非负数。

【问题讨论】:

  • 检查R 中的包nnls 以及非负最小二乘法相关的文献,我认为这就是您要找的。​​span>
  • 还有this 应该会有所帮助。

标签: r statistics lm


【解决方案1】:

一种选择是使用nls(...),它允许指定参数的上限和下限。所以,类似:

# not tested...
fit <- nls(y~a*x1 + b*x2 +c*x3...,data=mydata, 
           start=c(a=1,b=1,c=1...), lower=c(a=0,b=0,c=NA,...), algorithm="port")

阅读文档here

【讨论】:

    猜你喜欢
    • 2021-12-07
    • 1970-01-01
    • 2015-03-21
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 2020-03-06
    • 2021-11-06
    相关资源
    最近更新 更多