Skip to content

Commit 223ce95

Browse files
committed
Week 4 quiz
1 parent 9687315 commit 223ce95

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

Diff for: week-04/quiz.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Quiz
2+
====
3+
4+
Question 1
5+
----------
6+
7+
What is produced at the end of this snippet of R code?
8+
9+
set.seed(1)
10+
rpois(5, 2)
11+
12+
### Answer
13+
14+
A vector with the numbers 1, 1, 2, 4, 1
15+
16+
### Explanation
17+
18+
Because the `set.seed()' function is used, `rpois()' will always output the same vector in this code.
19+
20+
21+
Question 2
22+
----------
23+
24+
What R function can be used to generate standard Normal random variables?
25+
26+
### Answer
27+
28+
rnorm
29+
30+
### Explanation
31+
32+
Functions beginning with the `r` prefix are used to simulate random variates.
33+
34+
Standard probability distributions in R have a set of four functions that can be used to simulate variates, evaluate the density, evaluate the cumulative density, and evaluate the quantile function.
35+
36+
37+
Question 3
38+
----------
39+
40+
When simulating data, why is using the `set.seed()` function important?
41+
42+
### Answer
43+
44+
It ensures that the sequence of random numbers is reproducible.
45+
46+
47+
Question 4
48+
----------
49+
50+
Which function can be used to evaluate the inverse cumulative distribution function for the Poisson distribution?
51+
52+
### Answer
53+
54+
qpois
55+
56+
### Explanation
57+
58+
Probability distribution functions beginning with the `q` prefix are used to evaluate the quantile function.
59+
60+
61+
Question 5
62+
----------
63+
64+
What does the following code do?
65+
66+
set.seed(10)
67+
x <- rbinom(10, 10, 0.5)
68+
e <- rnorm(10, 0, 20)
69+
y <- 0.5 + 2 * x + e
70+
71+
### Answer
72+
73+
Generate data from a Normal linear model
74+
75+
76+
Question 6
77+
----------
78+
What R function can be used to generate Binomial random variables?
79+
80+
### Answer
81+
82+
rbinom
83+
84+
85+
Question 7
86+
----------
87+
88+
What aspect of the R runtime does the profiler keep track of when an R expression is evaluated?
89+
90+
### Answer
91+
92+
the function call stack
93+
94+
95+
Question 8
96+
----------
97+
Consider the following R code
98+
99+
library(datasets)
100+
Rprof()
101+
fit <- lm(y ~ x1 + x2)
102+
Rprof(NULL)
103+
104+
(Assume that y, x1, and x2 are present in the workspace.) Without running the code, what percentage of the run time is spent in the `lm` function, based on the `by.total` method of normalization shown in `summaryRprof()`?
105+
106+
107+
### Answer
108+
109+
100%
110+
111+
### Explanation
112+
113+
When using `by.total` normalization, the top-level function (in this case, `lm()`) always takes 100% of the time.
114+
115+
116+
Question 9
117+
----------
118+
119+
When using `system.time()`, what is the user time?
120+
121+
### Answer
122+
123+
It is the time spent by the CPU evaluating an expression
124+
125+
126+
Question 10
127+
-----------
128+
129+
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()`?
130+
131+
### Answer
132+
133+
Elapsed time may be smaller than user time

0 commit comments

Comments
 (0)