Ex. 1

Show \(x^{2} + exp(x) + 2 x^{4} + 1\) is convex.

Solution:

A function is considered convex if \(f( \alpha x + \beta y) \leq \alpha f(x) + \beta f(y)\), \(\forall x,y \in \Omega\), \(\alpha \ge 0, \beta \ge 0\), \(\alpha + \beta = 1\)

\((\alpha x + \beta y)^{2} + exp(\alpha x + \beta y) + 2 (\alpha x + \beta y)^{4} + 1 \leq \alpha (x^{2} + exp(x) + 2 x^{4} + 1) + \beta (y^{2} + exp(y) + 2 y^{4} + 1)\)

\((\alpha^{2} x^{2} + \beta^{2} y^{2} + 2 \alpha \beta x y ) + exp(\alpha x + \beta y) + 2 (\alpha x + \beta y)^{4} + 1 \leq \alpha x^{2} + \alpha exp(x) + 2 \alpha x^{4} + \alpha + \beta y^{2} + \beta exp(y) + 2 \beta y^{4} + \beta\)

Using \(\alpha + \beta = 1\) we rewrite as

\((\alpha^{2} x^{2} + \beta^{2} y^{2} + 2 \alpha \beta x y ) + exp(\alpha x + \beta y) + 2 (\alpha x + \beta y)^{4} \leq \alpha x^{2} + \alpha exp(x) + 2 \alpha x^{4} + \beta y^{2} + \beta exp(y) + 2 \beta y^{4}\)

\(2 \alpha x^{4} + \alpha x^{2} + \alpha exp(x) + 2 \beta y^{4} + \beta y^{2} + \beta exp(y) - (\alpha x + \beta y)^{2} - exp(\alpha x - \beta y) - 2 (\alpha x + \beta y)^{4} \geq 0\)

The inequality is always true and hence \(x^{2} + exp(x) + 2 x^{4} + 1\) is convex.

Ex. 2

Show that the mean of the exponential distribution

\(p(x) = \begin{cases} \lambda e^{- \lambda x}, & x \geq 0 ( \lambda > 0),\\0, & x < 0\end{cases}\)

is \(\mu = \frac{1}{ \lambda }\) and its variance is \(\sigma ^{2} = \frac{1}{ \lambda ^{2} }\).

Solution:

To find the mean we know that \(\mu = E[X] =\int xp(x)dx\)

\(\mu = \int_{-\infty}^0 x*0dx + \int_0^ \infty x \lambda e^{- \lambda x} dx\)

Using integration by parts \(\int u v dx = u \int v dx - \int u' (\int v dx) dx\)

replacing \(u=x, v=\lambda e^{- \lambda x}\) we will have

\(\mu =[-x e^{- \lambda x}]_0^ \infty + \int_0^ \infty e^{- \lambda x} dx\)

\(\mu =[-x e^{- \lambda x}]_0^ \infty + [ -\frac{1}{ \lambda } e^{- \lambda x}]_0^ \infty\)

\(\mu = (0 - 0) + (0 + \frac{1}{ \lambda })\) = \(\frac{1}{ \lambda }\)

To find the variance of the given exponential distribution we know that \(\sigma ^{2} = Var[X] = E[ X^{2}] - E[X] ^{2}\)

\(E[ X^{2}] = \int_0^ \infty x^{2} \lambda e^{- \lambda x}\) which could again be solved by using integration by parts

\(E[ X^{2}] = [-x^{2} e^{- \lambda x}]_0^ \infty + \int_0^ \infty 2xe^{- \lambda x} dx\)

\(E[ X^{2}] = [-x^{2} e^{- \lambda x}]_0^ \infty +[- \frac{2}{ \lambda } x e^{- \lambda x} dx]_0^ \infty + \frac{2}{ \lambda } \int_0^ \infty e^{- \lambda x} dx\)

using integration by parts again

\(E[ X^{2}] = [-x^{2} e^{- \lambda x}]_0^ \infty +[- \frac{2}{ \lambda } x e^{- \lambda x} dx]_0^ \infty + \frac{2}{ \lambda } [- \frac{1}{ \lambda } x e^{- \lambda x} dx]_0^ \infty\)

\((\frac{2}{ \lambda })( \frac{1}{ \lambda })\) = \(\frac{2}{ \lambda ^{2}}\)

\(E[ X^{2}] - E[X] ^{2} = \frac{2}{\lambda ^{2}} - (\frac{1}{ \lambda }) ^{2} = \frac{2}{\lambda ^{2}} - \frac{1}{\lambda ^{2}} = \frac{1}{ \lambda ^{2}}\)

Ex. 3

It is estimated that there is a typo in every 250 data entries in a database, assuming the number of typos can obey the Poisson distribution. For a given 1000 data entries, what is the probability of exactly 4 typos? What is the probability of no typo at all? Use R to draw 1000 samples with \(\lambda = 4\) and show their histogram.

Solution:

what is the probability of exactly 4 typos?

lambda <- 1000 * (1/250)
x <- 4 # 4 typos
p_four_typo <- (lambda ^ x * exp(-lambda)) / factorial(x)
p_four_typo
## [1] 0.1953668

The probability of exactly 4 typos is 19.54%.

What is the probability of no typo at all?

lambda <- 4
x <- 0 # no typo
p_zero_typo <- (lambda ^ x * exp(-lambda)) / factorial(x)
p_zero_typo
## [1] 0.01831564

The probability of no typos at all is 1.83%.

Now let’s confirm our results above using built in R function.

# probability of exactly 4 typos
p1 <- dpois(4, lambda = 4)
p1
## [1] 0.1953668
# probability of no typo
q2 <- dpois(0, lambda = 4)
q2
## [1] 0.01831564

Use R to draw 1000 samples with \(\lambda = 4\) and show their histogram.

events = 1:1000
lambda = 4
poisson <- rpois(1000, lambda)
df <- data.frame(events, poisson)

hist(df$poisson, main = "1000 Samples with lambda = 4")