Nonparametric

Nonparametric — selected nonparametric routines

Functions

int spearman_rho ()
int kendall_tau ()
double lockes_test ()
int runs_test ()
int diff_test ()
int sort_pairs_by_x ()
gretl_matrix * loess_fit ()

Object Hierarchy


Includes

#include <libgretl.h>

Description

Includes various nonparametric tests: rank correlation, runs (randomness), and differences between series. Also "loess" regression a la William Cleveland.

Functions

spearman_rho ()

int
spearman_rho (const int *list,
              const DATASET *dset,
              gretlopt opt,
              PRN *prn);

Calculates and prints Spearman's rank correlation coefficient for the two variables specified in the list .

Parameters

list

list of (two) variables to process.

 

dset

dataset struct.

 

opt

if includes OPT_V, print both the "raw" and the ranked data.

 

prn

gretl printing struct.

 

Returns

0 on successful completion, 1 on error.


kendall_tau ()

int
kendall_tau (const int *list,
             const DATASET *dset,
             gretlopt opt,
             PRN *prn);

Calculates and prints Kendall's rank correlation tau statistic for the two variables specified in list .

Parameters

list

list of (two) variables to process.

 

dset

dataset struct.

 

opt

if includes OPT_V, print both the "raw" and the ranked data.

 

prn

gretl printing struct.

 

Returns

0 on successful completion, 1 on error.


lockes_test ()

double
lockes_test (const double *x,
             int t1,
             int t2);

Performs Charles Locke's nonparametric test for whether an empirical distribution (namely, that of x over the range t1 to t2 ) is gamma. See C. Locke, "A Test for the Composite Hypothesis that a Population has a Gamma Distribution," Commun. Statis.-Theor. Meth. A5(4), 351-364 (1976). Also see Shapiro and Chen, Journal of Quality Technology 33(1), Jan 2001.

Parameters

x

data series.

 

t1

start of sample range.

 

t2

end of sample range.

 

Returns

the z value for test, or NADBL on error.


runs_test ()

int
runs_test (int v,
           const DATASET *dset,
           gretlopt opt,
           PRN *prn);

Performs, and prints the results of, the runs test for randomness for the variable specified by v . The normal approximation is that given in Gary Smith, Statistical Reasoning, 2e, p. 674.

Parameters

v

ID number of the variable to process.

 

dset

dataset struct.

 

opt

OPT_D to use first difference of variable, OPT_E to assume positive and negative are equiprobable.

 

prn

gretl printing struct.

 

Returns

0 on successful completion, non-zero on error.


diff_test ()

int
diff_test (const int *list,
           const DATASET *dset,
           gretlopt opt,
           PRN *prn);

Performs, and prints the results of, a non-parametric test for a difference between two variables or groups. The specific test performed depends on opt .

Parameters

list

list containing 2 variables.

 

dset

dataset struct.

 

opt

OPT_G, sign test; OPT_R, rank sum; OPT_I, signed rank; OPT_V, verbose (for rank tests).

 

prn

gretl printing struct.

 

Returns

0 on successful completion, non-zero on error.


sort_pairs_by_x ()

int
sort_pairs_by_x (gretl_matrix *x,
                 gretl_matrix *y,
                 int **order,
                 char **labels);

Orders the elements of x and y by increasing value of x . Optionally, returns in order an array of integers representing the order in which the original observations appear in the sorted vectors. Also optionally sorts an accomanying array of observation labels.

Parameters

x

data vector by which to sort.

 

y

data vector.

 

order

location to receive sort order, or NULL.

 

labels

array of strings to be sorted along with the data, or NULL.

 

Returns

0 on successful completion, non-zero on error.


loess_fit ()

gretl_matrix *
loess_fit (const gretl_matrix *x,
           const gretl_matrix *y,
           int d,
           double q,
           gretlopt opt,
           int *err);

Computes loess estimates based on William Cleveland, "Robust Locally Weighted Regression and Smoothing Scatterplots", Journal of the American Statistical Association, Vol. 74 (1979), pp. 829-836. Typically one expects that d = 1 and q is in the neighborhood of 0.5.

The x,y pairs must be pre-sorted by increasing value of x ; an error is flagged if this is not the case. See also sort_pairs_by_x().

Parameters

x

x-axis variable (must be pre-sorted).

 

y

response variable.

 

d

order for polynomial fit (0 <= d <= 2).

 

q

bandwidth (0 < q <= 1).

 

opt

give OPT_R for robust variant (with re-weighting based on the first-stage residuals).

 

err

location to receive error code.

 

Returns

allocated vector containing the loess fitted values, or NULL on failure.

Types and Values