R Programming Language Multiple Choice Questions on “Simulation”.
1. ________ generate random Normal variates with a given mean and standard deviation.
a) dnorm
b) rnorm
c) pnorm
d) rpois
Answer: b
Clarification: The “r” function is the one that actually simulates random numbers from that distribution.
2. Point out the correct statement?
a) R comes with a set of pseudo-random number generators
b) Random number generators cannot be used to model random inputs
c) Statistical procedure does not require random number generation
d) For each probability distribution there are typically three functions
Answer: a
Clarification: R allows you to simulate from well known probability distributions like the Normal, Poisson, and binomial.
3. ______ evaluate the cumulative distribution function for a Normal distribution.
a) dnorm
b) rnorm
c) pnorm
d) rpois
Answer: c
Clarification: p stands for cumulative distribution.
4. _______ generate random Poisson variates with a given rate.
a) dnorm
b) rnorm
c) pnorm
d) rpois
Answer: d
Clarification: q stands for quantile function (inverse cumulative distribution).
5. Point out the wrong statement?
a) For each probability distribution there are typically three functions
b) For each probability distribution there are typically four functions
c) r function is sufficient for simulating random numbers
d) R comes with a set of pseudo-random number generators
Answer: a
Clarification: There are typically four functions available that start with a “r”, “d”, “p”, and “q”.
6. Which of the following evaluate the Normal probability density (with a given mean/SD) at a point?
a) dnorm
b) rnorm
c) pnorm
d) rpois
Answer: a
Clarification: That point can be a vector of points.
7. _________ is the most common probability distribution to work with.
a) Gaussian
b) Parametric
c) Paradox
d) Simulation
Answer: a
Clarification: Working with the Normal distributions requires using four functions.
8. What will be the output of the following R code?
a)
[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513 [6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839
b)
[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011 [8] 19.60970 21.85104 20.96596
c)
Min. 1st Qu. Median Mean 3rd Qu. Max. 18.09 19.75 21.22 20.74 21.77 22.20
d) Error
Answer: a
Clarification: Here we simulate standard Normal random numbers with mean 0 and standard deviation 1.
9. What will be the output of the following R code?
> x <- rnorm(10) > summary(x)
a)
[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513 [6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839
b)
[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011 [8] 19.60970 21.85104 20.96596
c)
Min. 1st Qu. Median Mean 3rd Qu. Max. 18.09 19.75 21.22 20.74 21.77 22.20
d) Error
Answer: c
Clarification: We can modify the default parameters to simulate numbers with mean 20 and standard deviation 2.
10. What will be the output of the following R code?
a) 0.9772499
b) 1.9772499
c) 0.6772499
d) 2.6772499
Answer: a
Clarification: If you wanted to know what was the probability of a random Normal variable of being less than 2, you could use the pnorm() function to do that calculation.