Skip to content

statistics.py


pycmtensor.statistics

PyCMTensor statistics module

This module contains methods for calculating the statistics of the estimated parameters.

Functions: - variance_covariance(hessian): Computes the variance covariance matrix given the Hessian. - rob_variance_covariance(hessian, bhhh): Computes the robust variance covariance matrix given the Hessian and BHHH matrices. - t_test(stderr, params): Computes the statistical t-test of the estimated parameters and the standard errors. - p_value(stderr, params): Computes the p-value (statistical significance) of the estimated parameters using the two-tailed normal distribution. - stderror(hessian, params): Calculates the standard error of the estimated parameters given the Hessian matrix. - rob_stderror(hessian, bhhh, params): Calculates the robust standard error of the estimated parameters given the Hessian and BHHH matrices. - correlation_matrix(hessian): Computes the correlation matrix from the Hessian matrix. - rob_correlation_matrix(hessian, bhhh): Computes the robust correlation matrix from the Hessian and BHHH matrices.

variance_covariance(hessian)

computes the variance covariance matrix given the Hessian

Parameters:

Name Type Description Default
hessian ndarray

a 2-D hessian matrix

required

Returns:

Type Description
ndarray

the variance covariance matrix

Notes

The variance covariance matrix is calculated by taking the inverse of the (negative) hessian matrix. If the inverse is undefined, returns a zero or a large finite number.

\[ varcovar = -H^{-1} \]

rob_variance_covariance(hessian, bhhh)

computes the robust variance covariance matrix given the Hessian and the BHHH matrices

Parameters:

Name Type Description Default
hessian ndarray

the hessian matrix

required
bhhh ndarray

the BHHH matrix

required

Returns:

Type Description
ndarray

the robust variance covariance matrix

Notes

The robust variance covariance matrix is computed as follows:

\[ rob. varcovar = (-H)^{-1}\cdot BHHH\cdot (-H)^{-1} \]

t_test(stderr, params)

computes the statistical t-test of the estimated parameter and the standard error

Parameters:

Name Type Description Default
stderr Series

standard errors

required
params dict

estimated parameters

required

Returns:

Type Description
list

t-test of the estimated parameters

p_value(stderr, params)

computes the p-value (statistical significance) of the estimated parameter using the two-tailed normal distribution, where p-value=\(2(1-\phi(|t|)\), \(\phi\) is the cdf of the normal distribution

Parameters:

Name Type Description Default
stderr Series

standard errors

required
params dict

estimated parameters

required

Returns:

Type Description
list

p-value of the estimated parameters

stderror(hessian, params)

calculates the standard error of the estimated parameter given the hessian matrix

Parameters:

Name Type Description Default
hessian ndarray

the hessian matrix

required
params dict

estimated parameters containing numpy arrays

required

Returns:

Type Description
list

the standard error of the estimates

Note

The standard errors is calculated using the formula:

\[ stderr = \sqrt{diag(-H^{-1})} \]

rob_stderror(hessian, bhhh, params)

calculates the robust standard error of the estimated parameter given the hessian and the bhhh matrices

Parameters:

Name Type Description Default
hessian ndarray

the hessian matrix

required
bhhh ndarray

the bhhh matrix

required
params dict

estimated parameters

required

Returns:

Type Description
list

the robust standard error of the estimates

Note

The robust standard errors is calculated using the formula:

\[ rob. stderr = \sqrt{diag(rob. varcovar)} \]

correlation_matrix(hessian)

computes the correlation matrix from the hessian matrix

Parameters:

Name Type Description Default
hessian ndarray

the hessian matrix

required

Returns:

Type Description
ndarray

the correlation matrix

rob_correlation_matrix(hessian, bhhh)

computes the robust correlation matrix from the hessian and bhhh matrix

Parameters:

Name Type Description Default
hessian ndarray

the hessian matrix

required
bhhh ndarray

the bhhh matrix

required

Returns:

Type Description
ndarray

the tobust correlation matrix