5. Stat - HeloiseS/FUSS GitHub Wiki

The sub-module FUSS.stat contains functions I use for statistical analysis.

Co-variance Matrix

The following 2 functions may later be removed as I now know of numpy.cov, which evaluates the co-variance matrix given data and weights.

cov_el():

Provides the value of one element of the co-variance matrix (so either a variance or the co-variance depending on the indices specified).

Parameters

  • j (int): Column number
  • k (int): Row number
  • q (1D Array): Data set of first variable.
  • q_r (1D Array): Error on the first data set
  • u (1D Array): Data set of second variable.
  • u_r (1D Array): Error on the second data set

/!\ q, q_r, u, u_r must all have the same dimension.

Returns

  • Element C(j,k) of the Covariance matrix C

cov_mat()

Creates co-variance matrix C for 2 variables.

Parameters

  • q (1D Array): Data set of first variable.
  • q_r (1D Array): Error on the first data set
  • u (1D Array): Data set of second variable.
  • u_r (1D Array): Error on the second data set

/!\ q, q_r, u, u_r must all have the same dimension.

Returns

  • Covariance matrix C

Principal Components Analysis (PCA)

Makes use of cov_matrix().

pca()

Performs PCA on data provided.

Parameters

  • q (1D Array): Data set of first variable.
  • u (1D Array): Data set of second variable.
  • q_r (1D Array): Error on the first data set
  • u_r (1D Array): Error on the second data set

Returns

  • Axis ratio (b/a), rotation angle of the major axis (in degrees), rotation angle of the minor axis (also in degrees).

draw_ellipse()

Creates an ellipse that best fits the data to be drawn onto the q-u plane.

Parameters

  • q (1D Array): Data set of first variable.
  • u (1D Array): Data set of second variable.
  • a (float): Length of the major axis. Just pick a number that makes the ellipse look nice on top of the data.
  • alpha_dom (float): Rotation angle of the major axis (in degrees).

Returns

  • The ellipse, to be used as input of the function add_artist() from matplotlib.axes

Pearson Test

Makes use of cov_el().

pearson()

Perform a Pearson's test on the data provided. All arrays must have the same length.

Parameters

  • q (1D Array): Data set of first variable.
  • u (1D Array): Data set of second variable.
  • q_r (1D Array): Error on the first data set
  • u_r (1D Array): Error on the second data set

Returns

  • Pearson's coefficient

Orthogonal Distance Regression (ODR) fits

func()

Just a linear function. Used by odr_fit.

Parameters

  • beta (1D Array): [Intercept, Gradient]
  • *x (1D Array): Independent variable

Returns

  • 1D Array: y (dependent variable)

odr_fit()

Does what it says on the tin, an ODR fit.

Parameters

  • x (1D Array): x
  • xr (1D Array): errors on x
  • y (1D Array): y
  • yr (1D Array): errors on y

Returns

  • Gradient, error on gradient, intercept, error on intercept.