3

I'm trying to compute a p-value for a two tailed test following Wikipedia formula which indicates that:

one computes Z, and finds the cumulative probability for a standard normal distribution at -|Z|. For a 2-tailed test, multiply that number by two to obtain the p-value

I'm using this Rust's library which computes Tau value and then you can get the significance from this source code.

The problem is that this calculator (with default values) gives a 2-sided p-value = 0.0389842391014099. Which is far from the p-value I'm getting. The steps I'm following are these:

  1. Compute Tau
  2. Compute the statistical significance: Z with significance = kendall::significance(tau, x.len())
  3. Gets the CDF from Gaussian Distribution with sigma = 1 using this GSL library's function: cdf = gaussian_P(-significance.abs(), 1.0)
  4. Multiply that value by 2

I'm getting a very different value: 0.011946505026920469. I don't understand what I'm missing. Perhaps it's a misunderstanding of Gaussian distribution and it's sigma param. Any kind of help would be really appreciated

Brian Spiering
  • 20,142
  • 2
  • 25
  • 102
Genarito
  • 155
  • 4

1 Answers1

1

It looks like the issue is that you are using the wrong function to compute the cumulative distribution function (CDF) of the normal distribution. The function you are using, gaussian_P(), computes the CDF of the standard normal distribution, with mean 0 and standard deviation 1. However, the Z-score you are using (the output of kendall::significance()) is not necessarily normally distributed with mean 0 and standard deviation 1.

To compute the p-value for your two-tailed test, you need to use the CDF of the normal distribution with mean 0 and the same standard deviation as your Z-score. In the GSL library, this function is called gsl_cdf_gaussian_P(). You can use this function to compute the CDF of the normal distribution with the same standard deviation as your Z-score, and then multiply the result by 2 to get the p-value for your two-tailed test.

For example, if your Z-score has a standard deviation of 1.5, you could compute the p-value as follows:

let z = kendall::significance(tau, x.len());
let p_value = 2 * gsl_cdf_gaussian_P(-z.abs(), 1.5);

This should give you the correct p-value for your two-tailed tests.

Pluviophile
  • 3,520
  • 11
  • 29
  • 49