psytest.critval.critval module#

psytest.critval.critval#

Module to handle the tables in the psytest.critval.data directory. The main function is psytest.critval.critval_tabulated(), which calculates the critical values for a given set of parameters. Given the parameters, the function gets the best table to use, based on the precision of the simulations used for each table (see psytest.critval.critval.find_best_table() for more info). The values in the best match are then interpolated to return the critical values for every input value of psytest.critval.critval_tabulated.r2_eval.

psytest.critval.critval.make_colname_from_alpha(alpha: float) str[source]#

Create a column name from the alpha value.

psytest.critval.critval.find_best_table(kmax: int, r0: float) str[source]#

Finds the table with the best match for the given parameters. It sorts tables by their nreps (ascending), nobs (ascending), and rstep (descending). It then returns the one with the best value of these that satisfies the condition of having the given kmax and r0 as low as given.

Parameters:
  • kmax (int) – Maximum lag for the critical value table.

  • r0 (float) – Minimum index to evaluate the test statistics.

Returns:

table_name – The name of the table with the best match for the given parameters, or None if no match is found.

Return type:

str

psytest.critval.critval.load_critval(kmax: int, r0: float) DataFrame[source]#

Loads the critical values from the CSV file in the data directory.

Parameters:
  • kmax (int) – Maximum lag for the critical value table.

  • r0 (float) – Minimum index to evaluate the test statistics.

Returns:

critval_table – A DataFrame containing the critical values. The first column correspond to the r2 parameter. The remaining columns give, for each r2 the critical values with significance levels as the column names.

Return type:

DataFrame

psytest.critval.critval.critval_tabulated(r2_eval: float, kmax: int, r0: float, alpha: float = 0.05) float[source]#
psytest.critval.critval.critval_tabulated(r2_eval: Iterable[float], kmax: int, r0: float, alpha: float = 0.05) ndarray[tuple[int, ...], dtype[float64]]

Returns the critical values for all r2 in r2_eval from the tabulated values in the psytest.critval.data directory.

Parameters:
  • r2_eval (float | Iterable[float]) – The r2 value or an array of r2 values.

  • alpha (float, optional) – The significance level. Defaults to 0.05.

  • kmax (int) – Maximum lag for the critical value table.

  • r0 (float) – Minimum index to evaluate the test statistics.

Returns:

critval_table – The critical values for the given r2_eval (if single) or an array of critical values.

Return type:

NDArray[float64] | float

Raises:
  • TypeError – If r2_eval is not a float or an iterable; if alpha is not a float; if kmax is not an integer; if r0 is not a float.

  • ValueError – If r2_eval is not between 0 and 1; if alpha is not between 0 and 1; if kmax is negative; if r0 is not between 0 and 1; if the critical value for the given alpha is not found in the table.