집단간 차이분석 예제

hottogi·2022년 11월 4일
0

1. 교육 방법에 따라 시험성적에 차이가 있는지 검정하시오

(힌트. 두 집단 평균 차이 검정)
1) 데이터셋: twomethod.csv
2) 변수: method(교육방법), score(시험성적)
3) 모델: 교육방법(명목) -> 시험성적(비율)
4) 전처리, 결측치 제거

# 1번
data <- read.csv("C:/Rwork/dataset2/twomethod.csv", header = TRUE)
head(data)
summary(data)

result <- subset(data, !is.na(score), c(method, score))

a <- subset(result, method == 1)
b <- subset(result, method == 2)
a1 <- a$score
b1 <- b$score

length(a1)
length(b1)
mean(a1)
mean(b1)

var.test(a1, b1)

t.test(a1, b1, altr = "two.sided", 
       conf.int = TRUE, conf.level = 0.95)

# 양측검정 결과 p-value < 0.05 이므로 귀무가설 기각
# 시험성적에 차이가 있음.

2. 대학에 진학한 남학생과 여학생을 대상으로 진학한 대학에 대해서 만족도에 차이가 있는가를 검정하시오.

(힌트. 두 집단 비율 차이 검정)
1) 데이터셋: two_sample.csv
2) 변수: gender(1,2), survey(0, 1)

setwd("C:/Rwork/ ")
data <- read.csv("dataset2/two_sample.csv", header = TRUE)
head(data)

x <- data$gender
y <- data$survey

table(x)
table(y)
table(x, y, useNA = "ifany")

prop.test(c(138, 107), c(174, 126),
          alternative = "two.sided", conf.level = 0.95)

prop.test(c(138, 107), c(174, 126),
          alter = "greater", conf.level = 0.95)
prop.test(c(138, 107), c(174, 126), 
          alter = "less", conf.level = 0.95)

# p-value > 0.05 이므로 귀무가설 채택
# 만족도에 차이가 없음

3. 우리나라 전체 중학교 2 학년 여학생 평균 키가 148.5cm 로 알려진 상태에서 A 중학교 2 학년 전체 500 명을 대상으로 10%인 50 명을 표본으로 선정하여 표본평균 신장을 계산하고 모집단의 평균과 차이가 있는 지를 단계별로 분석을 수행하여 검정하시오.

1) 데이터셋: student_height,csv
2) height <- stheight$height
3) 기술통계량 평균 계산
4) 정규성 검정
5) 가설 검정

# 1)
setwd("C:/Rwork/ ")
stheight <- read.csv("dataset2/student_height.csv", header = TRUE)
head(stheight)

# 2)
height <- stheight$height

# 3)
mean(height, na.rm = T)
x1 <- na.omit(height)
mean(x1)

4. 중소기업에서 생산한 HDTV 판매율을 높이기 위해서 프로모션을 진행한 결과 기존 구매비율보다 15% 향상되었는지를 단계별로 분석을 수행하여 검정하시오.

귀무가설(H0):
연구가설(H1):
1) 구매여부 변수: buy (1: 구매하지 않음, 2: 구매)
2) 데이터셋: hdtv.csv
3) 빈도수와 비율 계산
4) 가설 검정

# 귀무가설: 기존 HDTV 판매율과 프로모션 후 HDTV 판매율에 차이가 없다.
# 연구가설: 기존 HDTV 판매율과 프로모션 후 HDTV 판매율에 차이가 있다.

setwd("C:/Rwork/ ")
data <- read.csv("dataset2/hdtv.csv", header = TRUE)
head(data)

x <- data$buy

summary(x)
length(x)
table(x)

library(prettyR)
freq(x)

binom.test(10, 50, p = 0.15)

binom.test(c(10, 50), p = 0.15, 
           alternative = "greater", conf.level = 0.95)

binom.test(c(10, 50), p = 0.15, 
           alternative = "less", conf.level = 0.95)

# p value가 0.05 이상이므로 귀무가설 채택
# 판매율에 차이가 없다
profile

0개의 댓글

관련 채용 정보