Course Outline
-
segmentGetting Started (Don't Skip This Part)
-
segmentStatistics and Data Science: A Modeling Approach
-
segmentPART I: EXPLORING VARIATION
-
segmentChapter 1 - Welcome to Statistics: A Modeling Approach
-
segmentChapter 2 - Understanding Data
-
segmentChapter 3 - Examining Distributions
-
segmentChapter 4 - Explaining Variation
-
segmentPART II: MODELING VARIATION
-
segmentChapter 5 - A Simple Model
-
segmentChapter 6 - Quantifying Error
-
segmentChapter 7 - Adding an Explanatory Variable to the Model
-
7.4 How the Model Makes Predictions
-
segmentChapter 8 - Digging Deeper into Group Models
-
segmentChapter 9 - Models with a Quantitative Explanatory Variable
-
segmentPART III: EVALUATING MODELS
-
segmentChapter 10 - The Logic of Inference
-
segmentChapter 11 - Model Comparison with F
-
segmentChapter 12 - Parameter Estimation and Confidence Intervals
-
segmentChapter 13 - What You Have Learned
-
segmentFinishing Up (Don't Skip This Part!)
-
segmentResources
list High School / Advanced Statistics and Data Science I (ABC)
7.4 How the Model Makes Predictions
Here’s the best-fitting model of thumb length using sex as an explanatory variable:
Armed with this understanding of how
If
How Does R Know Which Sex to Represent with ?
The answer to this question is: R doesn’t know; it’s just taking whatever group comes first alphabetically (in this case, female
) and making it the reference group. The mean of the reference group is the first parameter estimate (lm()
output).
R then takes the second group (in this case, male
) and represents it with the dummy variable male
. If it is coded 0, then the student is not male
.
Let’s say, just for fun, that you changed the label for male
to man
and the label for female
to woman
in the data frame. Because man
comes before woman
alphabetically, man
becomes the reference group, and its mean is now the estimate for the intercept (
As long as R knows that a variable is categorical (e.g., a factor), it doesn’t really care how you code it. You can code the categories under Sex
with any characters you choose (e.g., female
or woman
), or with any numbers you choose (e.g, 1 and 2, 0 and 1, or 1 and 500). However you code it, R will take the category that comes first as the intercept (