What this quiz covers
This quiz focuses on Logistic Regression Glm, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
A logistic model for a positive outcome has linear predictor 1.2−0.4x. An observation is classified as positive when its fitted probability is at least 0.5.
Which values of x will be classified as positive under this rule?
R Programming Quiz
Practice Logistic Regression Glm 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 Logistic Regression Glm, 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 logistic model for a positive outcome has linear predictor 1.2−0.4x. An observation is classified as positive when its fitted probability is at least 0.5.
Which values of x will be classified as positive under this rule?
A model is fitted with glm(y ~ hours * group, family = binomial, data = d). Group A is the reference level. The estimated coefficient for hours is 0.5, and the estimated coefficient for hours:groupB is −0.7.
What is the estimated effect of one additional hour for observations in group B?
glm includes an interaction term like hours * group, the coefficient for hours alone represents the effect of one additional hour only for the reference group (here, group A). For any other group, you must add the relevant interaction coefficient to get the true slope for that group.
For group B specifically, the effect of one additional hour on the log-odds is:
0.5+(−0.7)=−0.2
This means one additional hour decreases the log-odds by 0.2 for group B observations. Converting to an odds ratio: e−0.2≈0.82, confirming answer B is correct.
Choice A applies the hours coefficient (0.5) as if group B behaves identically to group A — this ignores the interaction term entirely, which is the most common mistake students make with interaction models. Choice C treats the interaction coefficient (−0.7) as the complete effect for group B, forgetting that the base slope for hours still applies and must be included. Choice D adds the two coefficients incorrectly as positives: 0.5+0.7=1.2, suggesting the student may have misread the sign of the interaction term or mistakenly treated it as reinforcing rather than opposing the base effect.
A reliable strategy: whenever you see an interaction term in a regression model, mentally build a "slope formula" for each group — start with the base coefficient, then add any interaction terms that apply to that group. This keeps you from accidentally using partial information, which is exactly the trap this question is designed to set.An analyst fits glm(churn ~ plan, family = binomial, data = customers). The factor plan has reference level basic. The estimated coefficients are planpremium = -0.8 and planstandard = 0.3.
Holding all else fixed, what is the estimated odds ratio for churn comparing premium with standard?
premium coefficient should be exponentiated.standard coefficient is the comparison baseline.basic is the reference. The model gives you:
standard as a new baseline and uses only its coefficient (e0.3≈1.35, not 2.23) — the reasoning is muddled and the arithmetic doesn't follow from any coherent method.
D flips the subtraction order: 0.3−(−0.8)=1.1, so e1.1≈3.00. This gives you the odds ratio for standard vs. premium, not premium vs. standard. The sign matters.
A useful habit: always ask "which group is in the numerator?" When comparing A to B, compute eβA−βB, where both coefficients are measured against the same reference.A fitted model has the linear predictor −2+0.7x−1.1z, where the response level treated as success is yes.
What probability does the model predict for an observation with x=2 and z=1?
For a new observation, predict(fit, newdata = new_case) returns 0.8 from a model fitted using family = binomial with the default logit link.
Which statement correctly interprets this result and obtains the predicted probability?
predict(fit, new_case, type = "response") gives about 0.690. (correct answer)exp() gives a probability of about 2.226.predict() used with a glm object fitted using family = binomial, you need to ask yourself: what scale is the prediction on? By default — without specifying type = "response" — R returns predictions on the link scale, which for the logit link means log-odds, not probabilities.
This is exactly what's happening in option B. The value 0.8 is a log-odds (logit) value. To convert it to a probability, you apply the inverse logit (sigmoid) transformation: p=1+e0.8e0.8=3.22552.2255≈0.690. Equivalently, you can simply add type = "response" to your predict() call and R does this conversion for you automatically. B is correct on both counts.
Option A is wrong because the default prediction scale is not the response scale — that's a very common trap. You must explicitly request type = "response" to get probabilities. Option C confuses log-odds with raw odds; the conversion formula p=odds/(1+odds) does apply to odds, but 0.8 here is a log-odds value, not odds — and applying that formula gives 0.444, which is incorrect. Option D treats 0.8 as a log-probability and applies exp(), yielding 2.226 — a value greater than 1, which can never be a probability. That alone should immediately signal something is wrong.
Your study tip: always remember that predict(fit) defaults to the link scale for GLMs. Use type = "response" whenever you want the predicted probability directly.A two-level factor response result has levels ordered as c("fail", "pass"). A logistic model is fitted with glm(result ~ x, family = binomial, data = d). The analyst then makes pass the first factor level and refits the same formula on the same complete observations.
How should the refitted model generally relate to the original model?
glm with family = binomial models the probability of the second factor level — the one coded as 1. When levels are c("fail", "pass"), R codes "fail" = 0 and "pass" = 1, so the model predicts P(pass).
When you reorder the levels so that "pass" comes first — c("pass", "fail") — R now codes "pass" = 0 and "fail" = 1. The model switches to predicting P(fail). Since the log-odds of failure is simply the negative of the log-odds of success, every coefficient flips sign: the new intercept equals −β^0 and the new slope equals −β^1. This makes answer A correct — the model now targets failure, and both estimates are negated.
Answer B is wrong because it claims the model still predicts passing, which ignores how R determines the reference outcome from factor level ordering. Answer C is wrong in a subtle way: it correctly notes the model switches to predicting failure, but claiming only the slope negates is incorrect — the intercept flips too, since the entire linear predictor changes sign. Answer D is wrong because it assumes nothing changes, which would only be true if the response coding remained identical.
A handy rule: in R, logistic regression always models the last factor level. Change that ordering, and you flip both the target outcome and the sign of every coefficient.An analyst fits fit <- glm(admitted ~ prep_hours + prior_score, family = binomial, data = applicants). The estimated coefficient for prep_hours is 0.405. Two applicants have the same prior_score, but one completed 2 more preparation hours than the other.
According to the fitted model, how do the applicants' predicted odds of admission compare?
prep_hours is 0.405 and the difference is 2 hours, so the odds ratio is:
e0.405×2=e0.810≈2.25
This confirms C — the applicant with more preparation has about 2.25 times the predicted odds of admission.
Choice A (1.50) corresponds to roughly e0.405, which is the odds ratio for only a one-hour difference, not two. Choice B (1.81) is close to e0.405×1.5, suggesting someone mistakenly used 1.5 instead of 2 as the multiplier, or miscalculated the exponent. Choice D (2.81) likely comes from arithmetic errors such as doubling the odds ratio multiplicatively (1.50×1.50≈2.25 is correct, but confusing addition and multiplication can push the result higher).
A useful tip: whenever a question specifies a multi-unit difference, always scale the exponent first — compute β^×Δx, then exponentiate. Exponentiating first and multiplying after is a common trap that leads to the wrong answer.A model is fitted with glm(y ~ age + region, family = binomial, data = train). In train, factor region has only the levels East and West. The analyst calls predict(fit, newdata = data.frame(age = 40, region = factor("North")), type = "response").
What should the analyst generally expect from this prediction call?
North as the reference level and uses only the fitted age contribution.North the average of the estimated East and West effects.North to the nearest known level.NA for the prediction, because North was not present among the levels used when fitting the model. (correct answer)predict() function, the key question to ask yourself is: does the new data contain only factor levels that the model has seen during training? R encodes factors as dummy variables based on the levels present at fit time, so any unseen level breaks that encoding entirely.
When you pass region = factor("North") to predict(), R cannot construct a valid model matrix row for this observation — it has no coefficient for North because that level never appeared in train. As a result, R issues a warning such as "factor region has new levels: North" and returns NA for that prediction. This is answer D, and it's the correct behavior — R refuses to silently fabricate a result.
Answer A is wrong because R doesn't quietly fall back to a reference-level interpretation. The reference level (East) is encoded as all-zero dummies, but R doesn't reassign North to that encoding; it flags the problem instead. Answer B is wrong because R has no mechanism to average coefficients across known levels — that would require custom logic you'd have to write yourself. Answer C is the most tempting distractor: you might assume R "rounds" to the nearest level, but R performs no such coercion. It does not resolve unknown factor levels by proximity or any other heuristic.
A good rule of thumb: before calling predict(), always verify that your new data's factor levels are a subset of those in the training data. Use levels(train$region) to check, and consider using factor(..., levels = levels(train$region)) when constructing new data frames.Data frame d contains one row per dose level. Each row records success, the number of successful trials, and total, the number of trials. The analyst fits glm(cbind(success, total - success) ~ dose, family = binomial, data = d).
Which alternative call represents the same grouped-binomial information?
glm(cbind(total - success, success) ~ dose, family = binomial, data = d)glm(success / total ~ dose, family = binomial, weights = success, data = d)glm(success / total ~ dose, family = binomial, data = d)glm(success / total ~ dose, family = binomial, weights = total, data = d) (correct answer)cbind(successes, failures), or a proportion response with a weights argument telling R the total number of trials per row. Understanding this equivalence is what this question tests.
The original call uses cbind(success, total - success), meaning the first column is successes and the second is failures. R's binomial family models the probability of the first column event, using both columns to recover the total. The equivalent proportion-based form divides successes by total to get the observed proportion, then supplies weights = total so R knows how many trials each proportion is based on. This is exactly what D does — it preserves all the same information: the estimated proportion and the denominator needed to reconstruct the likelihood.
A is wrong because it reverses the columns to cbind(total - success, success), which models the probability of failure rather than success. This flips the sign of all coefficients and changes the interpretation entirely.
B is wrong because it uses weights = success instead of weights = total. The weight in a binomial GLM must represent the number of trials, not the number of successes — using successes as weights provides incorrect denominators and distorts the likelihood.
C is wrong because it omits the weights argument entirely. Without knowing how many trials each proportion came from, R treats each row as a single Bernoulli trial, discarding all information about sample size.
A handy rule: whenever you use a proportion as the response in a binomial GLM, always ask yourself "what is the denominator?" — that answer belongs in weights.In a logistic model, the estimated coefficient for exposure is 0.2, with a confidence interval on the log-odds scale from −0.2 to 0.6.
Which interpretation of this interval is most appropriate?