For this lab, you’ll be using the gifted data set. This
data set was originally published in “Regression Analysis: Concepts and
Applications” in 1994. It was used to aid in understanding if any
relationships exist between a gifted child’s analytics skills.
A data dictionary can be found in the “Help” tab of RStudio or at openintro.org/data.
Use the outline below to build a linear model that predicts the age at which a child first counted to 10 successfully. Your goal is to find a model with a correlation value above 0.80.
Use the code chuck below to visually check for a relationship. You can copy/paste the code snippet to create plots for more than one explanatory variable.
ggplot(gifted, aes(count, count)) +
geom_point()
Once you’ve visually found at least one potential explanatory variable, use the chuck below to check the correlation. As above, you can copy/paste the code snippet as needed.
get_correlation(gifted, count ~ count, na.rm = TRUE)
## # A tibble: 1 × 1
## cor
## <dbl>
## 1 1
Now that you’ve found the correct explanatory variable, let’s build
the model and check that we’ve met the second and third conditions for
regression. For the histogram, you may need to adjust the number of
columns or bins.
count_mod <- lm(count ~ count, gifted)
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on
## the right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 1 in
## model.matrix: no columns are assigned
ggplot(count_mod, aes(.resid)) +
geom_histogram(bins = 30)
## Warning in model.matrix.default(object, data = structure(list(count = c(26L, :
## the response appeared on the right-hand side and was dropped
## Warning in model.matrix.default(object, data = structure(list(count = c(26L, :
## problem with term 1 in model.matrix: no columns are assigned
ggplot(count_mod, aes(.fitted, .resid)) +
geom_point() +
geom_hline(yintercept = 0)
## Warning in model.matrix.default(object, data = structure(list(count = c(26L, :
## the response appeared on the right-hand side and was dropped
## Warning in model.matrix.default(object, data = structure(list(count = c(26L, :
## problem with term 1 in model.matrix: no columns are assigned
Now we want to use the model to make a prediction. Choose an appropriate value for the explanatory variable and make a prediction for the age when a child first counted to 10 successfully.
predict(count_mod, newdata = data.frame(count = 140))
## 1
## 30.69444