jeff-hughes / reghelper

R package with regression helper functions
5 stars 5 forks source link

Using formula(x) is deprecated when x is a character vector of length > 1. #11

Closed ConnorEsterwood closed 3 years ago

ConnorEsterwood commented 3 years ago

I'm getting an error when I try to run a smiple_slopes with a three-way interaction.

EX: out <- lm(dv ~ iv1 + mod1 + mod2 + ctrl1 + dv1:PAW_Avg + iv1:mod1+ iv1:mod1:mod2, data = data)

Data is similar to this:

DV = continuous measure Mod1 = categorical A/B/C/D/E Mod2 = categorical T1/T2/T3 Ctrl1 = continuous measure


When I pass it into simple_slope like this:

simp_slope <- simple_slopes(out)

I get the following error messages and only mod2 appears in the output.

Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead.

Sorry if this is confusing but based on the error this might be something to do with the way that the function is written ??

jeff-hughes commented 3 years ago

Hi there,

I believe there are two issues going on here. The warning message about character vectors seems to be the same thing discussed in Issue #10, which I believe I developed a fix for. However, the real problem the person was having was resolved through other means, and then I just never bothered to release a new version. It should go away if you install the package from Github:

install.packages("devtools")
devtools::install_github("jeff-hughes/reghelper")

However, it's just a warning and does not have an impact on the estimates provided. So this is completely optional. If/when I push out a new version, that fix will be included.

The other issue you're having with regard to only mod2 appearing in the output is because of the way you specified your model. Using : only includes the single interaction term, as opposed to * which adds all the main effects and lower-order interactions as well. Your model thus excludes both the iv1:mod2 and mod1:mod2 interaction terms, which are lower-order effects upon which the three-way interaction is conditional. The simple_slopes() function assumes that all the lower-order effects related to the highest-order interaction are present in the model, and so it gets tripped up by these missing interaction terms. Running out <- lm(dv ~ ctrl1 + iv1* PAW_Avg + iv1 * mod1 * mod2, data = data) should produce more coherent results (with the above warning about character vectors still remaining, of course).

Perhaps you have legitimate reasons to exclude those effects from your model; however, my best understanding is that trying to interpret interactions when the lower-order effects are missing is likely to be misleading. But regardless, that is what the simple_slopes() function is expecting.

ConnorEsterwood commented 3 years ago

This was a great help and thanks for the thoughtful and well-written feedback!