sphstat.modelling module
Functions for correlation, regression, temporal association
xcorrrandomsamples()calculates the cross-correlation between two samplessamplecorrelation()calculates the sample cross-correlationjackknife_corrci()calculates a jeckknife estimate of the CI for the correlation coefficientxcorrsamplevariable()calculates the correlation of a sample with a variableregresscircular()calculates a regression model for a circular variableisnotseriallyassociated()tests the null hypothesis that the samples are independent as opposed to being temporally associated
- sphstat.modelling.isnotseriallyassociated(samplecart: dict, alpha: float = 0.05)[source]
Test the null hypothesis that the observations are independent as opposed to having serial association 1
- Parameters
samplecart (dict) – Sample to be used in the computations in ‘cart’ form
alpha (float) – Type-I error level to be used in the test
- Returns
Dictionary containing the keys: - Sstar: The test statistic (float) - cval: Critical value (float) - testresult: Test result (bool), False if the observations are serially associated
- Return type
dict
- 1
Watson, G. S. & Beran, R. J. (1967). Testing a sequence of unit vectors for randomness. J. Geophys. Res. 72, 5655-5659.
- sphstat.modelling.jackknife_corrci(samplecart1: dict, samplecart2: dict, alpha: float = 0.05) tuple[source]
Jackknife method for calculating an approximate confidence interval for correlation coefficient
- Parameters
samplecart1 (dict) – Sample 1 to be used in the computations in ‘cart’ form
samplecart2 (dict) – Sample 2 to be used in the computations in ‘cart’ form
alpha (float) – (1-alpha)% CI is calculated
- Returns
psijhat: Unbiased estimate using the jackknife method (float)
ci: (1-alpha)% confidence interval (tuple)
- Return type
tuple
- sphstat.modelling.regresscircular(samplecart: dict, thetas: list, alpha0: float, thr: float = 0.01) tuple[source]
Regression of a random unit vector on a circular variable 2
- Parameters
samplecart (dict) – Sample to be used in the computations in ‘cart’ form
thetas (list) – List containing a circular variable
alpha0 (float) – Initial angle for the iterations
thr (float) – Stopping condition for the iterations (Defaults to 1e-15)
- Returns
Uhat: Regression matrix (np.array)
w: np.array([0, 0, 1])
alphahat: The angle to be used in the regression model
fitmodel: Function to predict a value for a given variable [Callable]
- Return type
tuple
- 2
Jupp, P. E. & Mardia, K. V. (1980). A general correlation coefficient for directional data and related regression problems. Biometrika 67, 163-173.
- sphstat.modelling.samplecorrelation(samplecart1: dict, samplecart2: dict, indlist: Optional[list] = None) float[source]
Correlation of two samples
- Parameters
samplecart1 (dict) – Sample 1 to be used in the computations in ‘cart’ form
samplecart2 (dict) – Sample 2 to be used in the computations in ‘cart’ form
indlist – Indices to use for the second sample (use only for the permutation test)
- Returns
Sample cross correlation
- Return type
float
- sphstat.modelling.xcorrrandomsamples(samplecart1: dict, samplecart2: dict, numperms: int, htype: str = '=', alpha: float = 0.05) dict[source]
Correlation coefficient of two random unit vectors and hypothesis test given two samples 3
- Parameters
samplecart1 (dict) – Sample 1 to be used in the computations in ‘cart’ form
samplecart2 (dict) – Sample 2 to be used in the computations in ‘cart’ form
numperms (int) – Number of permutations to be used in the permutation test
htype – Null hypothesis type, ‘!=’ for H0: rho!=0 (no correlation), ‘>’ for H0: rho > 0 (positive correlation), ‘<’ for H0: rho < 0 (negative correlation)
htype – str
alpha (float) – (1-alpha)% CI is calculated
- Returns
Dictionary containing: - rhohat: Correlation coefficient estimate (float) - std: Standard deviation from jackknife estimate (float) - cval’: Critical values (tuple) - ci: (1-alpha)% CI for the correlation coefficient (tuple) - testresult: Hypothesis test result (bool)
- Return type
dict
- 3
Fisher, N. I. & Lee, A. J. (1986). Correlation coefficients for random variables on a unit sphere or hypersphere.
- sphstat.modelling.xcorrsamplevariable(samplecart: dict, variable: list, alpha: float = 0.05)[source]
Correlation between a random unit vector or axis and another random variable Tests the null hypothesis (H0) that the spherical sample and the variable are uncorrelated 4
- Parameters
samplecart (dict) – Sample to be used in the computations in ‘cart’ form
variable (list) – List of floats or 1-D numpy arrays representing a variable associated with the points in the sample
alpha (float) – Type-I error level to be used in the test
- Returns
Dictionary containing… - rhohatg: Correlation coefficient (float) - teststat: Test statistics (float) - cval: Critical value used in the test (float) - testresult: Result of the hypothesis test (bool)
- 4
Jupp, P. E. & Mardia, K. V. (1980). A general correlation coefficient for directional data and related regression problems. Biometrika 67, 163-173.