---
title: "Sample Homework Solution"
author: "Marek Rychlik (derived from a student's homework; some solutions are incorrect!!!)"
date: "11/02/2021"
output:
  html_document:
    toc: yes
  pdf_document:
    toc: yes
editor_options:
  markdown:
    wrap: 72
  chunk_output_type: console
---

Setup of some 'knitr' parameters

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

**Install required packages** You may omit this R "chunk" after the
packages are installed.

```{r install.packages("bookdown");install.packages("markdown")}

```

**Exercise 4.5**

Let $0 < p = 1 - q < 1$

From Example 4.3:

The sequence given by $u_n = \binom{N}{n}$ if $n=0,1,2,...,N$ $u_n = 0$
otherwise

has generating function
$U(s) = \sum_{n=0}^{N} \binom{N}{n}s^n = (1+s)^N$

generating function:
$U(s) = \sqrt{1-4pgs^2} = (1 - 4pqs^2)^{\frac{1}{2}}$

sequence: $u_n = \binom{-\frac{1}{2}}{n}$ if $n=0,1,2,...,N$ $u_n = 0$
otherwise

\newpage

**Exercise 4.18**

$X$ is a random variable with probability generating function $G_{X}(s)$
$k$ is a positive integer

$Y =kX$ and $Z = X + k$ have probability generating functions
$G_{Y}(s) = G_{X}(s^k)$, $G_{Z}(s) = s^k G_{X}(s)$

\newpage

**Exercise 4.19**

$X$ is uniformly distributed on {$0,1,2,...,a$} in that
$P(X=k) = \frac{1}{a+1}$ for $k=0,1,2,...,a$

$X$ has probability generating function
$G_{X}(s) = \frac{1-s^{a+1}}{(a+1)(1-s)}$

\newpage

**Exercise 4.30**

From Example 4.16: If $X$ has the Poisson distribution with parameter
$\lambda$, then
$$G_{X}(s) = \sum_{k=0}^{\infty} \frac{1}{k!} \lambda^{k} e^{- \lambda} s^{k} = e^{\lambda(s-1)}$$

From Proof 4.25: $E(X) = G_{X}'(s)$

$$
\begin{aligned}
E(X) = G_{X}'(s) &= \frac{d}{ds} e^{\lambda(s-1)} \\
&= e^{\lambda(s-1)} \frac{d}{ds} {\lambda}(s-1)\\
&= e^{\lambda(s-1)} \lambda\left[\frac{d}{ds}(s) - \frac{d}{ds}(1)\right]\\
&= e^{\lambda(s-1)} \lambda[1-0]\\
&= e^{\lambda(s-1)} \lambda
\end{aligned}
$$

From Equation 4.26: $E(X) = G_{X}'(1)$

$$
\begin{aligned}
E(X) = G_{X}'(1) &= e^{\lambda[(1)-1]} \lambda\\
                 &= e^{\lambda(0)} \lambda\\ 
                 &= e^{0} \lambda\\ 
                 &= \lambda
\end{aligned}
$$

From Equation 4.28: $var(X) = G_{X}''(1) + G_{X}'(1) - (G_{X}'(1))^2$

$$
\begin{aligned}
G_{X}''(s) &= \frac{d}{ds} \lambda e^{\lambda(s-1)}\\
          & = \lambda \frac{d}{ds} e^{\lambda(s-1)}\\ 
          & = \lambda e^{\lambda(s-1)} \frac{d}{ds} \lambda(s-1)\\ 
          & = \lambda e^{\lambda(s-1)} \lambda(1-0)\\ 
          & = \lambda e^{\lambda(s-1)} \lambda\\
          & = \lambda^2 e^{\lambda(s-1)}\\
G_{X}''(1) &= \lambda^2 e^{\lambda[(1)-1]}\\
          & = \lambda^2 e^{\lambda(0)}\\ 
          & = \lambda^2\\
    var(X) &= \lambda^2 + \lambda - (\lambda)^2\\
    var(X) &= \lambda^2 + \lambda - \lambda^2\\ 
    var(X) &= \lambda
\end{aligned}
$$

A random variable having the Poisson distribution with parameter
$\lambda$ has both mean and variance equal to $\lambda$.

\newpage

**Exercise 4.31**

$X$ has the negative binomial distribution with parameters $n$ and $p$

From Example 4.17: If $X$ has the negative binomial distribution with
parameters $n$ and $p$, then
$$G_{X}(s) = \sum_{k=n}^{\infty} \binom{k-1}{n-1} p^{n}q^{k-n}s^{k} = (\frac{ps}{1-qs})^n$$
if $|s| < q^{-1}$

\$G\_{X}'(s) = \$

$E(X) = \frac{n}{p}$, $var(X) = \frac{nq}{p^2}$ where $q = 1-p$

\newpage

**Exercise 4.41**

Find distribution of $X + Y$, where $X$ and $Y$ are independent random
variables, $X$ having the binomial distribution with parameters $m$ and
$p$, and Y having the binomial distribution with parameters $n$ and $p$.

Deduce that the sum of $n$ independent random variables, each having the
Bernoulli distribution with parameter $p$, has the binomial distribution
with parameters $n$ and $p$.

\newpage

**Exercise 4.42**

Egg cracks with probability of $p$

Number of eggs laid today by the hen has the Poisson distribution,
parameter $\lambda$

