Ejercicios 1
Ejercicios 1
If you upload the R solutions of this worksheet as R Markdown (.Rmd) file, please also upload a knitted PDF.
The mathematical solutions are preferably included in the .Rmd or uploaded as a scan.
Problem 1
Consider two normal distributions with means µA = 2 and µB = 4, and standard deviations σA = 1 and
σB = 1.5.
Using R, plot the probability density functions (PDFs) of both distributions on the same graph.
Problem 2
The Weibull distribution has the following density:
κ x κ−1 x κ
f (x; κ, σ) = exp − , x ≥ 0,
σ σ σ
which depends on the two parameters σ, κ > 0.
(a) Using R, plot the density of the Weibull distribution for shape values κ ∈ {0.5, 1.0, 1.5, 5.0} and scale
values σ ∈ {1, 1.5, 2}.
(b) The shape of the density of a Weibull random variable depends greatly on the value of κ. More
specifically, there are three cases of interest: 0 < κ < 1, κ = 1 and κ > 1. Let σ = 1: by using relevant
plots in R, give a qualitative description of the obtained pattern for each of the aforementioned cases.
Problem 3
Consider the hospital dataset http://user.math.uzh.ch/furrer/download/sta402/hospital.csv, which con-
tains data related to a number of patients at a certain hospital. The length of the hospitalization period is
given in the column stay, while age corresponds to a certain age group, hmo and died are binary variables,
representing insured and deceased patients, respectively.
(a) In R plot a histogram of the stay data. At a first glance, do you think a Poisson random variable could
fit well the given counts? Explain why.
(b) The name “geometric distribution” usually refers to one of two similar discrete probability distributions:
• The probability distribution of the number X ∼ Geom(p) of Bernoulli trials needed to get one
success, with probability mass function (1 − p)x−1 p for x = 1, 2, 3, . . .
• The probability distribution of the number Y ∼ Geom0 (p) of Bernoulli trial failures before the
first success, with PMF (1 − p)x p for x = 0, 1, 2, . . .
Using (for example) the R command any in a proper way, realize that all the provided counts are strictly
positive. Which geometric distribution should we choose to model our data?
(c) Let X ∼ Geom0 (p) for 0 < p ≤ 1. The related zero-truncated distribution is given by X | X > 0; find
explicitly its probability mass function. What do you notice?
1
Problem 4
iid
Let X1 , . . . , Xn ∼ Gamma(α, β), where α, β are shape and rate parameter, respectively.
Problem 5 *
Consider the following distributions and answer the questions below:
(y − µ)2
1
(a) Normal distribution: f (y; θ) = √ exp − , µ known.
2πθ 2θ
n y
(b) Binomial distribution: f (y; π) = π (1 − π)n−y , n known.
y
β α α−1 −yβ
(c) Gamma distribution: f (y; α) = y e , rate parameter β > 0 known.
Γ(α)
(d) Exponential distribution: f (y; θ) = θe−θy .
2. For those distributions that belong to the exponential family, which are in canonical form? i.e., η(θ) =
c1 · θ + c2 where c1 , c2 ∈ R a constant.