Exercise 4 Built-in Functions in R
4.1 Lecture slides
4.2 Probability Functions
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
\(f_X(4)\)
\(F_X(4)\)
\(F_X^{-1}(0.5)\)
Let \(X \sim Binomial(6, 0.5)\). Write R codes to calculate the followings:
\(P(X=3)\)
\(P(X \geq 3)\)
\(P(X \leq 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}. \]
Write R codes to solve the following problems:
Find the determinant of the matrix \(P\).
Find the transpose of the matrix \(P\).
Find the inverse of the matrix \(P\).
\({P'P}^{-1}\)
\(P + Q\)
\(P - Q\)
\(P \times Q\)
Write R codes to solve the following problems:
Generate a random sample of size 1000 from the \(Uniform(0, 5)\) store in a vector called
sample.unif
.Find the number of values greater than 2.5 in the vector
sample.unif
.Construct a 100x10 matrix to store the values in the vector
sample.unif
.Calculate and store the mean and median of each column of the matrix.