[R] levene.test

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Jul 14 14:28:11 CEST 2010


On Wed, 2010-07-14 at 05:07 -0700, martanair wrote:
> I am trying to use Levene's test (of package car), but I do 
> not understand quite well how to use it. '?levene.test' does 
> not unfortunately provide any example. My data are in a data 
> frame and correspond to 1 factor plus response. Could 
> someone please give me an example about how to use the command 

This doesn't really help us much as you don't tell us what you don't
understand. So what don't you understand? For example, if the data are
set-up correctly, such that:

> str(dat)
'data.frame':	25 obs. of  3 variables:
 $ fertilizzante: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 2 ...
 $ x            : num  55 60 48 44 63 60 50 56 54 100 ...
 $ y            : num  502 532 525 444 527 531 478 530 547 619 ...

so we have fertilizzante as a factor and x and y components numeric,
then I get:

> require(car)
> with(dat, levene.test(y, fertilizzante))
Levene's Test for Homogeneity of Variance
      Df F value  Pr(>F)  
group  1  5.7969 0.02447 *
      23                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Is that what you get for the list line of the code you provided?

If you need help with the interpretation, well that is another matter
and only the simplest help, in general, can be given in a mailing list
format such as this. That said, the results above suggest that the
observed statistic is unlikely to have arisen if the null hypothesis (of
equal variances in your two levels of fertilizzante) were true.

Here is an example where we generate two populations with almost equal
variances, and the output from the test is (using G from my earlier
email):

> dat <- data.frame(Y = c(rnorm(20, sd = 1), rnorm(20, sd = 1.1)), G =
G)
> with(dat, levene.test(Y, G))
Levene's Test for Homogeneity of Variance
      Df F value Pr(>F)
group  1  0.0798 0.7791
      38

Here an F value as larger as 0.0798 (observed) is quite likely to have
arisen if the null hypothesis were true, hence in this second case we'd
have no evidence to reject the null hypothesis and we might conclude
that for these data the variances of the two populations were "similar".

Does this help?

G

>    
> levene.test(y, group) 
>  
> Thanks in advance, 
>    
> marta 
>  
> filedati=read.table("filedati.txt",header=TRUE)
> filedati
> modello=aov(filedati$y ~ filedati$fertilizzante)
> anova(modello)
> str(filedati$fertilizzante)
> filedati$fertilizzante=factor(filedati$fertilizzante)
> filedati$fertilizzante
> library(car)
> levene.test(filedati$y , filedati$fertilizzante)
>  
> 
> 
> 
> filedati
>  fertilizzante	x	y
> 1	55	502
> 1	60	532
> 1	48	525
> 1	44	444
> 1	63	527
> 1	60	531
> 1	50	478
> 1	56	530
> 1	54	547	
> 2	100	619
> 2	75	425
> 2	52	400
> 2	62	418
> 2	68	449
> 2	86	525
> 2	57	470
> 2	82	506
> 2	72	507
> 2	88	495
> 2	55	393
> 2	67	515
> 2	45	382
> 2	103	570
> 2	103	611
> 2	84	473
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list