Re: R-alpha: ANNOUNCE: ctest

Kurt Hornik (Kurt.Hornik@ci.tuwien.ac.at)
Wed, 22 Jan 1997 12:53:16 +0100


Date: Wed, 22 Jan 1997 12:53:16 +0100
Message-Id: <199701221153.MAA28451@aragorn.ci.tuwien.ac.at>
From: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
To: Peter Dalgaard BSA <pd@kubism.ku.dk>
Subject: Re: R-alpha: ANNOUNCE: ctest
In-Reply-To: <x2680rc5mv.fsf@bush.kubism.ku.dk>
 <x2680rc5mv.fsf@bush.kubism.ku.dk>

>>>>> On 21 Jan 1997 18:14:32 +0100,
>>>>> Peter Dalgaard BSA <pd@kubism.ku.dk> said:

> Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:
>> 
>> A new version of my `ctest' collection of classical tests for R is now
>> available for ftp at the URL
>> 
>> ftp://ftp.ci.tuwien.ac.at/pub/export/R/ctest.tar.gz
>> 
>> It contains the functions
>> 
>> binom.test	Exact Binomial Test
>> chisq.test	Pearson's Chi-Square Test for Count Data
>> cor.test	Test for Zero Correlation
>> fisher.test	Fisher's Exact Test for Count Data
>> friedman.test	Friedman Rank Sum Test
>> kruskal.test	Kruskal-Wallis Rank Sum Test
>> ks.test		Kolmogorov-Smirnov Tests
>> mantelhaen.test	Mantel-Haenszel Chi-Square Test for Count Data
>> mcnemar.test	McNemar's Chi-Square Test for Count Data
>> prop.test	Test for Equal or Given Proportions
>> var.test	F Test to Compare Two Variances
>> wilcox.test	Wilcoxon Rank Sum and Signed Rank Tests

> Great! Of course, more wants more, so.... 

> Wanted:

> bartlett.test

> ...

A version of bartlett.test() is attached.  It is not yet in ctest
because the current usage is

	bartlett.test(x, y, z)

if you want to compare the samples x, y, and z for homogeneity of
variances, but I think it would be better to have

	bartlett.test(x, g)

where x contains all samples and g the group labels.

What do the others think?

-k

******************************************************************
bartlett.test := function (...)
{
  DNAME <- paste(as.character(substitute(list(...)))[-1],
		 collapse = " and ")
  l <- list(...)
  k <- length(l)
  if (k < 2)
    stop("at least 2 arguments are required")
  n <- real(k)
  v <- real(k)
  for (i in 1:k)
    {
      x <- l[[i]]
      x <- x[!is.na(x)]
      n[i] <- length(x) - 1
      if (n[i] < 1)
	stop(paste("input argument", i, "does not contain enough data"))
      else if (n[i] < 3)
	warning("Results may be insignificant")
      v[i] <- var(x)
    }
  n.total <- sum(n)
  v.total <- sum(n * v) / n.total
  STATISTIC <- ((n.total * log(v.total) - sum(n * log(v))) /
		(1 + (sum(1/n) - 1/n.total) / (3*(k-1))))
  names(STATISTIC) <- "Bartlett's K-square"
  PARAMETER <- k - 1
  names(PARAMETER) <- "df"
  RVAL <- list(statistic = STATISTIC, parameter = PARAMETER,
	       p.value = 1 - pchisq(STATISTIC, PARAMETER),
	       alternative = "two.sided", data.name = DNAME,
	       method = "Bartlett test for homogeneity of variances")
  class(RVAL) <- "htest"
  return(RVAL)
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-