R Programming Language Certification Statistical Analysis & Modeling in R 2 — Questions and Answers
Question 1: Which R function fits a logistic regression model?
- glm() with family = binomial (Correct answer)
- lm() with type = logistic
- logit()
- glm() with family = gaussian
Correct answer: glm() with family = binomial
Logistic regression is fit with glm(y ~ x, family = binomial(link='logit')), which models binary outcomes.
Question 2: What does the confint() function return for a fitted model in R?
- Confidence intervals for model coefficients (Correct answer)
- A confidence interval for the mean response
- The model's AIC score
- A bootstrap sample
Correct answer: Confidence intervals for model coefficients
confint() computes confidence intervals for the parameters of a fitted model, defaulting to 95% intervals.
Question 3: Which R function tests whether a numeric vector follows a normal distribution using the Shapiro-Wilk test?
- shapiro.test() (Correct answer)
- normtest()
- ks.test()
- normalcy()
Correct answer: shapiro.test()
shapiro.test() performs the Shapiro-Wilk normality test and returns a W statistic and p-value.
Question 4: What is the purpose of the predict() function in R?
- Generate predicted values from a fitted model for new data (Correct answer)
- Fit a new model
- Cross-validate a model
- Compute model residuals
Correct answer: Generate predicted values from a fitted model for new data
predict() uses a fitted model object to generate predictions for either the training data or new observations supplied via newdata=.
Question 5: Which R package provides tools for cross-validation and training machine learning models with a unified interface?
- caret (Correct answer)
- mlr
- tidymodels
- scikit
Correct answer: caret
caret (Classification And REgression Training) provides a unified interface for training, tuning, and evaluating hundreds of ML models.
Question 6: Which test in R is appropriate for testing association between two categorical variables in a contingency table?
- chisq.test()
- fisher.test()
- Both chisq.test() and fisher.test() (Correct answer)
- prop.test()
Correct answer: Both chisq.test() and fisher.test()
Both chisq.test() and fisher.test() test independence in contingency tables; Fisher's exact test is preferred for small expected counts.
Which R function fits a logistic regression model?