ANOVA (Error in Levels (x) [x]: Only 0's may be mixed w/ neg. subscripts)

I keep receiving the following error when attempting to perform the ANOVA test on 1 continuous and 1 categorical variable in a very large dataset (n= greater than 50,000). The independent variable is drop in insulin level (4 levels) and the dependent variable is number of medications prescribed.

Error in levels(x)[x] : only 0's may be mixed with negative subscripts

I used the following command:

aov.out = aov(num_medications ~ insulin, data=diabetic_data)
summary(aov.out)

Can any of you tell me why this is happening? As far as I'm concerned, there are no negative values in this data set.

Thank you

Can you please provide a REPRoducible EXample of your problem? It provides more specifics of your problem, and it helps others to understand what problem you are facing. If you don't know how to do it, take a look at this thread.

Along with a reprex, please share a small part of the data set in a copy-paste friendly format.

In case you don't know how to do it, there are many options, which include:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.