R의 Levene 테스트

Sheeraz Gul 2024년2월15일
R의 Levene 테스트

Levene의 검정은 여러 그룹에 대해 결정된 변수에 대한 분산의 동등성을 평가합니다. 이 튜토리얼은 R에서 Levene의 테스트를 수행하는 방법을 보여줍니다.

R의 Levene 테스트

Levene의 검정은 여러 그룹에 대해 결정된 변수에 대한 분산의 동등성을 평가합니다. 테스트는 모집단 분산이 동질성 또는 동질성이라고 하는 귀무 가설을 검사하고 k가 여러 표본일 수 있는 k 표본의 분산을 비교합니다.

Levene의 검정은 덜 민감한 Barlett의 검정에 대한 대안입니다. R 언어에는 Levene 테스트를 수행하는 leveneTest() 메서드가 있습니다. 이 메서드는 R 언어의 케어 패키지에서 가져온 것입니다.

먼저 car 패키지가 아직 설치되지 않은 경우 설치해야 합니다.

install.packages('car')

자동차 패키지가 설치되면 Levene 테스트를 수행할 수 있습니다.

코드 예:

library(car)
person_weight <- data.frame(weight_program = rep(c("Program1", "Program2", "Program3"), each = 40),
                   weight_loss = c(runif(40, 0, 4),
                                   runif(40, 0, 6),
                                   runif(40, 1, 8)))

#first six rows of data frame
head(person_weight)

#conduct Levene's Test to check equality of variances
leveneTest(weight_loss ~ weight_program, data = person_weight)

위의 스니펫은 세 가지 다른 체중 감량 프로그램으로 데이터 프레임을 생성하며, 이는 사람들이 다른 프로그램에서 얼마나 많은 체중을 감량했는지 보여줍니다. 먼저 코드는 데이터 프레임의 헤드를 표시한 다음 Levene의 테스트를 수행합니다.

출력:

  weight_program weight_loss
1       Program1    1.027946
2       Program1    2.147631
3       Program1    3.181947
4       Program1    3.933521
5       Program1    3.093434
6       Program1    3.652795

Levene's Test for Homogeneity of Variance (center = median)
       Df F value   Pr(>F)
group   2  5.2128 0.006782 **
      117
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Levene 검정의 p-값은 0.006782이며 유의 수준 0.05보다 작습니다. 따라서 Levene의 검정 개념에 따라 귀무가설을 기각하므로 세 그룹 간의 분산이 동일하지 않습니다.

무게 분포를 보여주기 위해 박스 그래프를 그려봅시다.

boxplot(weight_loss ~ weight_program,
        data = person_weight,
        main = "Weight Loss Distribution by the Weight Program",
        xlab = "Weight Program",
        ylab = "Weight Loss",
        col = "grey90",
        border = "black")

박스 플롯 출력:

중량 분포를 표시하기 위해 상자 그래프를 플로팅

작가: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

관련 문장 - R Test