简体   繁体   English

R中的digamma函数的根

[英]Roots of digamma function in R

I am working on a maximum likelihood estimator, and one of the parameters is estimated using the digamma function. 我正在研究最大似然估计器,其中一个参数是使用digamma函数估计的。 I'm trying to use uniroot to solve the equation but am unable to do so. 我正在尝试使用uniroot求解方程,但无法这样做。 Here's my code: 这是我的代码:

dig = function(alpha){
    digamma(2 + alpha) - digamma(alpha) - (1/(2+alpha)) + (2/(2+alpha))
}

curve(dig, from = 0, to = 10)
uniroot(dig, lower = 0, upper = 10)

This produces the following error: 这将产生以下错误:

Error in uniroot(dig, lower = 0, upper = 10) : f.lower = f(lower) is NA
In addition: Warning messages:
1: In digamma(alpha) : NaNs produced
2: In digamma(alpha) : NaNs produced

The first error sort of makes sense based on the curve, but the second has me stuck. 第一种基于曲线是有道理的,但是第二种却使我陷于困境。 It's entirely possible that I'm misunderstanding how to find the roots of the digamma function, or that there's a numerical package (maybe rootsolve?) in R that could help. 我很可能会误解如何找到digamma函数的根,或者R中有一个数字包(也许是rootsolve?)可能会有所帮助。 Not sure what I'm missing here- any tips would be appreciated. 不知道我在这里缺少什么-任何提示将不胜感激。 Thanks! 谢谢!

Consider the following 考虑以下

curve(dig, from = 0.01, to = 10)
uniroot(dig, lower = 0.01, upper = 10)

在此处输入图片说明

Error in uniroot(dig, lower = 0.01, upper = 10) : f() values at end points not of opposite sign uniroot(dig, lower = 0.01, upper = 10)错误uniroot(dig, lower = 0.01, upper = 10) :端点处的f()值不是相反的符号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM