BartlettTest: Bartlett's Test for Homogeneity of Variances (Manual...

View source: R/Bartlett.R

BartlettTestR Documentation

Bartlett's Test for Homogeneity of Variances (Manual Implementation)

Description

Conducts Bartlett's test to evaluate whether multiple groups have equal variances, based on a formula interface and raw data vectors, without requiring a fitted model. This implementation provides flexibility for exploratory variance testing in custom workflows.

Usage

BartlettTest(formula, data, alpha = 0.05)

Arguments

formula

A formula of the form y ~ group, where y is a numeric response and group is a factor indicating group membership.

data

A data frame containing the variables specified in the formula.

alpha

Significance level for the test (default is 0.05).

Details

Bartlett’s test is appropriate when group distributions are approximately normal. It tests the null hypothesis that all groups have equal variances (homoscedasticity).

Advantages: - Straightforward to compute. - High sensitivity to variance differences under normality.

Disadvantages: - Highly sensitive to non-normal distributions. - Less robust than alternatives like Levene’s test for skewed or heavy-tailed data.

Value

An object of class "homocedasticidad", containing:

  • Statistic: Bartlett's chi-squared test statistic.

  • df: Degrees of freedom associated with the test.

  • p_value: The p-value for the test statistic.

  • Decision: A character string indicating the conclusion ("Heterocedastic" or "Homocedastic").

  • Method: A character string indicating the method used ("Bartlett").

References

Bartlett, M. S. (1937). "Properties of sufficiency and statistical tests." Proceedings of the Royal Society of London, Series A, 160(901), 268–282.

Examples

data(d_e, package = "Analitica")
res <- BartlettTest(Sueldo_actual ~ labor, data = d_e)
summary(res)

summary(BartlettTest(Sueldo_actual ~ as.factor(labor), data = d_e))



Analitica documentation built on June 14, 2025, 9:07 a.m.