我是靠谱客的博主 平淡大门,最近开发中收集的这篇文章主要介绍python做meta分析_Python PythonMeta包_程序模块 - PyPI - Python中文网,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

importPythonMetaasPMAdefshowstudies(studies,dtype):#show continuous dataifdtype.upper()=="CONT":text="%-10s%-30s%-30sn"%("Study ID","Experiment Group","Control Group")text+="%-10s%-10s%-10s%-10s%-10s%-10s%-10sn"%(" ","m1","sd1","n1","m2","sd2","n2")foriinrange(len(studies)):text+="%-10s%-10s%-10s%-10s%-10s%-10s%-10sn"%(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%-20sn"%("Study ID","Experiment Group","Control Group")text+="%-10s%-10s%-10s%-10s%-10sn"%(" ","e1","n1","e2","n2")foriinrange(len(studies)):text+="%-10s%-10s%-10s%-10s%-10sn"%(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.2fn"%(# 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]%6dn"%(# 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+="%dstudies included (N=%d)n"%(len(rults)-1,rults[0][5])text+="Heterogeneity: Tauu00b2=%.3f"%(rults[0][12])ifnotrults[0][12]==Noneelse"Heterogeneity: "text+="Q(Chisquare)=%.2f(p=%s); Iu00b2=%sn"%(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=%sn"%(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","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","name=medium term","#"," ","#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 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)

最后

以上就是平淡大门为你收集整理的python做meta分析_Python PythonMeta包_程序模块 - PyPI - Python中文网的全部内容,希望文章能够帮你解决python做meta分析_Python PythonMeta包_程序模块 - PyPI - Python中文网所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部