소품집

[다변량 분석] Survey Data를 이용한 다변량분석 본문

Statistics

[다변량 분석] Survey Data를 이용한 다변량분석

sodayeong 2021. 9. 29. 23:31

 

setwd('/Users/dayeong/Desktop/21-2/전공/다변량 분석')

# 범주형 데이터 분석
# MASS 패키지의 내장된 데이터(survey) 활용
library(MASS)
library(ggplot2)
data_s <- survey
View(data_s)
?survey

# 독립 표본 t-검정(1)
# Pulse - Sex
var.test(Pulse~Sex, data=data_s)
boxplot(Pulse~Sex, data=data_s, main='Sex ~ Pulse BoxPlot')
t.test(Pulse~Sex, data=data_s, var.equal=T)

var.test(Height~Sex, data=data_s)
t.test(Height~Sex, data=data_s,var.equal=F )

# anova 분석-1
summary(aov(data_s$Height~data_s$Exer))
boxplot(Height~Exer, data=data_s, main='Height~Exer BoxPlot')
summary(aov(data_s$Age~data_s$Exer))


# anova 분석-2
summary(data_s$Age)
summary(aov(data_s$Age~data_s$Exer))
boxplot(Age~Exer, data=data_s, main='Age~Exer BoxPlot')

# 적합성 검정(1)
table(data_s$Exer)
Exer <- table(data_s$Exer)
ration <- c(0.48,0.1,0.42)
chisq.test(x=Exer, p=ration)

98/(115+24+98)


# 동질설 검정(1)
a.n <- table(data_s$Sex, data_s$W.Hnd)
prop.table(a.n)
addmargins(prop.table(a.n))
chisq.test(a.n)

plot(a.n, main='Sex-Smoke Ration')


# 독립성 검정
a.n <- table(data_s$Sex, data_s$Smoke)
prop.table(a.n)
addmargins(prop.table(a.n))
chisq.test(a.n)
plot(a.n, main='Sex-Smoke Ration')

수정본(HW01)다변량분석-20181478소다영 (1).pdf
0.71MB

 

728x90
Comments