R::dexp 的参数化 [英] Parameterisation of R::dexp

查看:37
本文介绍了R::dexp 的参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚花了一段时间试图在我的代码中找到一个错误,结果证明这是 R::dexp 函数的一个不寻常的(至少对我而言)参数化.例如:

I have just spent a while trying to find a bug in my code which has turned out to be an unusual (at least to me) parameterisation for the R::dexp function. For example:

cppFunction("
  double my_dexp(double x, double lambda, double is_log) {
    return R::dexp(x, lambda, is_log);
  }
")

> my_dexp(4.5, 2.5, FALSE)
[1] 0.06611956
> dexp(4.5, 2.5, FALSE)
[1] 3.251824e-05

查看这里我可以看到他们使用了定义:

Looking here I can see that they use the definition:

double R::dexp(double x, double sl, int lg)

但我一直无法找出 sl 代表什么.我不确定这是否在任何地方都有记录 - 所以希望这篇文章能够对像我这样使用过该函数的其他人发出警告,如果有人可以帮助了解使用了哪些参数化以及原因.

but I haven't been able to find out what sl stands for. I'm not sure if this is documented anywhere - so hopefully this post stands as a warning to others who have used the function like me, and also if anyone can help as to what parameterisation has been used, and why.

推荐答案

如果你查看 dexp 的函数定义,

If you look at the function definition for dexp,

R> dexp
function (x, rate = 1, log = FALSE) 
.Call(C_dexp, x, 1/rate, log)

您将看到dexp 调用带有参数1/rate 的C 函数C_dexp.这就是 R::dexp 的镜像.在 Rcp 中,它们总是使用与 R 本身在 C 级别上所做的相同的参数化,这可能与 R 级别不同.

you'll see that dexp calls the C function C_dexp with parameter 1/rate. This is what R::dexp is mirroring. In Rcp, they always use the same parameterisation as R itself does at the C level which may be different than the R level.

这意味着

R> my_dexp(4.5, 1/2.5, FALSE) - dexp(4.5, 2.5, FALSE)
[1] 0

如果您查看 指数函数 上的维基百科页面,您会看到替代方法基于速率参数 lambda 的倒数进行参数化.在此参数化中,参数 beta=1/lambda 扮演生存参数的角色.所以系统的预期生存时间是beta时间单位.

If you look at the Wikipedia page on the exponential function, you'll see the alternative parameterisation based on the reciprocal of the rate parameter, lambda. In this parameterisation, the parameter beta=1/lambda takes the role of a survival parameter. So the expected duration of survival of the system is beta units of time.

这篇关于R::dexp 的参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