Exercise 4 Built-in Functions in R

4.1 Lecture slides

4.2 Probability Functions

  1. A continuous random variable \(X\) is said to have the Normal distribution with mean (\(\mu\)), 5 and variance (\(\sigma^2\)), 9. Let \(f_X(x)\) and \(F_X(x)\) denote the probability density function and cumulative distribution function of \(X\) respectively. Write R codes to find

    1. \(f_X(4)\)

    2. \(F_X(4)\)

    3. \(F_X^{-1}(0.5)\)

  2. Let \(X \sim Binomial(6, 0.5)\). Write R codes to calculate the followings:

    1. \(P(X=3)\)

    2. \(P(X \geq 3)\)

    3. \(P(X \leq 1)\)

  1. Write R codes to visualize the probability mass function of \(Y \sim Binomial(6, 0.2)\).

4.3 Matrix calculations

The matrices \(P\) and \(Q\) are defined as follows

\[ P = \begin{bmatrix} 3 & 5 & 4 \\ 3 & 4 & 8\\ 7 & 6 & 5 \\ \end{bmatrix}, \quad Q = \begin{bmatrix} 1 & 5 & 4 \\ 2 & 5 & 7\\ 3 & 6 & 5 \\ \end{bmatrix}. \]

  1. Write R codes to solve the following problems:

    1. Find the determinant of the matrix \(P\).

    2. Find the transpose of the matrix \(P\).

    3. Find the inverse of the matrix \(P\).

    4. \({P'P}^{-1}\)

    5. \(P + Q\)

    6. \(P - Q\)

    7. \(P \times Q\)

  2. Write R codes to solve the following problems:

    1. Generate a random sample of size 1000 from the \(Uniform(0, 5)\) store in a vector called sample.unif.

    2. Find the number of values greater than 2.5 in the vector sample.unif.

    3. Construct a 100x10 matrix to store the values in the vector sample.unif.

    4. Calculate and store the mean and median of each column of the matrix.