How to utilize the distribution functions correctly?

104 views
Skip to first unread message

notio...@gmail.com

unread,
Nov 15, 2013, 9:29:53 AM11/15/13
to jstat-...@googlegroups.com

I have a question about how to use the distribution functions within the jstat library. Specifically, I am focused on studentt.

I've tried this:

var alphaLevel = 0.05;
var degreesOfFreedom = 18;

// the answer I want to get is 2.100922
tStat = jStat.studentt(alphaLevel,degreesOfFreedom);

// but all that is returned is an object with 
// members _a,_b,_c (_a=0.05, _b=18,_c=undefined).

As explained on the jstat github site, there is a difference between static and instance functions. However, it is above my experience with javascript as to how to do this.

Can anyone explain how to properly call the studentt function and get the proper result?

Thank you!


PS: I also posted this on StackOverflow seeing that Trevor had taken time to answer there previously. Without an official distribution, I simply used script tags to reference in each of the jStat js files in sequence.  Although I've been able to use matrix functions like .transpose - I can't figure out how to successfully utilitze the distribution library. 

I have not seen a way to contribute to the project, but perhaps I could contribute with a bit of guidance.

- Again, Thank you.

Trevor Norris

unread,
Nov 16, 2013, 3:00:19 PM11/16/13
to jstat-...@googlegroups.com
The usage follows this documentation: http://jstat.github.io/distributions.html#jStat.studentt

So in your example you have two options. Either you can get the result immediately:

var tStat = jStat.studentt.pdf(alphaLevel, degreesOfFreedom);

Or you can return an instance that allows you to pass in multiple degrees of freedom:

var tStat = jStat.studentt(alpha);
var a1 = tStat.pdf(doF1);
var a2 = tStat.pdf(doF2);

Trevor Norris

unread,
Nov 18, 2013, 4:35:15 AM11/18/13
to jstat-...@googlegroups.com
Please note that my arguments are reversed in the second example. Sorry about any confusion this might have caused.

notio...@gmail.com

unread,
Nov 21, 2013, 2:04:48 PM11/21/13
to jstat-...@googlegroups.com
No problemo.  With your help, I've been able to get things working.  Thank you so much! 
I hope the jStat library can find a steady state, I tried several to do what I needed and ended up using jStat even though it has gone somewhat dormant. Nice work!

joaofr...@gmail.com

unread,
Apr 1, 2016, 5:15:25 AM4/1/16
to jStat
Hi there

Any chance you can share the bigger solution to this problem. I am similarly stuck, but being completely new to javascript, am struggling to figure out where to include the above code. Here is my attempt:

<!DOCTYPE HTML>
<html>
<head>
<script src="//cdn.jsdelivr.net/jstat/<version>/jstat.min.js"></script>

<script>
var tStat = jStat.studentt.pdf(0.05, 10);
document.getElementById('demo').innerHTML = tStat;
</script>

</script>
</head>
<body>
<p id="demo"></p>
</body>
</html>

joaofr...@gmail.com

unread,
Apr 1, 2016, 5:15:25 AM4/1/16
to jStat
Hi Trevor

Any chance you can provide some more guidance to a complete novice. Where do I include this code? Here's what I have, but can't get to work:
Reply all
Reply to author
Forward
0 new messages