Last active
July 21, 2021 16:52
-
-
Save RikFerreira/7719dd6ac015f046f3a996ad5d4a3bc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://minato.sip21c.org/swtips/factor-in-R.pdf | |
bartlett.sphericity.test <- function(x) { | |
method <- "Bartlett’s test of sphericity" | |
data.name <- deparse(substitute(x)) | |
x <- subset(x, complete.cases(x)) # Omit missing values | |
n <- nrow(x) | |
p <- ncol(x) | |
chisq <- (1-n+(2*p+5)/6)*log(det(cor(x))) | |
df <- p*(p-1)/2 | |
p.value <- pchisq(chisq, df, lower.tail=FALSE) | |
names(chisq) <- "X-squared" | |
names(df) <- "df" | |
return( | |
structure( | |
list( | |
statistic = chisq, | |
parameter = df, | |
p.value = p.value, | |
method = method, | |
data.name = data.name | |
), | |
class = "htest" | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment