R卡方事后检验

4

我对R(以及统计学)是新手,因此对于可能是非常基础的问题提前道歉,但我将非常感激任何帮助!

我正在尝试评估在给定车道上开始赛车与其他车道相比是否存在统计优势。

我拥有的样本量很小,不一定符合正态分布,因此我选择使用卡方检验来检查预期胜利与观察到的胜利之间的显着差异。

#create lanes var
lane_num <- c(1:10)

#num wins per lane
num_wins <- c(8, 7, 10, 7, 6, 3, 6, 4, 1, 0)

#create df
df <- as.data.frame(cbind(lane_num, num_wins))

#convert lanes_num factor
df$lane_num <- as.factor(df$lane_num)

#check str
str(df)

#run chisq
chi_res <- chisq.test(df$num_wins)

#check results
chi_res

#check for sig diff between lanes
chisq.post.hoc(df) #this is where i'm having issues

chisq.test的结果表明,预期值与观察值之间存在显著差异;

    Chi-squared test for given probabilities

data:  df$num_wins
X-squared = 17.231, df = 9, p-value = 0.04522

我遇到困难的地方是在运行事后检验时,需要比较各个车道之间的差异,以确定哪些车道更有优势。

仅仅运行以下命令:

chisq.post.hoc(df)

返回以下错误:

Error in test(tbl[prs[, i], ], ...) : 
all entries of 'x' must be nonnegative and finite

正如我所说,我对R和统计学都很陌生,因此提供的关于chisq.post.hoc的文档对我来说并不是很清晰易懂 - 而且似乎该软件包已经不再得到支持了,因此我必须下载存档版本。我尝试了各种方法,但都出现了错误。例如:

chisq.post.hoc(df$num_wins, control = "bonferroni")
> Error in 1:nrow(tbl) : argument of length 0

我真的很希望你能给我指点一下,或者提供任何关于我可以使用的替代事后检验以及如何在运行前结构化数据的建议。

先谢谢了!

1个回答

1
这是因为您不应该使用 data.frame,而应该使用 table。由于 fifer 不再受支持,我无法安装它,因此这里提供了一个使用 RVAideMemoire 的解决方案:
race <- matrix(c(8, 7, 10, 7, 6, 3, 6, 4, 1, 0),ncol=10)
colnames(race) <- c(1:10)
race<-as.table(race)
race

#run chisq
chi_res <- chisq.test(race)

#check results
chi_res
library(RVAideMemoire)
chisq.multcomp(race, p.method = "none")

输出:

> chi_res

    Chi-squared test for given probabilities

data:  race
X-squared = 17.231, df = 9, p-value = 0.04522

> chisq.multcomp(race, p.method = "none")

    Pairwise comparisons using chi-squared tests 

data:  race 

   0      1      3      4      6      6      7      7      8     
1  0.3173 -      -      -      -      -      -      -      -     
3  0.0833 0.3173 -      -      -      -      -      -      -     
4  0.0455 0.1797 0.7055 -      -      -      -      -      -     
6  0.0143 0.0588 0.3173 0.5271 -      -      -      -      -     
6  0.0143 0.0588 0.3173 0.5271 1.0000 -      -      -      -     
7  0.0082 0.0339 0.2059 0.3657 0.7815 0.7815 -      -      -     
7  0.0082 0.0339 0.2059 0.3657 0.7815 0.7815 1.0000 -      -     
8  0.0047 0.0196 0.1317 0.2482 0.5930 0.5930 0.7963 0.7963 -     
10 0.0016 0.0067 0.0522 0.1088 0.3173 0.3173 0.4669 0.4669 0.6374

P value adjustment method: none 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接