ARTool icon indicating copy to clipboard operation
ARTool copied to clipboard

art.con: error when building model with within-subject style Error term

Open thomaskoehn11 opened this issue 3 years ago • 10 comments

When I do

art_model <- art(values ~ X*Y + Error(participant / (X*Y)), data = my_data)

and run

art.con(art_model, "X:Y")

I receive

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

Mind that my_data is a data.frame and X, Y and participant are factors. values is a num.

Mind that the following commands do work, and produce sensible results:

summary(art_model)
anova(art_model)
art.con(art_model, "X")
art.con(art_model, "Y")

And likewise, if I create the model instead with a shorter Error term like this:

art_model <- art(values ~ X*Y + Error(participant), data = my_data)

The original problematic line works and produces sensible results:

art.con(art_model, "X:Y")

Additional alternations, in the hope to provide more help – mind the adjusted Error terms and error message:

art_model <- art(values ~ X*Y + Error(participant / (X)), data = my_data)
art.con(art_model, "X:Y")
=> Error in eval(predvars, data, env) : object 'X' not found
art_model <- art(values ~ X*Y + Error(participant / (Y)), data = my_data)
art.con(art_model, "X:Y")
=> Error in eval(predvars, data, env) : object 'Y' not found

My environment:

  • macOS 10.14.6
  • RStudio 2021.09.2
  • R 4.1.3
  • ARTool 0.11.1

Thanks for the help @mjskay , and thanks for ARTool! :)

thomaskoehn11 avatar Nov 17 '22 17:11 thomaskoehn11

I can also confirm that the issue is not dataset-specific, as I just ran into the same error with a completely different dataset (only similarly is that both use the same amount of participants & conditions, but measured completely different data).

I can also confirm that both datasets were either fully or primarily non-normally distributed, and summary(art_model) showed all the expected items as 0.

thomaskoehn11 avatar Nov 18 '22 18:11 thomaskoehn11

@mjskay Hi Matthew. Apologies for pinging. Any chance you can look into this? Also happy to hear if I got something wrong and the above is actually expected behavior. Thanks!

thomaskoehn11 avatar Dec 09 '22 08:12 thomaskoehn11

I experience the same issue on two datasets. The art-function provides reasonable results, and so does the art.con function if I try to calculate the post-hoc tests for the main effects only. As soon as I try to calculate the interaction, I get the exact same error message as described above. The interaction contrasts (comparing differences of differences; interaction = TRUE) is working.

Frauke13 avatar Dec 17 '22 22:12 Frauke13

@mjskay This is really an issue. Is there any fix planned?

biosmanager avatar Aug 28 '23 13:08 biosmanager

Can you give a test dataset (on synthetic data will do) giving the error with a reprex? Thanks!

mjskay avatar Aug 28 '23 15:08 mjskay

@mjskay Sure thing:

library(ARTool)
data(Higgins1990Table5, package = "ARTool")

m <- art(DryMatter ~ Moisture*Fertilizer + Error(Tray/(Moisture*Fertilizer)), data=Higgins1990Table5)
print(art.con(m, ~ Moisture*Fertilizer))
#> Error in eval(predvars, data, env): object 'Moisture' not found

Created on 2023-08-28 with reprex v2.0.2

A slightly different error term gives this error:

library(ARTool)
data(Higgins1990Table5, package = "ARTool")

m <- art(DryMatter ~ Moisture*Fertilizer + Error(Tray), data=Higgins1990Table5)
print(art.con(m, ~ Moisture*Fertilizer))
#> Error in X[ii, ii, drop = FALSE] %*% y[ii]: non-conformable arguments

Created on 2023-08-28 with reprex v2.0.2

biosmanager avatar Aug 28 '23 21:08 biosmanager

Ah okay, I see the issue now. Fixing it for the repeated measures ANOVA is a bit of a pain, but fixing it for mixed effects models was straightforward. I put a fix on the dev branch for mixed effects models, for which you should be able to create an equivalent specification. A model like this:

m = art(values ~ X*Y + Error(participant / (X*Y)), data = my_data)

As random slopes in a mixed effects model would be:

m = art(values ~ X*Y + (X*Y | participant), data = my_data)

Which should now work with something like:

art.con(m, ~ X*Y)

To use this, you have to install the dev branch first via:

devtools::install_github("mjskay/ARTool@dev")

Let me know if that helps.

mjskay avatar Aug 29 '23 02:08 mjskay

Thanks for the effort! @mjskay I am not familiar with random slopes - is this really equivalent to a repeated measures model in all cases? Do you think that a fix for RM can also be implemented soon? We are currently conducting statistical analysis for a paper deadline ;)

biosmanager avatar Aug 29 '23 06:08 biosmanager

Ah, personally I would prefer the random slopes model, but you can get the precisely equivalent model in lmer using the same nesting syntax; something like:

m = art(values ~ X*Y + (1 | participant / (X*Y)), data = my_data)

See the Remark at the end of section 6.2.2 here.

You can verify by using aov() and lmer() directly on the data that these models are equivalent.

mjskay avatar Aug 29 '23 12:08 mjskay

(as I am under a paper deadline myself and the random effects syntax should yield the same model, I am unlikely to fix the error term syntax at the moment - it will require more hairy rewriting of internal code)

mjskay avatar Aug 29 '23 12:08 mjskay