寻求统计javascript函数以从z分数返回p值 [英] Seeking a statistical javascript function to return p-value from a z-score

查看:443
本文介绍了寻求统计javascript函数以从z分数返回p值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将z分数转换为百分位数。我找到了我可以使用的jStat库中的函数(jstat。 ztest),但jStat文档似乎领先于可用库,因为目前可用的库版本

I need to convert z-scores to percentile. I found reference to a function in the jStat library that I could use (jstat.ztest), but the jStat documentation seems to be ahead of the available library because there is no such function in the currently available version of the library.

我认为有一个更新版本的库GitHub ,可能包括ztest函数,但我是linux新手,无法弄清楚如何从指令构建库。我花了大约一天时间学习git bash和cygwin试图构建库;我终于决定在这里问我会好些。

I think there is a more recent version of the library on GitHub, which may include the ztest function, but I am a linux novice and could not figure out how to build the library from the instructions. I spent most of a day learning about git bash and cygwin trying to build the library; I finally decided I'd be better off asking here.

那么,有人能指出我能做我需要的javascript函数吗?
或者,是否有人可以指向包含ztest功能的jStat库的内置版本?

So, could anyone point me toward a javascript function that would do what I need? Alternatively, could anyone point me toward a built version of the jStat library with ztest function included?

推荐答案

我找到了这在一个论坛在线,它的工作就像一个魅力。

I found this in a forum online and it works like a charm.

function GetZPercent(z) 
  {
    //z == number of standard deviations from the mean

    //if z is greater than 6.5 standard deviations from the mean
    //the number of significant digits will be outside of a reasonable 
    //range
    if ( z < -6.5)
      return 0.0;
    if( z > 6.5) 
      return 1.0;

    var factK = 1;
    var sum = 0;
    var term = 1;
    var k = 0;
    var loopStop = Math.exp(-23);
    while(Math.abs(term) > loopStop) 
    {
      term = .3989422804 * Math.pow(-1,k) * Math.pow(z,k) / (2 * k + 1) / Math.pow(2,k) * Math.pow(z,k+1) / factK;
      sum += term;
      k++;
      factK *= k;

    }
    sum += 0.5;

    return sum;
  }

我不需要为一个函数包含一个大型库。

And I don't need to include a large library just for the one function.

这篇关于寻求统计javascript函数以从z分数返回p值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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