MTH3045: Statistical Computing: Challenges
16/01/2024
Chapter 1
Week 1 lecture 1
- Generate a sample of \(n = 20\) \(N(1, 3^2)\) random variates, and without using
mean()
,var()
orsd()
writeR
functions to calculate the sample mean, \(\bar x\), sample variance, \(s^2\), and sample standard deviation, \(s\), where \[ \bar x = \dfrac{1}{n} \sum_{i = 1}^n x_i \text{ and } s^2 = \dfrac{1}{n - 1} \sum_{i = 1}^n (x_i - \bar x)^2. \] Note thansum()
may be used.
Solution
- Consider computing \(\text{Pr}(Z \geq z) = 1 - \Phi(z)\) where \(Z \sim \text{Normal}(0, 1)\), or, for short, \(Z \sim N(0, 1)\). For \(z = 0, 0.5, 1, 1.5, 2, \ldots\) compute this in
R
in three different ways using the following three commands
and find the lowest value of \(z\) for which the three don’t give the same answer.
Solution
- The formula \(\text{Var}(Y) = \text{E}(Y^2) - [\text{E}(Y)]^2\) is sometimes called the ‘short-cut’ variance formula, i.e. a short-cut for \(\text{Var}(Y) = \text{E}[Y - \text{E}(Y)]^2\). Compare computing the biased version of \(\text{Var}(Y)\) using the two formulae above for the samples
y1
andy2
below.