2-1. Exercises

1. Basic Exercises

Ex 1. frequency histogram과 relative frequency histogram 사이의 차이를 설명하라.

Ex 2. frequency histogram과 비교하여 stem and leaf diagram이 갖는 장점을 설명하라.

Ex 3. 다음의 데이터를 기반으로 1) stem and leaf diagram, 2) frequency histogram 그리고 3) relative frequency histogram 을 작성하라. 히스토그램의 구간은 51-60, 61-70, ... 등으로 정한다.

69 92 68 77 80 70 85 88 85 96 93 75 76 82 100 53 70 70 82 85

[ Solution ]

data <- c(69, 92, 68, 77, 80, 70, 85, 88, 85, 96, 93, 
          75, 76, 82, 100, 53, 70, 70, 82, 85)

# 1. Stem and Leaf Diagram
stem(data)

# 2. Frequency Histogram
hist(data,  xlim = c(50, 110),
            ylim = c(0, 7),
            breaks = seq(51, 101, by=10))

# 3. Relative Frequecny Histogram
require(lattice)
require(openintro)

histogram(data, type = "percent",
          xlim = c(50, 110),
          ylim = c(0, 35),
          breaks = seq(51, 101, by=10))

Ex 4. 다음의 데이터를 기반으로 1) stem and leaf diagram, 2) frequency histogram 그리고 3) relative frequency histogram 을 작성하라. 히스토그램의 구간은 6.0-6.9, 7.0-7.9, ... 등으로 정한다.

8.5 8.2 7.0 7.0 4.3 6.5 8.2 7.6 1.5 9.3
9.6 8.5 8.8 8.5 8.7 8.0 7.7 2.3 9.2 6.9

Ex 5. 하나의 데이터 세트가 10개의 관측치를 가지고 있다. x 값과 빈도 f의 값이 다음과 같이 도수 분포표에 요약되어 있다. frequency histogram과 relative frequency table을 작성하라.

x  −1  0  1  2 
f   3  4  2  1

Ex 6. 하나의 데이터 세트가 20개의 관측치를 가지고 있다. 값의 빈도가 0인 것은 missing value이다. a 값을 찾아내고, 데이터 세트의 frequency histogram과 relative frequency table을 작성하라.

x  −1  0  1  2 
f   3  a  2  1

Ex 7. A data set has the following frequency distribution table:

  • x   -1   0   1   2
    f    3   a   2   1

The number a is unknown. Can you construct a frequency histogram? If so, construct it. If not, say why not.

Ex 8. 데이터 세트가 다음과 같은 도수분포표를 가지고 있다. a 값은 알려져 있지 않다. frequency histogram을 작성할 수 있는가? 그렇다면 작성하라. 그렇지 않다면 왜 그런지 설명하라.

x    1    2   3   4
f    3    a   2   1

Ex 9. 한 데이터 세트의 relative frequency table은 다음과 같다. p는 아직 계산되지 않았다. 표를 완성하고 이 데이터 세트의 relative frequency histogram을 작성하라.

  x    1   2    3    4
f/n  0.3   p  0.2  0.1

2. Application Exercises

Ex 10. 초등학교에서 무작위로 선택된 학생들의 IQ 가 다음과 같다. 측정치를 80점대, 90점대 등과 같이 그룹화하여 stem and leaf diagram, frequency histogram, 그리고 relative frequency histogram 을 작성하라.

108 100 99 125 87 105 107 105 119 118

Ex 11. 초등학교에서 학업에 자질을 가진 무작위로 선발된 20명 학생의 IQ는 다음과 같다. 100점대와 10점대로 측정치를 그룹화하여 stem and leaf diagram, frequency histogram, 그리고 relative frequency histogram 을 작성하라.

133 140 152 142 137 145 160 138 139 138

Ex 12. 300 명의 혈액 기부자의 혈액형이 다음의 표로 요약되어 있다. 이 데이터 세트에 대한 relative frequency histogram을 작성하라.

Blood type   O   A   B   AB
Frequency  136 120  32   12

Ex 13. 특정 주방용품 가게에서 전기밭솥은 인기있는 품목이다. 지난 20주간 동안의 주간 판매액은 다음과 같다. 계급 구간을 6-10, 11-15 그리고 16-20으로 하여 relative frequency histogram을 작성하라.

20 15 14 14 18 15 17 16 16 18 15 19 12 13 9 19 15 15 16 15

3. Additional Exercises

Ex 14. 낚시에서 잡은 생선의 길이를 센티미터로 표시한 표본의 크기가 10인 무작위 표본 3개가 있다.

