> For the complete documentation index, see [llms.txt](https://kmis.gitbook.io/statistics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kmis.gitbook.io/statistics/chapter-4.-discrete-random-variables/4-3.-exercises.md).

# 4-3. Exercises

**Ex 1.** 1에서 6까지 번호가 적혀있는 동일한 6개의 공이 들어 있는 상자에서 임의로 두 개의 공을 꺼냈을 때 나온 번호의 평균을 $$X$$ 라 하자.

1. $$X$$ 의 확률분포함수를 구하시오.
2. $$X$$ 의 기대값과 분산을 구하시오.
3. $$X$$ 가 4 이상일 확률을 구하시오.

**Ex 2.** 1에서 6까지 번호가 적혀있는 동일한 6개의 공이 들어 있는 상자에서 임의로 두 개의 공을 꺼냈을 때 나온 번호 중 큰 숫자를 X라 하자.&#x20;

1. $$X$$ 의 확률분포함수를 구하시오.
2. $$X$$ 의 기대값과 분산을 구하시오.
3. $$X$$ 가 4 이상일 확률을 구하시오.

**Ex 3.** 1에서 20까지 번호가 적혀있는 동일한 20개의 공이 들어 있는 상자에서 임의로 n 개의 공을 꺼냈을 때 나온 번호의 평균을 $$X\_n$$ 이라 하자.&#x20;

1. n=2, 5, 10 각각에 대하여, $$X\_n$$ 의 확률분포함수를  그래프로 작성하여 비교하라.
2. n=2, 5, 10 각각에 대하여, $$X\_n$$의 기대값과 분산을 구하여 비교하라.
3. n=2, 5, 10 각각에 대하여,  $$X\_n$$이 15 이상일 확률을 구하여 비교하라.

**\[ Solution ]**

{% tabs %}
{% tab title="R Source" %}

```
library(Rstat)

# 20 Balls
ball <- 1:20
S2 <- urnsample2(ball, size=2); (N2 <- nrow(S2))
S5 <- urnsample2(ball, size=5); (N5 <- nrow(S5))
S10 <- urnsample2(ball, size=10); (N10 <- nrow(S10))
S15 <- urnsample2(ball, size=15); (N15 <- nrow(S15))


# Sample Mean and Probability Distribution 
X2 <- apply(S2,1,mean); T2 <- table(X2); P2 <- T2/N2; v2 <- as.numeric(names(T2))
X5 <- apply(S5,1,mean); T5 <- table(X5); P5 <- T5/N5; v5 <- as.numeric(names(T5))
X10 <- apply(S10,1,mean); T10 <- table(X10); P10 <- T10/N10; v10 <- as.numeric(names(T10))
X15 <- apply(S15,1,mean); T15 <- table(X15); P15 <- T15/N15; v15 <- as.numeric(names(T15))

# Probability Distribution Plot
pmax <- max(c(P2,P5,P10,P15))
win.graph(9,6); par(mfrow=c(2,2)); par(mar=c(2,2,3,2))
plot(v2, P2, type="h", main="n=2", ylim=c(0,pmax), xlim=c(1,20), lwd=2, col=2)
plot(v5, P5, type="h", main="n=5", ylim=c(0,pmax), xlim=c(1,20), lwd=2, col=2)
plot(v10, P10, type="h", main="n=10", ylim=c(0,pmax), xlim=c(1,20), lwd=2, col=2)
plot(v15, P15, type="h", main="n=15", ylim=c(0,pmax), xlim=c(1,20), lwd=2, col=2)

# Expected Value and Variance
disc.exp(v2,T2); disc.exp(v5,T5); disc.exp(v10,T10); disc.exp(v15,T15)

# P(X>=15)
PX2 <- sum(P2[v2 >= 15]); PX5 <- sum(P5[v5 >= 15])
PX10 <- sum(P10[v10 >= 15]); PX15 <- sum(P15[v15 >= 15])
cat(PX2, PX5, PX10, PX15, "\n")
```

{% endtab %}

{% tab title="Prob. Distribution" %}
![](/files/-LsjtmE_jQzvbBkB23ey)
{% endtab %}

{% tab title="E(X) and Var(X)" %}

```
> # Expected Value and Variance
> disc.exp(v2,T2); disc.exp(v5,T5); disc.exp(v10,T10); disc.exp(v15,T15)
## E(V2) = 1995/190 = 10.5 
## V(V2) = 23940/190 - 10.5² = 15.75 
## D(V2) = √(15.75) = 3.969 
## E(V5) = 162792/15504 = 10.5 
## V(V5) = 1790712/15504 - 10.5² = 5.25 
## D(V5) = √(5.25) = 2.291 
## E(V10) = 1939938/184756 = 10.5 
## V(V10) = 20692672/184756 - 10.5² = 1.75 
## D(V10) = √(1.75) = 1.323 
## E(V15) = 162792/15504 = 10.5 
## V(V15) = 1718360/15504 - 10.5² = 0.583 
## D(V15) = √(0.583) = 0.764 
```

* All has the same $$E(X).$$&#x20;
* Variance decreases as $$n$$ increases.
  {% endtab %}

{% tab title="P(X>=15)" %}

```
> # P(X>=15)
> PX2 <- sum(P2[v2 >= 15]); PX5 <- sum(P5[v5 >= 15])
> PX10 <- sum(P10[v10 >= 15]); PX15 <- sum(P15[v15 >= 15])
> cat(PX2, PX5, PX10, PX15, "\n")
## 0.1578947 0.02631579 0.0001028383 0 
```

* $$P(X \ge 15)$$ decreases rapidly as $$n$$ increases.
  {% endtab %}
  {% endtabs %}
