[R] Bartlett's Test of Sphericity
Daniel Malter
daniel at umd.edu
Sat Jun 18 05:51:50 CEST 2011
The formula for the chi-square value is:
-( (n-1) - (2*p-5)/6 )* log(det(R))
where n is the number of observations, p is the number of variables, and R
is the correlation matrix. The chi square test is then performed on
(p^2-p)/2 degrees of freedom. So you can compute it by hand. Or you can use
the function below (no warranty) where you supply the data as data frame to
the function bartlett.sphere()
example:
x<-rnorm(100)
y<-x+rnorm(100,0,0.1)
bartlett.sphere<-function(data){chi.square=-( (dim(data)[1]-1) -
(2*dim(data)[2]-5)/6 )*
log(det(cor(data,use='pairwise.complete.obs')));cat('chi.square value ',
chi.square , ' on ', (dim(data)[2]^2-dim(data)[2])/2, ' degrees of freedom.'
, ' p-value: ', 1-pchisq(chi.square,(dim(data)[2]^2-dim(data)[2])/2))}
bartlett.sphere(data.frame(x,y))
HTH,
Daniel
thibault grava-3 wrote:
>
> Hello Dear R user,
>
> I want to conduct a Principal components analysis and I need to run two
> tests to check whether I can do it or not. I found how to run the KMO
> test, however i cannot find an R fonction for the Bartlett's test of
> sphericity. Does somebody know if it exists?
>
> Thanks for your help!
>
> Thibault
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
View this message in context: http://r.789695.n4.nabble.com/Bartlett-s-Test-of-Sphericity-tp3606765p3607184.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list