Sample 1 : 108 100  99 125  87 105 107 105 119 118
Sample 2 : 133 140 152 142 137 145 160 138 139 138
Sample 3 :  82  60  83  82  82  74  73  82  80  80

각각의 측정치를 100의 자리와 10의 자리로 그룹화하여 각각의 표본에 대하여 stem and leaf diagram, frequency histogram 그리고 relative frequency histogram을 작성하라. 히스토그램들을 비교하고, 그것들이 보여주는 패턴에 대하여 설명하라.

Ex 15. 300 명의 혈액 기부자의 혈액형이 다음의 표로 요약되어 있다. 이 데이터 세트에 대한 relative frequency histogram을 작성하라. 이 300명에 대해 가능 큰 relative frequency를 갖는 혈액형은 무엇인가? 그 혈액형이 이 모집단에 속한 모든 사람들의 가장 대표적인 혈액형이라고 결론을 내릴 수 있는가? 그 이유를 함께 설명하라.

Blood type   O   A   B   AB
Frequency  136 120  32   12

Ex 16. 특정 주방용품 가게에서 전기밭솥은 인기있는 품목이다. 지난 20주간 동안의 주간 판매액은 다음과 같다. 계급 구간을 6-10, 11-15 그리고 16-20으로 하여 relative frequency histogram을 작성하라.

20 15 14 14 18 15 17 16 16 18 15 19 12 13 9 19 15 15 16 15

소매 판매에서 너무 많은 재고는 자금을 압박하는 반면, 너무 재고가 적으면 판매와 고객 만족에 저해가 된다. 이 데이터 세트의 relative frequency histogram을 이용하여, 다음의 조건 하에서 매주 초 얼마나 많은 양의 전기밭솥을 재고로 가지고 있는 것이 좋을지 그 근사값을 제시하라.

a) 전체 주의 15%이상에 대해 주말에 재고가 바닥이 나지 않아야 한다면,

b) 전체 주의 5%이상에 대해 주말에 재고가 바닥이 나지 않아야 한다면,

4. Comparative Stem and Leaf Plot

Ex 17. 다음과 같이 2개의 데이터 세트가 있다. 이 데이터 세트를 비교하는 stem and leaft diagram을 작성하라.

a <- c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0,
  8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7) 
b <- c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5, 
  8.9, 9.8, 9.7, 14.1, 12.6, 11.2)

[ Method #1 ] Diagram

install.packages("aplpack")
library(aplpack)

a <- c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
b <-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7,14.1, 12.6, 11.2)

stem.leaf.backback(a, b)
stem.leaf.backback(a, b, m=1)

[ Method #2 ] Colorful Plot

#sample data
x<-list()
x[[1]]<-c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 
    6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 
    9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
x[[2]]<-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0,
    8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7, 14.1, 12.6, 11.2)

#specify common breaks
brx <- pretty(range(unlist(x)), 
    n = nclass.Sturges(unlist(x)),min.n = 1)

#calculate bins
h1 = hist(x[[1]], breaks=brx, plot=FALSE)
h2 = hist(x[[2]], breaks=brx, plot=FALSE)

#draw
plot(NA,NA,type="n", xlab="", ylab="",
    xlim=range(c(-h1$counts, h2$counts)),
    ylim=range(brx),
    xaxt="n"
)

rect(-h1$counts, brx[-1], 0,  brx[-length(brx)], col="blue")
rect(0, brx[-1], h2$counts,  brx[-length(brx)], col="red")

axis(1, at=axTicks(side=1), labels=abs(axTicks(side=1)))

[ Method #3 ]

x<-list()
x[[1]]<-c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
x[[2]]<-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7, 14.1, 12.6, 11.2)

X<-stack(setNames(x, c("a","b")))

brx <- pretty(range(X$values), 
    n = nclass.Sturges(X$values),min.n = 1)

X$stem <- factor(brx[cut(unlist(x), breaks=brx, include.lowest=T, labels=F)], levels=brx[-length(brx)])
X$leaf <- as.integer(X$values %% 1 *10)


max.leaf.width <- 2*with(aggregate(leaf~ind+stem, X, length), tapply(leaf, ind, max))

fmt<-paste0("%", max.leaf.width[1],"s | %2s | %-", max.leaf.width[2],"s")

va<-with(subset(X, ind=="a"), tapply(leaf, stem, function(x) paste(rev(sort(x)), collapse=" ")))
vb<-with(subset(X, ind=="b"), tapply(leaf, stem, function(x) paste(sort(x), collapse=" ")))

va[is.na(va)]<-""
vb[is.na(vb)]<-""

cat(paste(sprintf(fmt, va, levels(X$stem), vb), collapse="\n"), "\n")

Last updated