statmanrobin / Stat2Data

Datasets for the Stat2 Textbook
4 stars 5 forks source link

Better error messages for `emplogitplot2` #3

Open AmeliaMN opened 1 year ago

AmeliaMN commented 1 year ago

The function emplogitplot2 only works if the categorical variable you are providing is formatted as a factor. If not, you get the opaque error message

Error in eval(predvars, data, env) : object 'Logit' not found

For example, if we take the MedGPA data used in the documentation and transform Sex back into a character variable,

MedGPA <- MedGPA %>%
mutate(Sex = as.character(Sex))

Then running

emplogitplot2(Acceptance~GPA+Sex,data=MedGPA)

returns

Error in eval(predvars, data, env) : object 'Logit' not found

An error message like No factor variable found, please ensure your categorical variable is of the type factor would be much easier to interpret.