元分析的python模块,通常用于循证医学的系统综述。
PythonMeta的Python项目详细描述
蟒蛇
信息
名称=蟒蛇
版本=1.11
作者=邓宏勇(DHY)
电子邮件=dephew@126.com
url=www.pymeta.com
日期=2019.7.23(2017年首次开发)
关于
这是一个元分析包。
本模块旨在执行一些循证医学(EBM)任务,例如:
- 组合效应度量(或,rr,rd表示计数数据,md,smd表示连续数据);
- 异质性检验(q/chi-square检验);
- 子群分析;
- 绘图:森林图、漏斗图等。
本软件中的统计算法引用自: Jonathan J Deeks和Julian PT Higgins,代表Cochrane协作统计方法组。Review Manager中的统计算法,2010年8月5日。
请在任何广告中引用我的名字,比如:
邓洪永。pymeta,元分析的python模块,引用20xx xx xx xx(或您的时间);1个屏幕。可从以下网址获得:http://www.pymeta.com
这是一个正在进行的项目,因此,欢迎您提出任何问题和建议。 使用pip安装和更新
在代码中导入pythonmeta模块: pythonmeta包中有四个函数/类: help()(函数):显示pythonmeta的帮助信息。 data()(类):设置并加载要分析的数据。 meta()(类):设置并执行元分析。 fig()(类):设置并绘制结果图。 示例代码:sample.py 或者可以从文件中加载数据,例如: 以下是数据文件的一些示例:
(请记住所有以开头的行都是注释行,加载时将忽略这些注释行。) 连续数据样本
二分法数据样本
具有子组的数据样本 邓红勇博士 上海中医药大学 中国上海,201203 电子邮件:dephew@126.com
网址:www.pymeta.com
安装
pip install PythonMeta
导入
import PythonMeta
函数和类
示例
importPythonMetaasPMAdefshowstudies(studies,dtype):#show continuous dataifdtype.upper()=="CONT":text="%-10s%-30s%-30s\n"%("Study ID","Experiment Group","Control Group")text+="%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n"%(" ","m1","sd1","n1","m2","sd2","n2")foriinrange(len(studies)):text+="%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n"%(studies[i][6],#study IDstr(studies[i][0]),#mean of group1str(studies[i][1]),#SD of group1str(studies[i][2]),#total num of group1str(studies[i][3]),#mean of group2str(studies[i][4]),#SD of group2str(studies[i][5])#total num of group2)returntext#show dichotomous datatext="%-10s%-20s%-20s\n"%("Study ID","Experiment Group","Control Group")text+="%-10s%-10s%-10s%-10s%-10s\n"%(" ","e1","n1","e2","n2")foriinrange(len(studies)):text+="%-10s%-10s%-10s%-10s%-10s\n"%(studies[i][4],#study IDstr(studies[i][0]),#event num of group1str(studies[i][1]),#total num of group1str(studies[i][2]),#event num of group2str(studies[i][3])#total num of group2)returntextdefshowresults(rults):text="%-10s%-6s%-18s%-10s"%("Study ID","n","ES[95% CI]","Weight(%)\n")foriinrange(1,len(rults)):text+="%-10s%-6d%-4.2f[%.2f%.2f] %6.2f\n"%(# for each studyrults[i][0],#study IDrults[i][5],#total numrults[i][1],#effect sizerults[i][3],#lower of CIrults[i][4],#higher of CI100*(rults[i][2]/rults[0][2])#weight)text+="%-10s%-6d%-4.2f[%.2f%.2f] %6d\n"%(# for total effectrults[0][0],#total effect size namerults[0][5],#total N (all studies)rults[0][1],#total effect sizerults[0][3],#total lower CIrults[0][4],#total higher CI100)text+="%d studies included (N=%d)\n"%(len(rults)-1,rults[0][5])text+="Heterogeneity: Tau\u00b2=%.3f "%(rults[0][12])ifnotrults[0][12]==Noneelse"Heterogeneity: "text+="Q(Chisquare)=%.2f(p=%s); I\u00b2=%s\n"%(rults[0][7],#Q test valuerults[0][8],#p value for Q teststr(round(rults[0][9],2))+"%")#I-square valuetext+="Overall effect test: z=%.2f, p=%s\n"%(rults[0][10],rults[0][11])#z-test value and p-valuereturntextdefmain(stys,settings):d=PMA.Data()#Load Data classm=PMA.Meta()#Load Meta classf=PMA.Fig()#Load Fig class#You should always tell the datatype first!!!d.datatype=settings["datatype"]#set data type, 'CATE' for binary data or 'CONT' for continuous datastudies=d.getdata(stys)#load data#studies = d.getdata(d.readfile("studies.txt")) #get data from a data file, see examples of data filesprint(showstudies(studies,d.datatype))#show studiesm.datatype=d.datatype#set data type for meta-analysis calculatingm.models=settings["models"]#set effect models: 'Fixed' or 'Random'm.algorithm=settings["algorithm"]#set algorithm, based on datatype and effect sizem.effect=settings["effect"]#set effect size:RR/OR/RD for binary data; SMD/MD for continuous dataresults=m.meta(studies)#performing the analysisprint(m.models+" "+m.algorithm+" "+m.effect)print(showresults(results))#show results tablef.forest(results).show()#show forest plotf.funnel(results).show()#show funnel plotif__name__=='__main__':samp_cate=[#this array can be stored into a data file by lines, and loaded with d.readfile("filename")"Fang 2015,15,40,24,37","Gong 2012,10,40,18,35","Liu 2015,30,50,40,50","Long 2012,19,40,26,40","Wang 2003,7,86,15,86","<subgroup>name=short term","Chen 2008,20,60,28,60","Guo 2014,31,51,41,51","Li 2015,29,61,31,60","Yang 2006,21,40,31,40","Zhao 2012,27,40,30,40","<subgroup>name=medium term","#<nototal>"," ","#This is a sample of binary data with subgroup.","#Syntax: study name, e1, n1, e2, n2","#e1,n1: events and number of experiment group;","#e2,n2: events and number of control group.","#And you can add a line of <nototal> to hide the Overall result."]samp_cont=[#this array can be stored into a data file by lines, and loaded with d.readfile("filename")"Atmaca 2005, 20.9, 6.0, 15, 27.4, 8.5, 14","Guo 2014, 12.8, 5.2, 51, 11.9, 5.3, 51","Liu 2010, 23.38, 5.86, 35, 24.32, 5.43, 35","Wang 2012, 15.67, 8.78, 43, 18.67, 9.87, 43","Xu 2002, 15.49, 7.16, 50, 21.72, 8.07, 50","Zhao 2012, 12.8, 5.7, 40, 13.0, 5.2, 40"," ","#This is a sample of continuous data.","#Input one study in a line;","#Syntax: study name, m1, sd1, n1, m2, sd2, n2","#m1, sd1, n1: mean, SD and number of experiment group;","#m2, sd2, n2: mean, SD and number of control group."]#sample 1: dichotomous datasettings={"datatype":"CATE",#for CATEgorical/count/binary/dichotomous data"models":"Fixed",#models: Fixed or Random"algorithm":"MH",#algorithm: MH, Peto or IV"effect":"RR"}#effect size: RR, OR, RDmain(samp_cate,settings)#sample 2: continuous datasettings={"datatype":"CONT",#for CONTinuous data"models":"Fixed",#models: Fixed or Random"algorithm":"IV",#algorithm: IV"effect":"MD"}#effect size: MD, SMDmain(samp_cont,settings)
studies = d.getdata(d.readfile("studies.txt")
Atmaca 2005, 20.9, 6.0, 15, 27.4, 8.5, 14
Guo 2014, 12.8, 5.2, 51, 11.9, 5.3, 51
Liu 2010, 23.38, 5.86, 35, 24.32, 5.43, 35
Wang 2012, 15.67, 8.78, 43, 18.67, 9.87, 43
Xu 2002, 15.49, 7.16, 50, 21.72, 8.07, 50
Zhao 2012, 12.8, 5.7, 40, 13.0, 5.2, 40
#This is a sample of continuous data.
#Input one study in a line;
#Syntax: study name, m1, sd1, n1, m2, sd2, n2
#m1, sd1, n1: mean, SD and number of experiment group;
#m2, sd2, n2: mean, SD and number of control group.
Fang 2015, 15, 40, 24, 37
Gong 2012, 10, 40, 18, 35
Liu 2015, 30, 50, 40, 50
Long 2012, 19, 40, 26, 40
Pan 2015a, 57, 100, 68, 100
Wang 2001, 13, 18, 17, 18
Wang 2003, 7, 86, 15, 86
#This is a sample of binary data.
#Input one study in a line;
#Syntax: study name, e1, n1, e2, n2
#e1,n1: events and number of experiment group;
#e2,n2: events and number of control group.
Fang 2015,15,40,24,37
Gong 2012,10,40,18,35
Liu 2015,30,50,40,50
Long 2012,19,40,26,40
Wang 2003,7,86,15,86
<subgroup>name=short term
Chen 2008,20,60,28,60
Guo 2014,31,51,41,51
Li 2015,29,61,31,60
Yang 2006,21,40,31,40
Zhao 2012,27,40,30,40
<subgroup>name=medium term
#<nototal>
#This is a sample of subgroup.
#Cumulative meta-analysis and Senstivity analysis will blind to all <subgroup> tags.
#And you can add a line of <nototal> to hide the Overall result.
联系人
推荐PyPI第三方库