Skip to content

Z-test

3 messages · Joshua Wiley, Rolf Turner

#
Hi,

The Z is basically:

(mean(x) - mean(y))/sqrt(var(x)/length(x) + var(y)/length(y))

and pnorm will give you a p-value, if you desire it.

If the n - 1 divisior used in var() is a problem for you, it is
trivial to work around:

X <- cbind(x, y)
XX <- crossprod(X - tcrossprod(matrix(1, nrow(X))) %*% X *
(1/nrow(X))) * 1/nrow(X)
diff(colMeans(X))/sqrt(sum(diag(XX)/nrow(X)))

where the last line gives the Z and again, pnorm() will give you a
p-value if desired.

In most cases a t-test is preferred (and is available using the t.test
function).

HTH,

Josh
On Fri, Jul 15, 2011 at 9:56 PM, Bogdan Tanasa <tanasa at gmail.com> wrote:

  
    
#
On 16/07/11 17:49, Joshua Wiley wrote:
<SNIP>

(1) Why on earth should the n - 1 divisor be a problem?  This divisor
yields an unbiased estimator of sigma^2.  Generally speaking,
unbiasedness is a Good Thing.

(2) If a Z-test (rather than a t-test) is being done then this issue simply
does not arise.   In the context of a Z-test, the variances are ***known***
quantities and so do not get estimated.  So there is no divisor to *be* a
problem.

     cheers,

         Rolf
#
On Sat, Jul 16, 2011 at 12:05 AM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
Yes, it is an unbiased estimator of sigma^2 for a sample.  My response
was predicated on the assumption the OP was choosing a Z-test because
data on the entire population was available hence no need to use an
estimate.
But if raw data from the entire population is all that is available,
then the "known" variances still need to be calculated though not
estimated.  var() does not do this directly which is why I offered an
alternative.

Josh