@@ -16,25 +16,82 @@ PyStatPower 是一个专注于统计领域功效分析的开源的 Python 库。
1616
1717[ 详细文档] ( https://pystatpower.github.io/PyStatPower-Docs )
1818
19+ > [ !WARNING]
20+ > 本项目处于 alpha 阶段,文档尚未完成。
21+
1922## 安装
2023
2124``` cmd
2225pip install pystatpower
2326```
2427
25- ## 使用
28+ ## 示例
29+
30+ ### 计算样本量
31+
32+ #### 单组样本率检验
33+
34+ ``` python
35+ from pystatpower.models import one_proportion
36+
37+ result = one_proportion.solve_for_sample_size(
38+ alpha = 0.05 , power = 0.80 , nullproportion = 0.80 , proportion = 0.95 , alternative = " two_sided" , test_type = " exact_test"
39+ )
40+ print (result)
41+ ```
42+
43+ 输出:
44+
45+ ``` python
46+ Size(41.59499160228066 )
47+ ```
48+
49+ #### 两独立样本率差异性检验
50+
51+ ``` python
52+ from pystatpower.models import two_proportion
53+
54+ result = two_proportion.solve_for_sample_size(
55+ alpha = 0.05 ,
56+ power = 0.80 ,
57+ treatment_proportion = 0.95 ,
58+ reference_proportion = 0.80 ,
59+ alternative = " two_sided" ,
60+ test_type = " z_test_pooled" ,
61+ )
62+ print (result)
63+ ```
64+
65+ 输出:
66+
67+ ``` python
68+ (Size(75.11862332120842 ), Size(75.11862332120842 ))
69+ ```
70+
71+ ### 计算检验效能
2672
2773``` python
28- from pystatpower.procedures import ospp
74+ from pystatpower.models.two_proportion import *
2975
30- result = ospp.solve(n = None , alpha = 0.05 , power = 0.80 , nullproportion = 0.80 , proportion = 0.95 )
76+ result = solve_for_power(
77+ alpha = 0.05 ,
78+ treatment_proportion = 0.95 ,
79+ reference_proportion = 0.80 ,
80+ alternative = " two_sided" ,
81+ test_type = " z_test_pooled" ,
82+ group_allocation = GroupAllocation.ForPower(
83+ GroupAllocationOption.SIZE_OF_TREATMENT | GroupAllocationOption.SIZE_OF_REFERENCE ,
84+ size_of_treatment = 100 ,
85+ size_of_reference = 50 ,
86+ ),
87+ )
3188print (result)
3289```
3390
3491输出:
3592
3693``` python
37- 41.594991602280594
94+ Power( 0.7865318578853373 )
3895```
3996
4097## 鸣谢
0 commit comments