Closed dominic007 closed 1 year ago
Confirrmed; thanks for the reproducible example. It looks like this has to do with the fact that you've not dropped the factor levels, there are six factor levels (some of which have 0 observations). Hence, it cannot do a t test. Try this:
ttest = ttestBF(formula=count~spray, data=InsectSprays[InsectSprays$spray %in% c("C","B"),] |> droplevels())
(note the use of droplevels()
). That will remake the factor so that it only has two levels, C
and B
. Ideally, this would give a different warning, like "Indep. groups t test requires a factor with exactly 2 levels."
For my future reference, the correct error is not being emitted because the line:
(re)makes the factor before checking the number of levels, hence the unused levels will be dropped. This line should be changed so that it only remakes it if it is not already a factor.
Following is the code:
ttest= ttestBF(formula=count~spray, data=InsectSprays[InsectSprays$spray %in% c("C","B"),])
InsectSprays is inbuilt R data. I get the following error:
I notice that when I change the subsetting operation from
c("C","B")
toc("C","A")
there is an output. strange thing is that both the cases give similar dataframes (with 24 observations each)