rancova

R WRS ancova function: Error in if (nuhat < 2) stop("The degrees of freedom must be greater than or equal to 2")


I want to run a robust ANCOVA from the WRS2 package (https://rdrr.io/cran/WRS2/man/ancova.html). 'ratio' is my DV, 'bait' the predictor and 'session' the covariate.

I use the following function:

ancova_model = ancova(ratio ~ bait + session, data = training_data)

And here is my dataset:

enter image description here

However, I get the following error message:

Error in if (nuhat < 2) stop("The degrees of freedom must be greater than or equal to 2") : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In min(sub[vecn >= 12]) : no non-missing arguments to min; returning Inf 2: In max(sub[vecn >= 12]) : no non-missing arguments to max; returning -Inf

Any ideas what I'm doing wrong?


Solution

  • The issue is that the robust ANCOVA determines 5 points of the covariate and than on each point performs a yuen's t-test for independent groups. Consequently, I suspect that in such a small sample where the covariate has the exact same values for both groups it can happen that you end up with one observation for each group at each of these points (hence df < 2). With just one observation for each group the t-test cannot be computed and hence the error.

    A way to deal with this is that you can try to change the number and type of points of the covariate at which the group comparisons are measured like this: ancova(ratio ~ bait + session, data = training_data, pts = c(5,10)). This could give you a result but will probably also throw out warning messages that the tests have been conducted with too few observations which would mean that you can't really trust the outcome.

    In my opinion the covariate does not make much sense anyway. If I am not mistaken it just shows that the two groups (fruit and bunny) have been recorded during the same session. Thus these groups might be in fact dependent. You could do instead the dependent yuen's t-test with the function yuend.