- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
作为一名普通的 R 用户,我正在学习使用 python 进行分析,我从卡方开始并执行了以下操作:
> chisq.test(matrix(c(10,20,30,40),nrow = 2))$p.value # test1
[1] 0.5040359
> chisq.test(matrix(c(1,2,3,4),nrow = 2))$p.value # test2
[1] 1
Warning message:
In chisq.test(matrix(c(1, 2, 3, 4), nrow = 2)) :
Chi-squared approximation may be incorrect
> chisq.test(matrix(c(1,2,3,4),nrow = 2),correct = FALSE)$p.value # test3
[1] 0.7781597
Warning message:
In chisq.test(matrix(c(1, 2, 3, 4), nrow = 2), correct = FALSE) :
Chi-squared approximation may be incorrect
In [31]:
temp = scipy.stats.chi2_contingency(np.array([[10, 20], [30, 40]])) # test1
temp[1] # pvalue
Out[31]:
0.50403586645250464
In [30]:
temp = scipy.stats.chi2_contingency(np.array([[1, 2], [3, 4]])) # test2
temp[1] # pvalue
Out[30]:
0.67260381744151676
对于 test1
,我很满意,因为 python 和 R 的测试结果相似,但是 test2
不是这样,因为 R 有参数 correct
,所以我把它改成默认的,生成的p值不一样。
我的代码有什么问题吗?我应该“相信”哪一个?
感谢您的反馈。我知道卡方检验不应该用于值小于 5 的单元格,我应该改用 fisher 精确检验,我担心的是为什么 R 和 Python 给出的 p 值差异如此之大。
最佳答案
除了单元格计数 < 5 的问题,根据我的经验,统计测试的 R 和 Python 实现通常默认启用各种更正(应该改进基本方法)。关闭校正似乎使 scipy
p 值与 R 匹配:
scipy.stats.chi2_contingency(np.array([[1, 2], [3, 4]]), correction=False)
Out[6]:
# p-val = 0.778159
(0.079365079365079388, 0.77815968617616582, 1, array([[ 1.2, 1.8],
[ 2.8, 4.2]]))
这同样适用于 t 检验等,默认情况下可能会或可能不会假设方差相等。基本上每当您在统计数据之间匹配输出时遇到问题软件,开始查看默认参数,看看您是否应该启用或禁用这些调整。
关于python - python和R中卡方检验的不同p值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25028833/
这是我第一次提问,对于任何格式问题或任何让我难以回答的问题,我深表歉意。请让我知道我需要添加什么才能回答问题。 我正在尝试比较 2 个不相等的组大小(一个 ~ 97,另一个 ~ 714)之间的差异。差
这个问题在这里已经有了答案: dplyr summarize across ttest (1 个回答) 关闭 5 个月前。 我有这样的数据框 X1 X2 X3 X4 X5 class 1 1
我正在尝试对数据框中的两个数据子集运行 wilcox.test()。它们的长度不相等(48 对 260)。我想看看活橡树和水橡树的 dbh(胸高直径)是否存在差异。 Pine_stand 并收到该错
我有一个带有两个级别的因子列和许多数字列的数据框。我想按因子列拆分数据帧并对列对进行 t 检验。 使用示例数据集 Puromycin 我希望结果看起来像这样: Variable Treated
我尝试对数据框的所有列(一次两列)进行 t 检验,并仅提取 p 值。这是我想出的: for (i in c(5:525) ) { t_test_p.value =sapply( Data[5:525]
我有一个有 11 列数据的 Pandas 。我想通过测试将每一列与其他每一列进行比较(见下文)。如何创建一个循环来自动比较所有列,而无需为每个列对组合手动编写代码? from scipy.stats
我有一些数据,如下所示: # Groups: date [4] date data 1 2021-01-31 2 20
这就是我的数据的样子: > dput(data) structure(list(Name = c("Mark", "Tere", "Marcus", "Heidi", "Georg", "Tieme"
我有一个有 11 列数据的 Pandas 。我想通过测试将每一列与其他每一列进行比较(见下文)。如何创建一个循环来自动比较所有列,而无需为每个列对组合手动编写代码? from scipy.stats
我有一些数据,如下所示: # Groups: date [4] date data 1 2021-01-31 2 20
所以我有一些股票价格数据,我想测试价格是否遵循对数正态分布。我的代码如下: import scipy.stats as stats print(stats.kstest(df['DJIA'], "lo
我想对我的固定效应回归系数进行简单的联合 Wald 检验,但我想将限制设置为非零值。更具体地说,我想测试:H0: ai=0 and b=1 for every i或者基本上,是否从固定效应模型 (ai
我正在尝试进行双样本 t 检验,以检查两个数据集之间的均值是否存在显着差异。 我有两个数据集,每个数据集有 5 个试验,每个试验有 3 个特征。每个 Trial 都有不同的唯一标签,但 3 个特征(X
考虑以下虚拟数据: x <- rnorm(15,mean = 3,sd = 1) y <- rnorm(15,mean = 3,sd = 1) xy <- c(x,y) factor <- c(rep
我是一名计算机科学专业的学生,我正在自学算法类(class)。 在类(class)中我看到了这个问题: Show an efficient randomized algorithm to fact
我想使用拟合我的数据的 f 检验来比较两个模型。对于每个模型,我都执行了蒙特卡洛模拟,为每个模型参数和均方根拟合误差提供了统计估计。我想在 R 中使用 f-test 来确定哪个模型更可取。 最佳答案
我很难让 ks.test 使用卡方分布式数据: > chi10 ks.test(chi10, dchisq, df=10) One-sample Kolmogorov-Smirnov tes
我试图在 R 中复制 SPSS 的线性判别分析输出,但我很难找到执行 m-box 测试的方法。 我唯一找到的是一些发布在论坛上的代码,用于手动实现该过程,但我想知道语言本身是否已经包含用于此目的的任何
我有以下数据框: structure(list(test1 = c(0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1), test2 = c(0, 0, 1, 1, 0,
标准 stats::kruskal.test 模块允许计算数据集上的 kruskal-wallis 测试: >>> data(diamonds) >>> kruskal.test(price~cara
我是一名优秀的程序员,十分优秀!