I want to do "One-sample test for proportion" with Python. I found this document one sample proportion ztest example but I don't understand how to use it. For example, what are count and nobs. In the 2 examples, example1 gives single number for count and nobs, however, example2 gives 2 numbers.
For result, I'd like to know the p-value that the event happen rate is higher than 60%
Example1
>>> count = 5
>>> nobs = 83
>>> value = .05
>>> stat, pval = proportions_ztest(count, nobs, value)
>>> print('{0:0.3f}'.format(pval))
0.695
Run Code Online (Sandbox Code Playgroud)
Example2
>>> import numpy as np
>>> from statsmodels.stats.proportion import proportions_ztest
>>> count = np.array([5, 12])
>>> nobs = np.array([83, 99])
>>> stat, pval = proportions_ztest(counts, nobs)
>>> print('{0:0.3f}'.format(pval))
0.159
Run Code Online (Sandbox Code Playgroud)
My data looks like this
Yes No
1 0
1 0
1 0
0 1
0 1
1 0
1 0
0 1
0 1
0 1
0 1
0 1
Run Code Online (Sandbox Code Playgroud)
Can you help explain how to use it and give some examples?
Thank you!
小智 5
In case of example 1:
nobs is the total number of trials, i.e. the number of rows in your list.
count是成功试验的数量,即Yes您列表中的事件数量。
value是要测试的比例,即0.6基于您的问题文本。
这里的零假设是这些值给出的单个样本是从比例等于指定 的分布中抽取的value。
在示例 2 的情况下:
有两个独立的样本,nobs和count向量的第一个条目代表第一个样本,第二个代表第二个样本。value然后省略,原假设将是两个样本具有相等的真实比例。
| 归档时间: |
|
| 查看次数: |
5127 次 |
| 最近记录: |