2

I am trying to run a hypothesis test using the following code:

library(statsr)
inference(x= sex, y = natheal, data = dataset, 
    statistic = "proportion", type = "ht", 
    method = "theoretical", alternative = "greater", 
    success = "Too Much")

But I keep getting this error:

Error: Insufficient values in manual scale. 3 needed but only 2 provided.

What does this mean? How can I fix it?

CSJCampbell
  • 2,025
  • 15
  • 19

1 Answers1

0

The error is caused when the function plots the output graphic; is expecting to use two colours for two outcomes, but there are more than two outcomes. The graphics can be suppressed by setting arguments show_eda_plot and show_inf_plot to FALSE.

However the error is because the method you have selected is expecting only two outcomes in your response variable, but there are more than two.

library(statsr)
dataset <- data.frame(
    sex = c(0, 0, 1, 1), 
    natheal = c("Not Enough", "Just Right", "Too Much", "Not Enough"))
inference(x = sex, y = natheal, 
    data = dataset, 
    statistic = "proportion", 
    type = "ht", 
    method = "theoretical", 
    alternative = "greater", 
    success = "Too Much")
# Error: Insufficient values in manual scale. 3 needed but only 2 provided.

unique(dataset$natheal)
# [1] Not Enough Just Right Too Much  
# Levels: Just Right Not Enough Too Much

If you recode your response variable so that there are only two unique values, the function will behave as expected. Alternatively, choose a different method to analyse your data.

dataset2 <- data.frame(
    sex = c(0, 0, 1, 1), 
    natheal = c("Not Enough", "Not Enough", "Too Much", "Not Enough"))
inference(x = sex, y = natheal, 
    data = dataset2, 
    statistic = "proportion", 
    type = "ht", 
    method = "theoretical", 
    alternative = "greater", 
    success = "Too Much")

two panel plot showing barplot of sample distribution on left and null distribution on right

CSJCampbell
  • 2,025
  • 15
  • 19