Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomaskoehn11 opened this issue Nov 17, 2022 · 10 comments

Comments

@thomaskoehn11
Copy link

thomaskoehn11 commented Nov 17, 2022

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
Copy link
Author

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
Copy link
Author

@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!

@Frauke13
Copy link

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.

@biosmanager
Copy link

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

@mjskay
Copy link
Owner

mjskay commented Aug 28, 2023

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

@biosmanager
Copy link

biosmanager commented Aug 28, 2023

@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

mjskay added a commit that referenced this issue Aug 29, 2023
…contrasts can be computed on random slopes models, closes #37
@mjskay
Copy link
Owner

mjskay commented Aug 29, 2023

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.

@biosmanager
Copy link

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 ;)

@mjskay
Copy link
Owner

mjskay commented Aug 29, 2023

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
Copy link
Owner

mjskay commented Aug 29, 2023

(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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants