R Programming Quiz 4

This is Quiz 3 from the R Programming course within the Data Science Specialization.

Questions


1. What is produced at the end of this snippet of R code?

set.seed(1)
rpois(5, 2)
## [1] 1 1 2 4 1

  • A vector with the numbers 1, 1, 2, 4, 1


set.seed(1)
rpois(5, 2)
## [1] 1 1 2 4 1

2. What R function can be used to generate standard Normal random variables?


  • rnorm


rnorm(10, 0, 1)
##  [1]  1.272429321  0.414641434 -1.539950042 -0.928567035 -0.294720447
##  [6] -0.005767173  2.404653389  0.763593461 -0.799009249 -1.147657009

3. When simulating data, why is using the set.seed() function important? Select all that apply.


  • It ensures that the sequence of random numbers starts in a specific place and is therefore reproducible.


Explanation:

Set.seed allows other to get the same psuedorandom sequence to verify results.


set.seed(22)

4. Which function can be used to evaluate the inverse cumulative distribution function for the Poisson distribution?


  • qpois


Explanation:

See documentation ?qpois


5. What does the following code do?

set.seed(10)
x <- rep(0:1, each = 5)
e <- rnorm(10, 0, 20)
y <- 0.5 + 2 * x + e

  • Generate data from a Normal linear model



6. What R function can be used to generate Binomial random variables?


  • rbinom



7. What aspect of the R runtime does the profiler keep track of when an R expression is evaluated?


  • the function call stack


8. Consider the following R code

library(datasets) Rprof() fit <- lm(y ~ x1 + x2) Rprof(NULL)


  • 100%


9. When using ‘system.time()’, what is the user time?


  • It is the time spent by the CPU evaluating an expression


10. If a computer has more than one available processor and R is able to take advantage of that, then which of the following is true when using ‘system.time()’?


  • Elapsed time may be smaller than user time


Check out my website at: http://www.ryantillis.com/