本文介绍了如何计算 Perl 中给定正态分布的点的概率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl 中是否有一个包可以让您计算每个给定点的概率分布高度.例如,这可以在 R 中以这种方式完成:

Is there a package in Perl that allows you to compute the height of probability distribution at each given point. For example this can be done in R this way:

> dnorm(0, mean=4,sd=10)
> 0.03682701

即点 x=0 落入正态分布的概率为 0.0368,均值=4,sd=10.我查看了 Statistics::Distribution 但它没有不给,非常功能来做到这一点.

Namely the probability of point x=0 falls into a normal distribution, with mean=4 and sd=10, is 0.0368.I looked at Statistics::Distribution but it doesn't give that very function to do it.

推荐答案

为什么不遵循这些原则(我用 R 编写,但它可以在 Perl 中使用 Statistics::Distribution 完成):

Why not something along these lines (I am writing in R, but it could be done in perl with Statistics::Distribution):

dn <- function(x=0 # value
               ,mean=0 # mean 
               ,sd=1 # sd
               ,sc=10000 ## scale the precision
               ) {
  res <- (pnorm(x+1/sc, mean=mean, sd=sd)-pnorm(x, mean=mean, sd=sd))*sc
  res
}
> dn(0,4,10,10000)
0.03682709
> dn(2.02,2,.24)
1.656498

[edit:1] 我应该提到这个近似值在远尾会变得非常可怕.取决于您的应用,这可能重要也可能无关紧要.

[edit:1] I should mention that this approximation can get pretty horrible at the far tails. it might or might not matter depending on your application.

[edit:2] @foolishbrat 把代码变成了一个函数.结果应该总是积极的.也许您忘记了在 perl 模块中您提到的函数返回上概率 1-F,而 R 返回 F?

[edit:2] @foolishbrat Turned the code into a function. The result should always be positive. Perhaps you are forgetting that in the perl module you mention the function returns the upper probability 1-F, and R returns F?

[edit: 3] 修复了复制和粘贴错误.

[edit: 3] fixed a copy and paste error.

这篇关于如何计算 Perl 中给定正态分布的点的概率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:40