# 1. histogram with color and title, legend par(mfrow=c(2,2)) hist(G1, breaks = 10, col = "lightblue", main="Histogram of Grade 1" ) hist(G2, breaks = 10, col = "green", main="Histogram of Grade 2" ) hist(G3, breaks = 10, col = "coral", main="Histogram of Grade 3" )
상자그림
거주 지역에 따른 G3, 통학 시간에 따른 G3
1 2 3
par(mfrow=c(1,2)) boxplot(G3~address, boxwex = 0.5, col = c("yellow", "coral"), main="G3 by (Urban, Rural)") boxplot(G3~traveltime, boxwex = 0.5, col = c("red","orange","yellow","green"), main="G3 by traveltime")
# bar chart for romantic by sex ggplot(data=stud, aes(factor(romantic)))+geom_bar(aes(fill=factor(sex)), width=.4, colour="black")+ ggtitle("Romantic by sex")
결과 해석
연애 경험 있는 경우, 여학생 비율이 높음
1 2
# bar chart for internet use by (Urban, Rural) ggplot(data=stud, aes(factor(internet)))+geom_bar(aes(fill=factor(address)), width=.4, colour="black")+ggtitle("Internet use by (Urban, Rural)")
결과 해석
인터넷 사용자 중에는 도심지역에 사는 경우가 훨씬 많음
pariwise plot
pairwise scatterplot: pairs(변수리스트)
1 2 3 4 5
# new variable lists vars1<-c("G1", "G2", "G3") # pariwise plot pairs (stud[vars1], main = "Student Math Data", pch = 21,bg = c ("red","green3")[unclass(stud$sex)])
결과 해석
G1, G2, G3 상관성은 매우 높음
성별 차이는 없음
4. 데이터의 정규성검정과 신뢰구간
데이터의 정규성검정
정규확률도(Normal Q-Q plot): 데이터가 정규분포하는가?
1 2 3 4 5 6 7 8 9 10 11 12
# Testing for normality # multiple plot (2 by 2) par(mfrow=c(2,2)) #Quantile plot qqnorm(G1) qqline(G1, col = 2, cex=7)
qqnorm(G2) qqline(G2, col = 2, cex=7)
qqnorm(G3) qqline(G3, col = 2, cex=7)
정규분포
정규분포(Normal distribution)
정규분포 적합성검정: 데이터가 정규분포하는지에 대한 검정
Shapiro-Wilks 검정
1 2
#Shapiro-Wilks test shapiro.test(G3)
결과 해석
p-value가 0에 가까워서 정규분포한다고 볼 수 없음
Anderson-Darling 검정(패키지 설치 필요)
1 2 3 4
#Anderson-Darling test require installing package "nortest" # install.packages('nortest') library(nortest) ad.test(G3)