public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* T-Student question
@ 2003-04-29 17:41 Asier
  2003-04-29 18:08 ` Martin Jansche
  0 siblings, 1 reply; 9+ messages in thread
From: Asier @ 2003-04-29 17:41 UTC (permalink / raw)
  To: gsl-discuss

I need to calculate one of the t-student parameters, but I don't know how to
do it with the gsl library.

If 't' is the tStudent probability, and t_X the probability with 'X' degrees
of freedom P(t_7 < 2.11) I can get it with the gsl_rand_tdist_pdf(x, nu)
function.

    double d = gsl_rand_tdist_pdf(2.11, 7);

¿Ok? How can I calculate the t_(n-1;\alpha) probability 

Given I know the above 'd' and 'nu' numbers, how can I calculate the 'x'
parameter of the function? I've seen tables with this data but I don't know
if there's a 'direct way' to calculate it with gsl.

PD: Excuse my poor english.
--
Asier

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 17:41 T-Student question Asier
@ 2003-04-29 18:08 ` Martin Jansche
  2003-04-29 18:57   ` Asier
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Jansche @ 2003-04-29 18:08 UTC (permalink / raw)
  To: gsl-discuss

On Tue, 29 Apr 2003, Asier wrote:

> I need to calculate one of the t-student parameters, but I don't know how to
> do it with the gsl library.
>
> If 't' is the tStudent probability, and t_X the probability with 'X' degrees
> of freedom P(t_7 < 2.11) I can get it with the gsl_rand_tdist_pdf(x, nu)
> function.
>
>     double d = gsl_rand_tdist_pdf(2.11, 7);
>
> ¿Ok?

No.  That gives you the *density* at 2.11.

> How can I calculate the t_(n-1;\alpha) probability

You need the CDF, the integral of the density.  The following code
might work (not tested, use at your own risk, etc.):

double
gsl_ran_tdist_cdf (const double x, const double nu)
{
  if (x == 0)
      return 0.5;
  else {
    double d = 0.5 * gsl_sf_beta_inc (0.5*nu, 0.5, nu/(nu + x*x));
    /* d as a function of x is symmetric about zero, but has a
       maximum there; adjust as follows(?): */
    return (x < 0)? d : 1 - d;
  }
}

This would give you the "probability" (let's not quibble) for the
one-sided t-test(?).  You'd then have to compare it to 1-alpha.

> Given I know the above 'd' and 'nu' numbers, how can I calculate the 'x'
> parameter of the function?

You're asking for the inverse CDF, I assume.  Are you sure you need
it?  In many applications you ultimately want to know whether you can
reject the null-hypothesis and at what p-value.  If you do your
calculcations from tables, then critical values of x are useful.  But
otherwise, what do you need them for?

- martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 18:08 ` Martin Jansche
@ 2003-04-29 18:57   ` Asier
  2003-04-29 20:21     ` Martin Jansche
  0 siblings, 1 reply; 9+ messages in thread
From: Asier @ 2003-04-29 18:57 UTC (permalink / raw)
  To: gsl-discuss

El 29/04/2003, Martin Jansche escribió:

> No.  That gives you the *density* at 2.11.

Oops! Sorry O:)

> You're asking for the inverse CDF, I assume.  Are you sure you need
> it?  In many applications you ultimately want to know whether you can
> reject the null-hypothesis and at what p-value.  If you do your
> calculcations from tables, then critical values of x are useful.  But
> otherwise, what do you need them for?

My mathematical knowledge is near zero compared to yours O:)

I've two vectors of means and variances (from a normal distribution)
calculated from a matrix of data.  (from each column of the matrix I
calculate one mean and one variance) and I must give each one a confidence
interval.

I must know that t_(n-1;\alpha). I usually have seen this data in
tables like this:

"T Student Distribution" 

        P (t <= t_p) = p

Degrees     t_0.995       t_0.99  (...)

   1          63,66         31,82  ...
   2           9,92          6,96  ...
  ...          ...           ...   ...

Like in http://helios.bto.ed.ac.uk/bto/statistics/table1.html

I need to know how to calculate this kind of tables. If I know the degrees of
freedom and the probability, I want to calculate the data in the table.

I think I'll have the same problem with the Pearson's chi-square function
when I'll try to calculate the interval for the variance. I have a similar
table ("pearson chi-square distribution table"), and the same need so if yo
know how... :)))))

Hmmm my english is really poor. I've been writting this for 30 minutes!
(you know spanish??)
--
Asier ·· NO A LA GUERRA, NO EN MI NOMBRE ·· [ Socio Co-Fundador del K.T.P ]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 18:57   ` Asier
@ 2003-04-29 20:21     ` Martin Jansche
  2003-04-29 20:39       ` Martin Jansche
  2003-04-29 23:39       ` Asier
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Jansche @ 2003-04-29 20:21 UTC (permalink / raw)
  To: gsl-discuss

On Tue, 29 Apr 2003, Asier wrote:

> I must know that t_(n-1;\alpha). I usually have seen this data in
> tables
[...]
> I need to know how to calculate this kind of tables. If I know the
> degrees of freedom and the probability, I want to calculate the
> data in the table.

Unless you want to do this via root-finding, you'd need a way to
calculate the inverse function (with respect to the third parameter)
of gsl_sf_beta_inc.  If you had a function f such that f(a,b,y)=x iff
gsl_sf_beta_inc(a,b,x)=y, you could then calculate

  sqrt(nu * (1 / f(2*(1-p), nu/2, 0.5) - 1))

to get the critical value for a given p-value and degrees of freedom
nu.

The requisite function f does not seem to be part of GSL yet, but
would be useful to have.  Mathematica has InverseBetaRegularized,
which seems to be what you need.

