#16,17#기술통계#데이터셋명$변수명, 숫자exam <- c(50,53,53,55,55,72,73,73,73,73,58,58,59, 59,60,73,73,73,74,74,60,62,62,62,62,75,75,76,76, 77,63,64,64,65,65,77,77,78,78,78,66,66,66,67,67, 78,79,79,79,80,67,67,67,67,67,67,80,71,82,82,83, 68,68,68,68,69,84,84,84,86,87,70,70,70,71,72,89,90,91,92,98)#4분위수quantile(exam)#p% 분위수p <- 0.02quantile(exam,p) #중앙값을 중심으로 전체데이터의 50%을 포함하는 범위c(quantile(exam , probs = 0.25),quantile(exam , probs = 0.75)) #중앙값을 중심으로 전체95%가 포함된 범위c(quantile(exam, probs = 0.025),quantile(exam, probs = 0.775)) #밀도그림hist(exam)a<-hist(exam, freq=FALSE)##순서ab<-lines(density(exam))####a;babline(v=mean(exam),lty="dotted") abline(v=median(exam),col="red",lty="dotted")abline(v=quantile(exam,c(0.25,0.75)),col="green")abline(v=quantile(exam,c(0.95)),col="red",lwd=2) fivenum (1:11) #20#아래 밀도그림에서 비대칭도 install.packages("boot")library(boot)install.packages("e1071")library(e1071) faithfulstr(faithful)duration = faithful$eruptions skewness(duration) wait = faithful$waiting skewness(wait)####faithful1<-faithfulwrite.csv(faithful1,"c:/source_data_package2/faith.csv")####erup <- faithful$eruptionshist(erup, freq=FALSE)lines(density(erup))abline(v=mean(erup),lty="dotted",col="green")abline(v=median(erup),col="red",lty="dotted")#abline(v=quantile(erup,c(0.25,0.75)),col="green")abline(v=quantile(erup,c(0.95)),col="red",lwd=2) #21set.seed(1000)x1 = rbeta(10000,2,4)x2 = rbeta(10000,5,5)x3 = rbeta(10000,4,2)skewness(x1)skewness(x2)skewness(x3)par(mfrow=c(2,2))hist(x1, freq=FALSE)lines(density(x1))hist(x2, freq=FALSE)lines(density(x2))hist(x3, freq=FALSE)lines(density(x3)) #22,23library(boot)install.packages("e1071")library(e1071)str(faithful)sapply(faithful,kurtosis)sapply(faithful,skewness)#그림이 그려지는 창을 분할par(mfrow=c(1,2))hist(faithful$eruptions, freq=FALSE)lines(density(faithful$eruptions))hist(faithful$waiting, freq=FALSE)lines(density(faithful$waiting))#변수에 대한 하나의 왜도 및 첨도로 판단 할 수 있는 데이터가 아니다.#양봉형 데이터: 하나의 변수내에 두 개의 class 가 있을 수 있을 것등을 고려하여서 적절한 처리 후 분석하여야한다.#두 집단으로 분리 가능성 정도, 평균차를 구해볼 필요성 등이 있다.
#24#두 개의 변수에서는 평균, 중위수가 의미가 있지만 #나머지 두 개 변수에서는 중위수나 평균이 의미가 x#표본의 개수를 더 증가 시키거나, 데이터를 분할 한 후에 분석 #밀도par(mfrow=c(2,2))hist(iris[,1], freq=FALSE)lines(density(iris[,1]))hist(iris[,2], freq=FALSE)lines(density(iris[,2]))hist(iris[,3], freq=FALSE)lines(density(iris[,3]))hist(iris[,4], freq=FALSE)lines(density(iris[,4]))#산점도par(mfrow=c(1,1))#pairs(숫자변수 여러개, panel=panel.smooth 선,#col=정수(데이터셋명$factor변수(그룹)))pairs(iris[,1:4], panel=panel.smooth,col=as.integer(iris$Species))
#변수별 비대칭도와 첨도sapply(iris[1:4],kurtosis) sapply(iris[1:4],skewness) #변수선택#iris 데이터셋에서 #Petal(꽃잎)은 Species(target) 별로 구분이 뚜렷 함#Sepal(꽃받침)은 Species(target) 별로 구분하기가 뚜렷하지 않은 분포 임.#그러므로 종을 구분하는데 있어서 Petal(꽃잎)을 중요한 변수로 설정함 #33#점크기와 점모양 예제par(mfrow=c(1,1))plot(0:10,0:10,xlim=c(0,32),ylim=c(0,48), type="n",xaxt="n",yaxt="n",xlab="",ylab="")x <- seq(1,31,2); y <- rep(4,16)points(x,y,pch=0:15, cex=0.7)text(x,y-3,as.character(0:15),cex=0.6) #36#5가지 심볼을 5가지 색# 빈 도표 생성plot(0:6,0:6,pch=22,type="n",xaxt="n",yaxt="n",ylab="col(border)",xlab="bg(background)")# “axis(1“은 x축 지정# at은 x 축의 눈금 명칭 지정,범위를 1에서 5로 지정axis(1,at=1:5) #“axis(2“은 y 축 지정#at=1:5은 y 축의 눈금 명칭 지정axis(2,at=1:5) # y축을 1위치에지정#(1,1) (2,1) (3,1)points(1:5,rep(1,5),pch=c(21,22,23,24,25),bg=1:5,col=1) #y축을 2위치에지정points(1:5,rep(2,5),pch=c(21,22,23,24,25),bg=1:5,col=2)