What this quiz covers
This quiz focuses on Simulation And Variability, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
An analyst runs x <- replicate(500, { set.seed(9); mean(rnorm(25)) }) and then obtains sd(x), which is essentially 0.
What is the best explanation for the observed lack of variability?
replicate() automatically averages the 500 results before sd() is called, eliminating variability among the replications.set.seed() guarantees independent random samples with matching moments, so the near-zero standard deviation is expected.R Programming Quiz
Practice Simulation And Variability in R Programming with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
This quiz focuses on Simulation And Variability, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.
An analyst runs x <- replicate(500, { set.seed(9); mean(rnorm(25)) }) and then obtains sd(x), which is essentially 0.
What is the best explanation for the observed lack of variability?
replicate() automatically averages the 500 results before sd() is called, eliminating variability among the replications.set.seed() guarantees independent random samples with matching moments, so the near-zero standard deviation is expected.set.seed() is everything. A random seed initializes R's pseudo-random number generator at a fixed state — meaning every call to a random function after that seed produces an identical sequence of numbers. If you reset the seed to the same value at the start of each replication, you don't get 500 different samples; you get the same sample repeated 500 times. That's exactly what's happening here: set.seed(9) fires inside the replicate() block, so every iteration draws the identical 25 values from rnorm(25), computes the identical mean, and stores it. When all 500 values in x are the same number, sd(x) is necessarily 0. Answer A correctly identifies this as the culprit.
Answer B is mathematically false. The variance of a sample mean of n standard normal observations is 1/n, not 0 — so for n=25, the theoretical standard deviation of the sampling distribution is 1/5=0.2. There is real variability; the simulation just can't reveal it due to the seed issue. Answer C is wrong because replicate() collects individual results into a vector — it performs no averaging whatsoever before returning. Answer D misrepresents what set.seed() does: it does not produce independent samples with matching moments; it produces identical samples, which is the opposite of independence.
A practical rule to remember: always place set.seed() outside the replicate() call if you want reproducible but varied simulations. Placing it inside is a subtle bug that silently destroys variability — exactly the kind of trap this exam question is designed to expose.Two estimators are applied to each of 900 simulated data sets. Across replications, estimator A has standard deviation 0.50, estimator B has standard deviation 0.40, and their paired estimates have correlation 0.80. The analyst compares methods using the mean of A - B.
What is the approximate Monte Carlo standard error of the estimated mean difference?
A - B.
The variance of a paired difference is σA−B2=σA2+σB2−2ρσAσB. Plugging in: 0.502+0.402−2(0.80)(0.50)(0.40)=0.25+0.16−0.32=0.09, so σA−B=0.30. The Monte Carlo standard error of the mean difference is then 0.30/900=0.30/30=0.010. That confirms A is correct.
B makes the mistake of assuming independence between estimators, computing 0.25+0.16/900≈0.021. Ignoring the positive correlation inflates the estimated variance — a common and consequential error when paired structure exists.
C uses the correct paired standard deviation (0.30) but divides by 100 instead of 900, as if only 100 replications were used. This inflates the MCSE by a factor of 3, reflecting a miscount of the sample size.
D simply reports σA−B=0.30 without dividing by anything, confusing the standard deviation of a single difference with the standard error of the mean difference — a fundamental mix-up between spread and precision.
Your study tip: whenever two methods share the same simulated data, always use the paired variance formula. Forgetting the correlation term is one of the most frequent errors in simulation-based comparisons.An estimator is simulated in 1,000 replications, but numerical optimization fails in 40 of them, producing NA. Among the remaining replications, mean(theta_hat, na.rm = TRUE) = 1.98 and sd(theta_hat, na.rm = TRUE) = 0.21. The true parameter is 2.00.
Which report most appropriately summarizes both performance and variability?
na.rm = TRUE makes failures irrelevant.na.rm = TRUE silently restricts your analysis to successful replications, so you must be transparent about that restriction and report the failure rate alongside your statistics.
Answer B is correct because it does exactly this — it reports the conditional bias (θ^−θ0=1.98−2.00=−0.02) and standard deviation (0.21) among the 960 successful fits, while explicitly flagging the 4% failure rate. This gives readers a complete, honest picture: the estimator's precision when it works, and how often it doesn't.
Answer A is tempting because na.rm = TRUE is syntactically convenient, but it doesn't make failures "irrelevant" — it silently excludes them. Reporting results without acknowledging the 4% failure rate misrepresents the estimator's overall reliability.
Answer C sounds like it avoids selection bias by including all 1,000 replications, but substituting failed estimates with 0 introduces severe artificial bias. You're not recovering missing information — you're fabricating it with an arbitrary value that distorts both the mean and standard deviation.
Answer D overcorrects in the opposite direction. A 4% failure rate is meaningful, but it doesn't invalidate the information from the 960 successful replications. Discarding valid results entirely is unnecessarily wasteful and tells you nothing about estimator accuracy when convergence succeeds.
Study tip: Whenever you see na.rm = TRUE in a simulation context, ask yourself whether the NAs are random noise or systematic failures — if they're systematic, always report the failure rate explicitly alongside your conditional summaries.A simulation of prediction loss gives mean(loss) = 2.00, median(loss) = 1.02, sd(loss) = 10.00, and quantile(loss, 0.95) = 1.30. Inspection of the values shows that a small fraction of replications have extremely large losses.
Which interpretation best accounts for these summaries?
For IID observations with finite variance, a simulation finds that the empirical standard deviation of the sample mean is approximately 0.30 when each simulated data set has sample size 100. The number of simulation replications is kept fixed.
If the sample size within each simulated data set is increased to 400, what empirical standard deviation should be expected approximately?
A simulation study evaluates a nominal 95% confidence-interval procedure. Among 1,000 independent replications, 930 intervals contain the true parameter.
Using a normal approximation for Monte Carlo error, which approximate 95% interval describes uncertainty in the estimated coverage probability?
An analyst uses 400 independent simulation replications. The empirical standard deviation of the estimator is 0.24, so the Monte Carlo standard error of the simulated mean estimate is 0.24/400=0.012. The analyst plans to rerun the same design with 1,600 replications.
Assuming the simulation design and estimator distribution remain unchanged, what should the analyst expect?
Under a fixed alternative hypothesis, a test is simulated 2,500 times. The vector reject contains TRUE when the null hypothesis is rejected. The results are mean(reject) = 0.64 and sd(reject) = 0.48.
Which statement correctly summarizes the simulation?
reject is a logical vector of TRUE/FALSE values, mean(reject) gives the proportion of rejections — that's your estimated power, which here equals 0.64. The MCSE for a proportion estimated from n simulations is MCSE=ns, where s is the sample standard deviation. Plugging in the given values: 25000.48=500.48=0.0096. This confirms B is correct.
Choice A confuses the roles of mean and sd, treating sd(reject) = 0.48 as the power estimate and mean(reject) as something else entirely — a straightforward swap of the two statistics. Choice C gets the power right (0.64) but uses the raw standard deviation (0.48) as the MCSE, forgetting to divide by n — a critical omission that ignores how sample size reduces uncertainty. Choice D computes 1−0.64=0.36, which would be the estimated Type II error rate (β), not power; the MCSE calculation happens to be correct, but it's answering the wrong question.
A handy rule: in any simulation study, power = mean(reject) and MCSE = sd(reject) / sqrt(n). Keep these two formulas together and you'll avoid all four traps here.From many simulated data sets, an analyst obtains estimator values in theta_hat. The command quantile(theta_hat, c(0.05, 0.95)) returns 1.2 and 2.8. The true parameter used to generate every data set was 2.
Which interpretation of the two reported quantiles is most accurate?
theta_hat, accounting for Monte Carlo uncertainty in that mean.quantile() on your collected estimator values, you're summarizing the empirical distribution of those estimates — nothing more, nothing less. Keep that scope in mind as you evaluate each choice.
quantile(theta_hat, c(0.05, 0.95)) returning 1.2 and 2.8 means that 5% of the simulated θ^ values fell below 1.2 and 5% fell above 2.8. In other words, the central 90% of your estimator's sampling distribution — as approximated by simulation — sits between those two values. That's exactly what D says, and it's the only claim the output directly supports.
A is wrong because quantile() says nothing about uncertainty in the mean of theta_hat. A confidence interval for that mean would require a standard error calculation (e.g., using the standard deviation of theta_hat divided by n), not quantiles of the raw estimates.
B confuses two different things: the spread of θ^ values and confidence-interval coverage. Coverage is the proportion of intervals (each built from one data set) that contain the true parameter θ=2. Computing that requires checking each interval individually — the quantiles of theta_hat don't tell you this.
C is a classic trap. The true value 2 does happen to sit exactly midway between 1.2 and 2.8, but symmetry around the truth in one simulation run doesn't establish unbiasedness. Unbiasedness requires E[θ^]=θ, which you'd assess with the mean of theta_hat, not its quantiles.
A useful rule of thumb: always ask what object a statistic describes. Quantiles of θ^ describe θ^'s distribution — not interval coverage, not means, not bias.A simulation produces five estimates with theta_hat <- c(8, 9, 10, 11, 12). The true parameter value is theta <- 10. The analyst computes bias using the mean signed error, empirical standard deviation using R's sd(), and RMSE using the mean squared error.
Which set of simulation summaries is correct?
theta_hat <- c(8, 9, 10, 11, 12) and theta <- 10, the errors are (−2,−1,0,1,2). Bias is the mean signed error: 5−2−1+0+1+2=0. RMSE is the square root of the mean squared error: 54+1+0+1+4=2≈1.41. Empirical standard deviation uses R's sd(), which divides by n−1=4: 44+1+0+1+4=2.5≈1.58. This makes option C correct — bias =0, SD ≈1.58, RMSE ≈1.41.
A is wrong because it assigns RMSE the value 1.58, which is actually the sample SD. B flips both: it gives SD as 1.41 (the population-style calculation) and RMSE as 1.58 (the sample SD value) — a double swap. D is wrong because it reports a nonzero bias; since the estimates are symmetric around 10, bias is exactly 0.
The key study tip: remember that sd() in R uses n−1 (Bessel's correction), while RMSE divides by n. These produce different values even from the same data, and exam questions are specifically designed to exploit that confusion.