错误代码:手动刻度值不足
Posted
技术标签:
【中文标题】错误代码:手动刻度值不足【英文标题】:Error code: insufficient values in manual scale 【发布时间】:2021-08-19 02:26:25 【问题描述】:我正在尝试使用以下代码运行假设检验:
library(statsr)
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.
这是什么意思?我该如何解决?
【问题讨论】:
【参考方案1】:该函数在绘制输出图形时引起错误;期望为两种结果使用两种颜色,但结果不止两种。可以通过将参数show_eda_plot
和show_inf_plot
设置为FALSE
来抑制图形。
但是错误是因为您选择的方法只期望响应变量中有两个结果,但有两个以上。
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
如果您重新编码响应变量,以便只有两个唯一值,则函数将按预期运行。或者,选择其他方法来分析您的数据。
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")
【讨论】:
以上是关于错误代码:手动刻度值不足的主要内容,如果未能解决你的问题,请参考以下文章