Without an explicit inverse of the incomplete Beta function, you can
use standard root finding with derivatives.

> I think I'll have the same problem with the Pearson's chi-square function

Same situation.  You'll need to calculate the inverse function of
gsl_sf_gamma_inc_P.

- martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 20:21     ` Martin Jansche
@ 2003-04-29 20:39       ` Martin Jansche
  2003-04-29 23:39       ` Asier
  1 sibling, 0 replies; 9+ messages in thread
From: Martin Jansche @ 2003-04-29 20:39 UTC (permalink / raw)
  To: gsl-discuss

On Tue, 29 Apr 2003, I wrote:

>   sqrt(nu * (1 / f(2*(1-p), nu/2, 0.5) - 1))

but meant:

    sqrt(nu * (1 / f(nu/2, 0.5; 2*(1-p)) - 1))

(as I can never decide where the additional argument of the incomplete
Beta function should go).  Also, for p < 0.5 you'll have to use
symmetry.

- martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 20:21     ` Martin Jansche
  2003-04-29 20:39       ` Martin Jansche
@ 2003-04-29 23:39       ` Asier
  2003-04-30  3:13         ` Jason H. Stover
  1 sibling, 1 reply; 9+ messages in thread
From: Asier @ 2003-04-29 23:39 UTC (permalink / raw)
  To: gsl-discuss

El 29/04/2003, Martin Jansche escribió:

> Unless you want to do this via root-finding, you'd need a way to

Jason H. Stover has pointed me to the R sources, where there's a function
that computes that value.

R-1.7.0/src/nmath/qt.c

Also I've found some other java and C code, normally based on the R project
code. It seems easy to re-use this code, but I would like to use the gsl
libraries and not mix code from here and there...

¿Is there any plan to include functions like this in gsl?
--
Asier ·· NO A LA GUERRA, NO EN MI NOMBRE ·· [ Socio Co-Fundador del K.T.P ]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-29 23:39       ` Asier
@ 2003-04-30  3:13         ` Jason H. Stover
  2003-05-07  0:10           ` Asier
  0 siblings, 1 reply; 9+ messages in thread
From: Jason H. Stover @ 2003-04-30  3:13 UTC (permalink / raw)
  To: gsl-discuss


Yes, there is a cumulative distribution function module
at http://savannah.gnu.org/projects/gsl on the cdf-1-2
branch. Currently there is no function to invert the t
distribution. I may add one in the next few weeks.

If someone else already has a good t quantile function they'd like to
contribute, send it along.

-Jason

On Wed, Apr 30, 2003 at 01:39:10AM +0200, Asier wrote:
> El 29/04/2003, Martin Jansche escribi?:
> 
> > Unless you want to do this via root-finding, you'd need a way to
> 
> Jason H. Stover has pointed me to the R sources, where there's a function
> that computes that value.
> 
> R-1.7.0/src/nmath/qt.c
> 
> Also I've found some other java and C code, normally based on the R project
> code. It seems easy to re-use this code, but I would like to use the gsl
> libraries and not mix code from here and there...
> 
> ?Is there any plan to include functions like this in gsl?
> --
> Asier ?? NO A LA GUERRA, NO EN MI NOMBRE ?? [ Socio Co-Fundador del K.T.P ]
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: T-Student question
  2003-04-30  3:13         ` Jason H. Stover
@ 2003-05-07  0:10           ` Asier
  0 siblings, 0 replies; 9+ messages in thread
From: Asier @ 2003-05-07  0:10 UTC (permalink / raw)
  To: gsl-discuss

El 29/04/2003, Jason H. Stover escribió:

> Yes, there is a cumulative distribution function module
> at http://savannah.gnu.org/projects/gsl on the cdf-1-2
> branch. Currently there is no function to invert the t
> distribution. I may add one in the next few weeks.
> 
> If someone else already has a good t quantile function they'd like to
> contribute, send it along.
> 

In my recent search for this quantile functions I've found one that looks
primising (it's small and GPL!).  It's in java, but translation to C is
really trivial, and also has a applet demo:

http://www.math.uah.edu/psol/applets/QuantileApplet.html

And the source code and javadoc:

http://www.math.uah.edu/psol/objects/edu/uah/math/experiments/QuantileApplet.html

Perhaps you could use this as an idea.
--
Asier ·· NO A LA GUERRA, NO EN MI NOMBRE ·· [ Socio Co-Fundador del K.T.P ]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* T-Student question
@ 2003-04-29 17:31 Asier
  0 siblings, 0 replies; 9+ messages in thread
From: Asier @ 2003-04-29 17:31 UTC (permalink / raw)
  To: gsl-discuss

I need to calculate one of the t-student parameters, but I don't know how to
do it with the gsl library.

If 't' is the tStudent probability, and t_X the probability with 'X' degrees
of freedom P(t_7 < 2.11) I can get it with the gsl_rand_tdist_pdf(x, nu)
function.

    double d = gsl_rand_tdist_pdf(2.11, 7);

¿Ok? How can I calculate the t_(n-1;\alpha) probability 

Given I know the above 'd' and 'nu' numbers, how can I calculate the 'x'
parameter of the function? I've seen tables with this data but I don't know
if there's a 'direct way' to calculate it with gsl.

PD: Excuse my poor english.
--
Asier

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-05-07  0:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-29 17:41 T-Student question Asier
2003-04-29 18:08 ` Martin Jansche
2003-04-29 18:57   ` Asier
2003-04-29 20:21     ` Martin Jansche
2003-04-29 20:39       ` Martin Jansche
2003-04-29 23:39       ` Asier
2003-04-30  3:13         ` Jason H. Stover
2003-05-07  0:10           ` Asier
  -- strict thread matches above, loose matches on Subject: below --
2003-04-29 17:31 Asier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).