Recall & Review
beginner
What does releveling a factor mean in R?
Releveling a factor means changing which level is considered the reference or baseline level. This affects how comparisons are made in analyses like regression.
Click to reveal answer
beginner
How do you relevel a factor in R to set a new reference level?
Use the function
relevel(). For example, relevel(factor_variable, ref = "new_level") sets "new_level" as the reference.Click to reveal answer
intermediate
Why is it important to set the correct reference level in a factor variable?
The reference level determines the baseline group for comparisons in models. Choosing the right reference helps interpret results clearly and meaningfully.
Click to reveal answer
intermediate
What happens if you do not relevel a factor before running a regression in R?
R uses the first level in the factor's levels attribute as the reference by default, which is often the first level in the order the factor was created (not necessarily alphabetical). This might not be meaningful and can lead to confusing interpretations.
Click to reveal answer
beginner
Show an example of releveling a factor in R and explain the output.
Example:<br>
f <- factor(c("low", "medium", "high"))<br>f_new <- relevel(f, ref = "high")<br>levels(f_new)<br>Output:<br>[1] "high" "low" "medium"<br>This means "high" is now the baseline level for comparisons.Click to reveal answer
What function is used in R to change the reference level of a factor?
✗ Incorrect
The function
relevel() is specifically designed to set a new reference level for a factor.If you do not relevel a factor, which level does R use as the reference by default?
✗ Incorrect
By default, R uses the first level in the factor's levels attribute as the reference level, which is often the first level in the order the factor was created (not necessarily alphabetical).
Why might you want to relevel a factor before running a regression?
✗ Incorrect
Releveling sets a meaningful baseline level, which helps interpret regression coefficients clearly.
What does the argument
ref in relevel() specify?✗ Incorrect
The
ref argument specifies which level should become the new reference level.After releveling a factor, what does
levels() show?✗ Incorrect
After releveling,
levels() shows the factor levels with the new reference level listed first.Explain what releveling a factor means and why it is useful in R.
Think about how the baseline group affects comparisons.
You got /3 concepts.
Describe how to use the relevel() function with an example.
Show how to set a new baseline level.
You got /4 concepts.