What this quiz covers
This quiz focuses on Linear Models Lm, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
A data frame has 12 rows. For lm(y ~ x, data = d), y is missing in rows 2 and 7, while x is missing in rows 7 and 9. A separate variable z, which is not in the formula, is missing in row 10. Using the default missing-value handling, what residual degrees of freedom should the fitted model have?
y or x are dropped, leaving nine complete cases from which two coefficients are estimated.z in row 10 removes that row as well.R Programming Quiz
Practice Linear Models Lm 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 Linear Models Lm, 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.
A data frame has 12 rows. For lm(y ~ x, data = d), y is missing in rows 2 and 7, while x is missing in rows 7 and 9. A separate variable z, which is not in the formula, is missing in row 10. Using the default missing-value handling, what residual degrees of freedom should the fitted model have?
y or x are dropped, leaving nine complete cases from which two coefficients are estimated. (correct answer)z in row 10 removes that row as well.lm() and missing data in R, the key concept to recall is na.action = na.omit, which is the default behavior. Under this rule, R drops any row that is missing a value for a variable actually used in the formula — and only those rows.
Here, the formula is y ~ x, so R checks columns y and x for NAs. Row 2 is missing y, row 7 is missing both y and x, and row 9 is missing x. That gives three distinct rows removed: rows 2, 7, and 9. The variable z is not part of the formula, so row 10 is untouched. Starting from 12 rows, dropping 3 leaves 9 complete cases. Fitting lm(y ~ x) estimates 2 coefficients (intercept and slope), so residual degrees of freedom =9−2=7. Answer B is correct.
Answer A is wrong because it counts four "missing entries" as four dropped rows — but rows 2 and 7 share the same observation, and missing entries, not rows, were counted. Answer C incorrectly includes row 10 (missing z) in the exclusion, and its logic about row 7 being "counted twice" misunderstands how na.omit works: a row is dropped once regardless of how many of its formula variables are NA. Answer D is wrong in the opposite direction — it claims only y-missing rows are dropped, ignoring that missing predictor values (x in row 9) also trigger omission.
A useful rule of thumb: R's default na.omit performs casewise (listwise) deletion on formula variables only — count unique rows affected, then subtract coefficients.For a fitted model fit <- lm(y ~ x, data = d), an analyst uses predict(fit, newdata = data.frame(x = 10), interval = "confidence"). The analyst instead needs an interval for a single future response observed at x = 10. Which change and interpretation are appropriate, assuming the usual linear-model conditions?
interval = "confidence"; it already includes future individual-response variation.interval = "prediction"; its center changes, but its interval is generally narrower.interval = "prediction"; its center is the same, but its interval is generally wider. (correct answer)interval = "confidence"; prediction intervals and confidence intervals are numerically identical.predict() in R, ask yourself: am I estimating the mean response at a given x, or am I predicting one new individual observation? These require different intervals, and confusing them is one of the most common modeling mistakes.
A confidence interval (CI) for the mean captures uncertainty about where the true average response falls at x = 10. A prediction interval (PI) captures that same uncertainty plus the natural scatter of individual observations around the mean — represented by the residual variance σ2. Formally, the CI width depends on SE(μ^), while the PI adds σ^2 underneath the square root:
PI=y^±t∗⋅σ^1+n1+Sxx(x∗−xˉ)2
Notice the extra "1" inside the square root — that single term is what widens the prediction interval. Critically, both intervals share the same center y^; only the width differs.
This makes C correct: switching to interval = "prediction" keeps the point estimate identical but produces a wider interval, as required for a single future observation.
A is wrong because a confidence interval does not account for individual-response variability — it only reflects uncertainty about the mean.
B is wrong on two counts: the center does not change between CI and PI, and prediction intervals are wider, not narrower, than confidence intervals.
D is wrong because the two intervals are numerically distinct; only their centers coincide.
As a study tip, remember: "confidence" → mean, "prediction" → individual. Same center, PI is always wider.An analyst fits lm(log(y) ~ x, data = d) and obtains an intercept of 2 and an x coefficient of 0.1. According to the fitted equation, what is the effect of increasing x by 3 units on the back-transformed fitted value?
lm(log(y) ~ x), you need to remember that predictions live on the log scale, and back-transformation requires exponentiation — not simple arithmetic.
The fitted equation on the log scale is log(y^)=2+0.1x. When you increase x by 3, the log-scale prediction changes by 0.1×3=0.3. To understand the multiplicative effect on y^ itself, consider two predictions at values x0 and x0+3:
y^new=e2+0.1(x0+3)=e2+0.1x0⋅e0.3=y^old⋅e0.3
The intercept cancels out completely in the ratio. So the fitted value is multiplied by e0.3≈1.35, confirming B is correct.
A is wrong because a change on the log scale does not transfer additively to the original scale — you must exponentiate. C incorrectly includes the intercept (e2.3) in the multiplicative effect. Since you're measuring a change between two predictions, the intercept cancels — it shifts both values equally. D tempts you with the "log ≈ percent change" approximation, which only holds for very small changes; a log-scale shift of 0.3 corresponds to a 35% increase (e0.3−1), not 30%.
As a study tip, always take the ratio of two back-transformed predictions when assessing a unit-change effect in log-linear models — intercepts vanish and only the slope-driven term remains.A model is fit with lm(y ~ x * group), where group has reference level A and comparison level B. The estimated coefficients are: intercept 10, x 2, groupB 5, and x:groupB −1.5. For an observation in group B, how much does the fitted response change when x increases from 4 to 7?
x * group, the slope of x is not the same for all groups — it depends on which group an observation belongs to. Your job is to find the effective slope for the specific group in question, then multiply by the change in x.
For group B, the effective slope of x is the reference-group slope plus the interaction coefficient: 2+(−1.5)=0.5. When x increases from 4 to 7, that's a change of Δx=3. The predicted change in response is 0.5×3=1.5, so the fitted value increases by 1.5. That confirms A is correct.
Here's why each distractor fails. B uses the reference-group slope of 2 and computes 2×3=6, but that slope applies to group A only — it ignores the interaction term entirely, which is exactly the trap the question is setting. C focuses only on the interaction coefficient −1.5 and multiplies it by Δx=3 to get −4.5, confusing the adjustment to the slope with the slope itself; the interaction term modifies the slope, it doesn't replace it. D adds the groupB main effect (5) into the slope calculation, but main effects shift the intercept for group B, not the slope — the groupB coefficient is irrelevant when calculating how much the response changes with x.
A useful rule of thumb: when computing change in ŷ, intercept-type terms (including group main effects) cancel out. Only terms involving x matter — so always build the effective slope first, then multiply by Δx.A factor treatment has levels control, drugA, and drugB, with control as the reference level. For lm(response ~ treatment), the estimated coefficients are: intercept 50, treatmentdrugA −4, and treatmentdrugB 6. If drugB is made the reference level and the model is refitted, which coefficients should result?
treatmentcontrol −6, and treatmentdrugA −10. (correct answer)treatmentcontrol 6, and treatmentdrugA −4.treatmentcontrol 6, and treatmentdrugA −4.treatmentcontrol 50, and treatmentdrugA 46.treatmentcontrol is then control−drugB=50−56=−6, and treatmentdrugA is 46−56=−10. That gives you intercept 56, treatmentcontrol −6, treatmentdrugA −10 — exactly answer A.
Answer B is a trap: it keeps the original intercept of 50 and coefficients unchanged, which would only be correct if the reference level hadn't changed. Answer C gets the intercept right (56) but incorrectly reuses the old coefficients without adjusting them to the new baseline — a common half-step error. Answer D appears to confuse coefficients with raw means in a scrambled way, producing nonsensical values that don't correspond to any coherent model.
A reliable strategy: always recover the group means first, then rebuild from the new reference. The means never change; only the arithmetic used to express them does. In R, use relevel(treatment, ref = "drugB") before refitting to let R handle this automatically.A model lm(y ~ x1 + x2) is fit using 10 complete observations. Its residual sum of squares is 18, and the total sum of squares around the sample mean is 90. Which pair gives the model's multiple R2 and adjusted R2, respectively?
An analyst fits fit <- lm(score ~ hours + prior, data = d). The estimated intercept is 20, the coefficient of hours is 3, and the coefficient of prior is 0.5. Student 1 has hours = 4 and prior = 60; Student 2 has hours = 2 and prior = 68. According to the fitted model, how do their predicted scores compare?
hours effect: Student 1 studies 2 more hours, so 3×2=6 extra points from hours, but you must also account for the prior difference. Student 2 has 8 more prior points, contributing 0.5×8=4 extra points, which partially offsets Student 1's advantage: 6−4=2, not 10. C reverses the direction — Student 2 does benefit more from prior, but not enough to overcome Student 1's larger hours advantage. D is tempting because the predictors do partially offset each other, but "exactly" is wrong; the net difference is 2 points, not zero.
A useful habit: when comparing two observations, calculate the difference in each predictor, multiply by its coefficient, then sum. Here, 3(4−2)+0.5(60−68)=6−4=2. This shortcut saves time and reduces arithmetic errors.An analyst fits fit <- lm(y ~ x + z, data = d) and obtains the fitted equation y^=4+2x−3z. For one row, x=5, z=1, and the observed response is 18. What are the fitted value and ordinary residual for that row?
In every row of a data frame, x2 equals exactly twice x1. An analyst fits lm(y ~ x1 + x2, data = d). Which outcome best describes the fitted model?
lm() automatically standardizes correlated predictors before solving the normal equations.lm() detects this rank deficiency and drops one redundant predictor (typically x2), setting its coefficient to NA. This means the two slopes cannot be separately identified — infinitely many combinations of β1 and β2 satisfying β1+2β2=c produce identical fitted values. The model still runs and still produces fitted values (and predictions) using the reduced-rank solution, which is exactly what D describes.
A is wrong because lm() does not automatically standardize predictors before solving the normal equations. Even if it did, standardizing perfectly collinear columns wouldn't break the dependence — they'd still be proportional.
B is wrong because lm() does return a solution; it simply drops the linearly dependent column and estimates the remaining coefficients. Coefficients are not forced to zero, and no error is thrown — just a warning and an NA for the dropped term.
C is wrong because the intercept is unaffected by collinearity among predictors. The intercept is estimated normally; it's the slopes that become non-uniquely estimable, not the intercept.
Study tip: When you see "exact collinearity" in a question, remember the key consequence: fitted values are still valid, but individual slopes are not separately identifiable. Always check summary(model) for NA coefficients as your diagnostic signal.Suppose group has levels A and B, and an analyst fits lm(y ~ 0 + group + x). The estimated coefficients are groupA 10, groupB 15, and x 2. Which interpretation is correct?
groupB coefficient is added to groupA, so group B's baseline fitted value is 10+15=25.lm(y ~ 0 + group + x) in R, recognize that suppressing the global intercept with 0 causes R to estimate a separate intercept for each factor level rather than one shared baseline. Each group coefficient becomes that group's fitted value of y when x=0, and the slope on x applies equally to both groups.
With coefficients groupA =10, groupB =15, and x =2, the fitted value equations are:
y^A=10+2xy^B=15+2x
At x=0, group A fits to 10 and group B fits to 15. Because both lines share the same slope of 2, their vertical distance stays at 15−10=5 for every value of x. That makes B the correct interpretation.
A is wrong because the group coefficients here are adjusted baselines (controlling for x), not raw sample means — and the claim that the difference "applies only at x=0" is misleading; since the slope is shared, the difference is constant everywhere. C is wrong because removing the intercept does not force group A's fitted value to zero — it simply gives each group its own intercept estimated from the data. D reflects a confusion with treatment-coded (dummy) models, where one group's coefficient is added to a reference intercept; in a no-intercept model, groupA and groupB are independent, not cumulative.
As a quick rule of thumb: in ~ 0 + factor, every level gets its own intercept — they are never added together.