[R] bootstrapping Levene's test

Chuck Cleland ccleland at optonline.net
Tue Feb 20 11:06:24 CET 2007


parsons at uoguelph.ca wrote:
> Hello all,
> 
> I am low down on the learning curve of R but so far I have had little  
> trouble using most of the packages. However, recently I have run into  
> a wall when it comes to bootstrapping a Levene's test (from the car  
> package) and thought you might be able to help. I have not been able  
> to find R examples for the "boot" package where the test statistic  
> specifically uses a grouping variable (or at least a simple example  
> with this condition). I would like to do a  non-parametric bootstrap  
> to eventually get 95% confidence intervals using the boot.ci command.  
> I have included the coding I have tried on a simple data set below. If  
> anyone could provide some help, specifically with regards to how the  
> "statistic" arguement should be set up in the boot package, it would  
> be greatly appreciated.
> 
>> library(boot)
>> library(car)
>> data<-c(2,45,555,1,77,1,2,1,2,1)
>> group<-c(1,1,1,1,1,2,2,2,2,2)
>> levene.test(data,group)
> Levene's Test for Homogeneity of Variance
>        Df F value Pr(>F)
> group  1  1.6929 0.2294
>         8
>> stat<-function(a){levene.test(a,group)}
>> trial1<-boot(data,statistic,100)
> Error in statistic(data, original, ...) : unused argument(s) ( ...)

  One problem is that levene.test() returns an ANOVA table, which is not
a statistic.  Looking inside levene.test() to see what might be used as
a statistic, for the two-group case it seems like you could do something
like this:

library(boot)
library(car)
set.seed(671969)

df <- data.frame(Y = c(rnorm(100,0,1), rnorm(100,0,1)),
                 G = rep(c(1,2), each = 100))

boot.levene <- function(data,indices){
      levene.diff <- diff(tapply(df$Y[indices],
                            list(df$G[indices]), mad))
      return(levene.diff)
      }

first.try <- boot(df, boot.levene, 1000)

first.try

ORDINARY NONPARAMETRIC BOOTSTRAP

Call:
boot(data = df, statistic = boot.levene, R = 1000)


Bootstrap Statistics :
      original     bias    std. error
t1* -0.1944924 0.02439172   0.1753512

boot.ci(first.try, index=1, type="bca")

BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1000 bootstrap replicates

CALL :
boot.ci(boot.out = first.try, type = "bca", index = 1)

Intervals :
Level       BCa
95%   (-0.5772,  0.1159 )
Calculations and Intervals on Original Scale

> Best regards,
> Kevin
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list