Supplement 2. Python and WinBUGS model code for simulation study.
收藏资源简介:
File List bugs_sim.py -- Python code to simulate data for input into WINBUGS. Program calls WINBUGS in a DOS command and sends summary output to a storage file. def_sim.py -- Python code (called by bugs_sim.py) specifying input parameters for simulations. oarunscript.txt -- WINBUGS script file for batch execution. oa_model.txt -- WINBUGS model file for batch execution. oa_data.txt -- WINBUGS data file (replaced at each simulation iteration). oa_inits.txt -- WINBUGS initial parameter value file (replaced at each simulation iteration). Description To execute program in WINDOWS operating systems, place all files in /Program Files/ WINBUGS14 and open the file "bugs_sim.py". This file references the "def_sim.py" and simulates data and initial values, replacing oa_data.txt and oa_intis.txt. The program then executes WINBUGS as a DOS command, with parameters contained in "oa_runscript.txt", using the simulated model specified in "oa_model.txt" and current data and initial values. Summary output is sent to two comma-delimited files: "sim_params.csv" and "sim_summary.csv", which keep track of parameter values and model estimates, respectively, for each simulation, and from which estimator performance (e.g., bias, MSE, and interval coverage) can be evaluated. Note: Execution of "bugs_sim.py" and "def_sim.py" requires installation of Python; we recommend ActiveState ActivePython 2.5 (http://www.activestate.com), and numpy numeric Python (http://www.scipy.org/Download). Installation of pymc (http://pymc.googlecode.com/files/pymc-2.0.win32-py2.5.exe) is required to access the likelihood objects in "bugs_sim.py"; alternatively users may code their own likelihood functions directly in Python.
文件列表 bugs_sim.py:用于为WINBUGS生成输入数据的Python代码,该程序会在DOS命令行中调用WINBUGS,并将汇总输出保存至存储文件。 def_sim.py:由bugs_sim.py调用的Python代码,用于指定模拟的输入参数。 oarunscript.txt:用于批量执行的WINBUGS脚本文件。 oa_model.txt:用于批量执行的WINBUGS模型文件。 oa_data.txt:WINBUGS数据文件(每次模拟迭代时均会被覆盖)。 oa_inits.txt:WINBUGS初始参数值文件(每次模拟迭代时均会被覆盖)。 描述 在Windows操作系统中运行该程序时,请将所有文件放置于/Program Files/WINBUGS14目录下,随后运行"bugs_sim.py"文件。该文件将调用"def_sim.py",模拟数据与初始参数值,并覆盖oa_data.txt与oa_inits.txt。随后程序将以DOS命令形式执行WINBUGS,调用"oa_runscript.txt"中包含的参数,使用"oa_model.txt"中指定的模拟模型以及当前的数据与初始参数值。程序的汇总输出将被写入两个以逗号分隔的文件:"sim_params.csv"与"sim_summary.csv",二者分别记录每次模拟的参数值与模型估计结果,可用于评估估计器的性能(例如偏差、均方误差(Mean Squared Error)与区间覆盖率)。 注意事项 注意:运行"bugs_sim.py"与"def_sim.py"需要安装Python;我们推荐使用ActiveState ActivePython 2.5(下载链接:http://www.activestate.com)与Python数值计算库numpy(下载链接:http://www.scipy.org/Download)。若要调用"bugs_sim.py"中的似然对象,则需要安装pymc库(下载链接:http://pymc.googlecode.com/files/pymc-2.0.win32-py2.5.exe);用户也可以直接在Python中自行编写似然函数。