Number of uncracked ages has the Poisson distribution with parameter
$\lambda(1-p)$

$G_{N}(s) = E(s^N) = (p + ps)^{\lambda}$

$G_{X}(s) = e^{\lambda (1-p)(s-1)}$

$S = X_1 + X_2 + ... + X_N$

$G_{S}(s) = G_{N}(G_{X}(s)) = (p + p(e^{\lambda (1-p)(s-1)}))^{\lambda}$

\newpage

**Exercise C4.4.2**

A random variable $X$ has generating function
$G_{X}(s) = (\frac{1}{2} + \frac{1}{2} e^{3(s-1)})^{20}$

\newpage

**Problem 1**

Let $X$ have probability generating function $G_{X}(s)$ and let
$u_n = P(X > n)$

The generating function $U(s)$ of the sequence $u_0, u1, ...$ satisfies
$(1-s)U(s) = 1 - G_{X}(s)$

whenever the series defining these generating function coverage

\newpage

**Problem 2**

Symmetrical die thrown independently 7 times. $$
P(X_j = k) = \begin{cases}
\frac{1}{6}, &k \in \{1,2,3,4,5,6\}\\
0  &\text{otherwise.}
\end{cases}
$$
$$G_{X_j}(s) = \sum_{k=1}^6 \frac{1}{6} s^k = \frac{1}{6} s \frac{1-s^6}{1-s}$$
$$G_{X}(s) = \left(G_{X_1}(s)\right)^6 = \left(\frac{1}{6} s \frac{1-s^6}{1-s}\right)^6$$

$$
\begin{aligned}
P(X = 14) &= [s^{14}]\left(\frac{1}{6} s \frac{1-s^6}{1-s}\right)^6 \quad \text{($g = 14-6 = 8$)}\\
&= \frac{1}{6^6} [s^g] \left(\frac{1-s^6}{1-s}\right)^6\\ 
&= \frac{1}{6^6} [s^g] (1-s^6)^6 (1-s)^{-6}\\
&= \frac{1}{6^6} [s^g] \left[\sum_{k=0}^{6} \binom{6}{k} (-s^6)^k\right] \left[\sum_{l=0}^{\infty} \binom{-6}{l} (-s)^l\right]\\
&= \frac{1}{6^6} [s^g] \sum_{k=0}^{6} \sum_{l=0}^{\infty} \binom{6}{k} (-1)^{k+l} \binom{-6}{l} s^{6k+l}\\
&= \frac{1}{6^6} \sum_{k \in {0,1,...,6}} \binom{6}{k} \binom{-6}{l} (-1)^{k+l}\\
&= \frac{1}{6^6} \left[- \binom{6}{0} \binom{-6}{8} + \binom{6}{1} \binom{-6}{3}\right]\\
&= \frac{1}{46656} \left[-(1) \binom{-6}{8} + (6) \binom{-6}{3}\right]
\end{aligned}
$$ \`\`\` \newpage

**Problem 3**

3 players throw a perfect die in turn independently in the order A, B,
C, A, ... until one wins by throwing a 5 or 6.

Probability generating function $F(s)$ for the random variable $X$ which
takes the value $r$ if the game ends on the $r$th throw can be written
as:

$$F(s) = \frac{9s}{27-8s^3} + \frac{6s^2}{27-8s^3} + \frac{4s^3}{27-8s^3}$$

\newpage

**Problem 5**

Tree of a particular type flowers once each year.

Probability a tree has $n$ flowers is $(1-p)p^n, n=0,1,2,...$ where 0 \<
$p$ \< 1

Each flower has probability $\frac{1}{2}$ of producing a ripe fruit,
independently of all other flowers.

a)  $P(X = r)$

b)  $P(X = n | X = r)$

\newpage

**Problem 7**

Let $X$ and $Y$ be independent random variables having Poisson
distributions with parameters $\lambda$ and $\mu$ respectively.

$X + Y$ has a Poisson distribution

$var(X + Y) = var(X) + var(Y)$

conditional probability: $P(X = k | X + Y = n)$ for $0 \leq k \leq n$

conditional expectation of $X$ given that $X + Y = n$:

$$E(X|X + Y =n) = \sum_{k=0}^{\infty} k P(X = k | X + Y = n)=\frac{n \lambda}{\lambda + \mu}$$

\newpage

**Problem 10**

Probability generating function $\phi$

If $\phi(s)$ has the form $\frac{p(s)}{q(s)}$, the mean value is
$\frac{(p'(1) - q'(1))}{q(1)}$

\newpage

**Problem 11**

A random number $N$ of foreign objects in soup, with mean $\mu$ and
finite variance.

Each object is a fly with probability $p$, and otherwise spider.

Different objects have independent types.

Let $F$ be the number of flies and $S$ the number of spiders.

a)  $G_{F}(s) = G_N(ps + 1 -p)$

b)  $N$ has the Poisson distribution with parameter $\mu$. $F$ has the
    Poisson distribution with parameter $\mu p$. $F$ and $S$ are
    independent.

c)  Let $p = \frac{1}{2}$ and suppose $F$ and $S$ are independent.
    $G_{N}(s) = G_{N}\left(\frac{1}{2} [1 + s]\right)^2$

$\left[1 + (\frac{x}{n}) + o(n^{-1})\right]^n \rightarrow e^x$ as
$n \rightarrow \infty$
