0

I would like to compute the inverse CDF of Student T distribution using MATLAB without the statistic toolbox but with the help of Python and SciPy, see as well https://stackoverflow.com/a/20627638/7556646.

The following code running from MATLAB R2023a using Python 3.9.13

py.scipy.stats.t().ppf(0.975, df=4)

gives me the following error:

Error using _distn_infrastructure>__init__
Python Error: TypeError: _parse_args() missing 1 required positional argument: 'df'

Error in _distn_infrastructure>freeze (line 824)

Error in _distn_infrastructure>__call__ (line 829)

The argument df is provided but not recognized. I don't understand why? See as well https://ch.mathworks.com/help/matlab/matlab_external/python-function-arguments.html

For a normal distribution I can use SciPy from MATLAB:

py.scipy.stats.norm().ppf(0.975)

returns 1.9600 as expected.

In Python I can do it:

>>> scipy.stats.t.ppf(0.975, df=4)
2.7764451051977987
Wollmich
  • 1,616
  • 1
  • 18
  • 46
  • If in Python you can call `t.ppf(0.975, 4)`, then in MATLAB you should do the same thing. `df=4` is valid in MATLAB for keyword arguments only, but `df` is a positional argument. (The docs you link specify the function as `ppf(q, df, loc=0, scale=1)`, the first two are positional arguments, the latter two are keyword arguments.) Note that you need to use MATLAB syntax, not Python syntax. – Cris Luengo Mar 23 '23 at 13:51
  • @CrisLuengo `py.scipy.stats.t().ppf(0.975, 4)` throws as well an error. `py.scipy.stats.t(df=4).ppf(0.975)` returns the expected result. – Wollmich Mar 24 '23 at 06:59

1 Answers1

0

The following code will work:

>> py.scipy.stats.t(df=4).ppf(0.975)

ans =

    2.7764
Wollmich
  • 1,616
  • 1
  • 18
  • 46