Show \(x^2+\exp(x)+2x^4+1\) is convex.
A function is called a convex function x + y) f(x) + f(y); 8x; y 2 \[f(\alpha x+\beta y) \le \alpha f(x)+\beta f(y), \alpha \ge 0, \beta \ge 0, \alpha + \beta=1\]
\(f(\alpha x + \beta y)\le \alpha f(x) + \beta f(y)\)
\((\alpha x + \beta y)^2 + exp(\alpha x + \beta y) + 2(\alpha x + \beta y)^4 + 1 \le \alpha(x^2 + exp (x) +2x^4 +1 +\beta (y^2 +exp(y)+2y^4+1\)
Using \(\alpha + \beta = 1\) we can simplify the inequality and rewrite it as,
\(2\alpha x^4 + \alpha x^2 + \alpha exp(x)+2 \beta y^4+\beta y^2 + \beta exp(y) +1 - ((\alpha x + \beta y)^2 + exp(\alpha x + \beta y) +2 (\alpha x + \beta y)^4 +1)\ge0\)
\(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\ge0\)
The inequility is always true and therefor \(x^2+exp(x)+2x^4+1\) is convex.
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} }\)
To find the mean of a exponential distribution we know that \(\mu = E[X] = \int_0^ \infty x \lambda e^{- \lambda x}\)
Using integrated by parts: \(\int u v dx = u \int v dx - \int u' (\int v dx) dx\)
By replacing \(u=x\) and \(v=\lambda e^{- \lambda x}\)
we will end up with
\(\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 })\)
\(\mu = \frac{1}{ \lambda }\)
To find the exponential distribution we can solve,
\(\sigma ^{2} = Var[X] = E[ X^{2}] - E[X] ^{2}\)
Using integration by parts we can solve, \(E[ X^{2}] = \int_0^ \infty x^{2} \lambda e^{- \lambda x}\)
\([-x^{2} e^{- \lambda x}]_0^ \infty + \int_0^ \infty 2xe^{- \lambda x} dx\)
\([-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,
\([-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 })\)
\(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}}\)
It is extimated 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 typos at all? Use R to draw 1000 samples with \(\lambda = 4\) and show their histograms.
What is the probability of 4 typos?
lambda <- 1000 * (1/250)
x1 <- 4
four_typos <- (lambda^x1 * exp(-lambda))/factorial(x1)
round(four_typos * 100,2)
## [1] 19.54
#check the answer with r function dpois
four_typos_2 <- dpois(4, lambda = 4)
round(four_typos_2 * 100, 2)
## [1] 19.54
The probability of having exactly four typos is 19.54%
What is the probability of no typos at all?
lambda <- 4
x2 <- 0
zero_typos <- (lambda ^ x2 * exp(-lambda)) / factorial(x2)
round(zero_typos * 100, 2)
## [1] 1.83
#check the answer with r function dpois
zero_typos_2 <- dpois(0, lambda = 4)
round(zero_typos_2 * 100, 2)
## [1] 1.83
The probability of having zero typos is 1.83%
draw 1000 samples with \(\lambda = 4\) and show their histograms.
samples <- 1:1000
values <- rpois(1000, lambda = 4)
hist(values, main = "1000 Samples with lambda = 4")