Passing mean and standard deviation into dnorm() using Rcpp Sugar

[亡魂溺海] 提交于 2019-12-05 19:12:55

The sugar dnorm is only vectorized in terms of the first argument.

To simplify (it is slightly more involved, but we don't need to concern ourselves with this yet here), the call

dnorm(xx, 0.0, 1.0)

uses the overload

NumericVector dnorm( NumericVector, double, double )

And the second call tries to use something like

NumericVector dnorm( NumericVector, NumericVector, NumericVector )

which is not implemented. We could implement it, it would have to go high enough in our priority list.

In the meantime, it is easy enough to write a small wrapper, like (this does not handle argument lengths, etc ...) :

NumericVector my_dnorm( NumericVector x, NumericVector means, NumericVector sds){
    int n = x.size() ;
    NumericVector res(n) ;
    for( int i=0; i<n; i++) res[i] = R::dnorm( x[i], means[i], sds[i] ) ;
    return res ;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!