Skip to content
R for the Rest of Us Logo

Inferential Statistics with R

Multiple Regression

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

Perform a multiple regression examining how both iq and act_science predict act_reading. Ask for standardized coefficients before calling for the summary of results. Which (if any) of the IVs are significant predictors? Based on the standardized coefficient, which is the stronger predictor of ACT readings cores?

Learn More

Read more about the lm() function in the stats package.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Mike LeVan

Mike LeVan • January 8, 2025

Hi,

I am getting an error when I try to change the reference level. I have checked my code and it is the same as yours, but I get this error :

Error in `mutate()`:
 In argument: `gender = fct_relevel(gender, levels = "Trans*", "Female",
  "Male")`.
Caused by error in `fct_relevel()`:
! Arguments in `...` must be passed by position, not name.
 Problematic argument:
 levels = "Trans*"
Run `rlang::last_trace()` to see where the error occurred.

Here is the Back Trace : 

Backtrace:
     
  1. ├─... %>% summary()
  2. ├─base::summary(.)
  3. ├─lm.beta::lm.beta(.)
  4.  └─"lm" %in% attr(object, "class")
  5. ├─stats::lm(exam_2 ~ iq + gender, data = .)
  6.  └─base::eval(mf, parent.frame())
  7.    └─base::eval(mf, parent.frame())
  8.      ├─stats::model.frame(...)
  9.      └─stats::model.frame.default(...)
 10.        └─base::is.data.frame(data)
 11. ├─dplyr::mutate(...)
 12. ├─dplyr:::mutate.data.frame(...)
 13.  └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
 14.    ├─base::withCallingHandlers(...)
 15.    └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
 16.      └─mask$eval_all_mutate(quo)
 17.        └─dplyr (local) eval()
 18. └─forcats::fct_relevel(gender, levels = "Trans*", "Female", "Male")
> 

Thanks, Mike

David Keyes

David Keyes Founder • January 8, 2025

I'm guessing your code looks like this:

fct_relevel(gender, levels = "Trans*", "Female",  "Male")

If so, you need to change it to this (note the c() around the levels):

fct_relevel(gender, levels = c("Trans*", "Female", "Male"))

Let me know if that solves it for you!

Mike LeVan

Mike LeVan • January 9, 2025

Hi,

Appreciate your time.

Thanks for the idea, but that didn't fix the issue. Still getting this error :

Error in mutate(): ℹ In argument: gender = fct_relevel(gender, levels = c("Trans*", "Female", "Male")). Caused by error in fct_relevel(): ! Arguments in ... must be passed by position, not name. ✖ Problematic argument: • levels = c("Trans*", "Female", "Male")

Thanks, Mike

Dana Linnell

Dana Linnell • January 11, 2025

fct_relevel must have changed since I created this many years ago. This line of code worked for me:

mutate(gender = fct_relevel(gender, "Trans*", "Female", "Male"))