Learn R Programming

olsrr (version 0.4.0)

ols_bartlett_test: Bartlett Test

Description

Test if k samples are from populations with equal variances.

Usage

ols_bartlett_test(variable, ...)

# S3 method for default ols_bartlett_test(variable, ..., group_var = NA)

# S3 method for lm ols_bartlett_test(variable, ...)

# S3 method for formula ols_bartlett_test(variable, data, ...)

Arguments

variable

a numeric vector/an object of class formula or lm

...

numeric vectors

group_var

grouping variable

data

a data frame

Value

ols_bartlett_test returns an object of class "ols_bartlett_test". An object of class "ols_bartlett_test" is a list containing the following components:

fstat

f statistic

pval

p-value of fstat

df

degrees of freedom

var_c

name(s) of variable

g_var

name of group_var

Details

Bartlett's test is used to test if variances across samples is equal. It is sensitive to departures from normality. The Levene test is an alternative test that is less sensitive to departures from normality.

References

Snedecor, George W. and Cochran, William G. (1989), Statistical Methods, Eighth Edition, Iowa State University Press.

Examples

Run this code
# NOT RUN {
# using grouping variable
model <- lm(mpg ~ disp + hp, data = mtcars)
resid <- residuals(model)
cyl <- as.factor(mtcars$cyl)
ols_bartlett_test(resid, group_var = cyl)
# }
# NOT RUN {
# }
# NOT RUN {
# using variables
ols_bartlett_test(hsb$read, hsb$write)
# }
# NOT RUN {
# }
# NOT RUN {
# using formula
mt <- mtcars
mt$cyl <- as.factor(mt$cyl)
ols_bartlett_test(mpg ~ cyl, data = mt)
# }
# NOT RUN {
# }
# NOT RUN {
# using model
model <- lm(mpg ~ cyl, data = mt)
ols_bartlett_test(model)
# }

Run the code above in your browser using DataLab