2
$\begingroup$

i wanted to calculate a Student-t table with

m = 
Table[
  NSolve[
    Rationalize[
      Integrate[PDF[StudentTDistribution[0, 1, df], x], {x, -a, a}] == 
      Vertrauensintervall/100
    ], a, Reals
  ], 
  {df, 3, 30, 1}, 
  {Vertrauensintervall, {80, 90, 95, 98, 99, 99.73}}
]

but when I export it now to Excel, I get 30 sheets of those 6 values each :(

How can I tell Mathematica, to put it all in one sheet? (bonus would be formatted with just the value, without the a -> )

$\endgroup$
  • $\begingroup$ try a/.First@NSolve $\endgroup$ – george2079 Oct 3 '14 at 10:49
3
$\begingroup$
Export["matrix.csv", m[[All, All, 1, 1, 2]]]

should do the trick.

| improve this answer | |
$\endgroup$
2
$\begingroup$

Your table can be generated much easier and considerably faster using

c = CDF[StudentTDistribution[0, 1, df], a] - 
    CDF[StudentTDistribution[0, 1, df], -a] // FullSimplify

m = Table[
      a /. FindRoot[c == Vertrauensintervall/100., {a, 0.1}], 
     {df, 3, 30, 1}, 
     {Vertrauensintervall, {80, 90, 95, 98, 99, 99.73}}
    ];

This exports to a single Excel sheet if you use:

Export["test.xls", m]

The CDF is the integrated PDF which Mathematica knows in algebraic form in the case of the StudentTDistribution. So, no need to integrate yourself.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much, i am a mathematica beginner, so it took me a while to even come up with my formula :) $\endgroup$ – Stephan Ketterer Oct 3 '14 at 11:08
2
$\begingroup$

You can also use the built-in function Quantile without having to use Solve or FindRoot.

m2 = Table[Quantile[StudentTDistribution[0, 1, df], (100 + Vertrauensintervall)/ 200.],
          {df, 3, 30, 1}, {Vertrauensintervall, {80, 90, 95, 98, 99, 99.73}}];

The result is identical to the one you get using the method suggested by @Sjoerd (to the deafult tolerance of 10^(-10) )

Chop[Norm[m - m2]] === 0
(* True *) 

Export["test.xls", m2]
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.