# How to solve for an Z-Score of a T-Distribution?

I'm looking for the Z-Score for a distribution, where the integrated area sums up to 0.90. Unfortunately I always get an error from Mathematica, "nonnumerical value". Does someone know why?

Solve[NIntegrate[PDF[StudentTDistribution[49], x], {x, -Infinity, y}] == 0.95, y]


I tried as well

Solve[StudentTPValue[x, 49] == 0.10, x]


How can one get only the value as an output? I ultimately want to test a hypothesis value to check if they are in the 0.95±∞ part of a Student-t distribution.

-
Search for ?NumericQ for more information about why the first line does not work. – Searke Mar 28 '12 at 13:36
objective[y_?NumericQ] := NIntegrate[PDF[StudentTDistribution[49], x], {x, -Infinity, y}]; InverseFunction[objective][0.95] – Searke Mar 28 '12 at 13:37
What is the problem with just using the built-in solution InverseCDF[StudentTDistribution[49], 0.95]? – whuber Mar 28 '12 at 16:57

Have you tried FindRoot? It's a numerical function looking for a root given some starting location. In addition to that, you can get around integrating by using CDF instead of PDF in the first place:

FindRoot[CDF[StudentTDistribution[49], y] == 0.95, {y, 1}]

{y -> 1.67655}


If you're interested, the reason why your first approach doesn't work: NIntegrate cannot use placeholders, it has to evaluate to a number in all cases. What you're trying to do is equivalent to NIntegrate[x*y, {x,0,1}], and the program complains that it does not know the full integrand since y is undefined, therefore it cannot be evaluated. The fact that you've wrapped a Solve, which inserts the missing variable (x in your case) after NIntegrate has been evaluated, does not have any impact on that.

-
thank you for your help, both solutions work well, sometimes I feel like its very hard to compute with mathematica, the next time I think again its so convenient :P – PeriodicProgrammer Feb 28 '12 at 17:48

David's method is the route I would go if I didn't want to use Quantile for some reason.

Quantile[StudentTDistribution[49], .95]

==> 1.67655


If you really want to use PDF's to demonstrate this you can still use FindRoot by first setting the integration up so that it only accepts numeric input.

f[y_?NumericQ] := NIntegrate[PDF[StudentTDistribution[49], x], {x, -Infinity, y}]

FindRoot[f[y] == 0.95, {y, 1}]

==> {y -> 1.67655}

-