[R] Help with cochran.test

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Mon Nov 5 20:08:19 CET 2007


Stephanie Bernard wrote:
> Hi,
> I have been trying to use the function cochran.test from the Outliers 
> package to test for homogeneity of variance. This works well except when 
> I use transformed data. Would anyone have an idea why it doesn't work 
> and how I could do the cochran test on transformed data?
>   
Sounds like the code has a buglet in the handling of nontrivial left
hand sides. Report to the package maintainer.
> Thanks,
> Stephanie
>
>  >library(outliers)
>  > set.seed(1234)
>  > x=rnorm(100)
>  > d=data.frame(x=x,group=rep(1:10,10))
>  > cochran.test(x~group,d)
>
>     Cochran test for outlying variance
>
> data:  x ~ group
> C = 0.1619, df = 10, k = 10, p-value = 0.935
> alternative hypothesis: Group 10 has outlying variance
> sample estimates:
>         1         2         3         4         5         6         
> 7         8         9        10
> 0.9702567 1.0762180 0.9489474 0.9098832 1.1665495 0.9753678 1.2960769 
> 0.8036918 0.7193931 1.7127172
>
>  > cochran.test(log(x)~group,d)
> Error in tapply(data[[bn[1]]], by.factor, var) :
>     arguments must have same length
>   
The straightforward workaround would seem to be

d2 <- transform(d, logx=log(x))
cochran.test(logx~group, d2)

or (maybe)

with(d, {logx <- log(x); cochran.test(logx~group)})



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list