{"id":15893280,"url":"https://github.com/nunofachada/simoututils","last_synced_at":"2025-04-02T17:41:27.174Z","repository":{"id":74270391,"uuid":"47463586","full_name":"nunofachada/simoututils","owner":"nunofachada","description":"SimOutUtils - Utilities for analyzing time series simulation output","archived":false,"fork":false,"pushed_at":"2017-08-18T18:30:14.000Z","size":399,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T08:15:25.605Z","etag":null,"topics":["distributional-analysis","docking","focal-measures","latex-table","matlab","matlab-toolbox","model-alignment","multiple-comparisons","octave","octave-functions","octave-scripts","output-analysis","plot","simulation","simulation-modeling","simulations","statistical-analysis","statistical-summaries","statistical-tests","timeseries"],"latest_commit_sha":null,"homepage":"","language":"Matlab","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nunofachada.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-12-05T16:36:56.000Z","updated_at":"2022-04-07T12:00:30.000Z","dependencies_parsed_at":"2023-07-12T05:00:09.478Z","dependency_job_id":null,"html_url":"https://github.com/nunofachada/simoututils","commit_stats":{"total_commits":139,"total_committers":3,"mean_commits":"46.333333333333336","dds":0.4532374100719424,"last_synced_commit":"fe4aacd516b2e54beb21296c3fe898c2e745638b"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunofachada%2Fsimoututils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunofachada%2Fsimoututils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunofachada%2Fsimoututils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunofachada%2Fsimoututils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nunofachada","download_url":"https://codeload.github.com/nunofachada/simoututils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246863645,"owners_count":20846291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributional-analysis","docking","focal-measures","latex-table","matlab","matlab-toolbox","model-alignment","multiple-comparisons","octave","octave-functions","octave-scripts","output-analysis","plot","simulation","simulation-modeling","simulations","statistical-analysis","statistical-summaries","statistical-tests","timeseries"],"created_at":"2024-10-06T08:09:39.658Z","updated_at":"2025-04-02T17:41:27.155Z","avatar_url":"https://github.com/nunofachada.png","language":"Matlab","readme":"SimOutUtils - Utilities for analyzing time series simulation output\n===================================================================\n\n1\\.  [What is SimOutUtils?](#whatissimoututils?)  \n2\\.  [File format](#fileformat)  \n3\\.  [How to use the utilities](#howtousetheutilities)  \n4\\.  [Examples](#examples)  \n4.1\\.  [Core functionality](#corefunctionality)  \n4.1.1\\.  [Plot simulation output](#plotsimulationoutput)  \n4.1.2\\.  [Get statistical summaries from one replication](#getstatisticalsummariesfromonereplication)  \n4.1.3\\.  [Get and analyze statistical summaries from multiple replications](#getandanalyzestatisticalsummariesfrommultiplereplications)  \n4.2\\.  [Distributional analysis of output](#distributionalanalysisofoutput)  \n4.2.1\\.  [Distributional analysis tables](#distributionalanalysistables)  \n4.2.2\\.  [Visually analyze the distributional properties of a focal measure](#visuallyanalyzethedistributionalpropertiesofafocalmeasure)  \n4.2.3\\.  [LaTeX table with distributional analysis of all focal measures for one setup](#latextablewithdistributionalanalysisofallfocalmeasuresforonesetup)  \n4.2.4\\.  [LaTeX table with a distributional analysis of one focal measure for multiple setups](#latextablewithadistributionalanalysisofonefocalmeasureformultiplesetups)  \n4.3\\.  [Comparison of model implementations](#comparisonofmodelimplementations)  \n4.3.1\\.  [Compare the outputs of two or more model implementations](#comparetheoutputsoftwoormoremodelimplementations)  \n4.3.2\\.  [Compare focal measures of two model implementations](#comparefocalmeasuresoftwomodelimplementations)  \n4.3.3\\.  [Compare focal measures of multiple model implementations](#comparefocalmeasuresofmultiplemodelimplementations)  \n4.3.4\\.  [Pairwise comparison of model implementations](#pairwisecomparisonofmodelimplementations)  \n4.3.5\\.  [Plot the PDF and CDF of focal measures from one or more model implementations](#plotthepdfandcdfoffocalmeasuresfromoneormoremodelimplementations)  \n4.3.6\\.  [Table with _p_-values from comparison of focal measures from model implementations](#tablewith_p_-valuesfromcomparisonoffocalmeasuresfrommodelimplementations)  \n4.3.7\\.  [Multiple comparisons and comparison names](#multiplecomparisonsandcomparisonnames)  \n4.3.8\\.  [Comparison groups](#comparisongroups)  \n5\\.  [Unit tests](#unittests)  \n6\\.  [License](#license)  \n7\\.  [References](#references)  \n\n\u003ca name=\"whatissimoututils?\"\u003e\u003c/a\u003e\n\n## 1\\. What is SimOutUtils?\n\nA number of [MATLAB]/[Octave] functions for analyzing output data from\nsimulation models, as well as for producing publication quality tables and\nfigures. These utilities were originally developed to analyze the [PPHPC] model,\nand later generalized to be usable with stochastic simulation models with time\nseries-like outputs.\n\nThese utilities are compatible with GNU Octave. However, note that a number of \nstatistical tests provided by Octave return slightly different _p_-values from\nthose returned by the equivalent MATLAB functions.\n\nThe following links list the available functions:\n\n* [Core functions](core)\n* [Distributional analysis of output](dist)\n* [Comparison of model implementations](compare)\n* [Helper functions](helpers)\n* [Third-party functions](3rdparty)\n\nIf you use _SimOutUtils_, please cite reference [\\[1\\]][ref1].\n\n\u003ca name=\"fileformat\"\u003e\u003c/a\u003e\n\n## 2\\. File format\n\nThe functions provided by _SimOutUtils_ use the [dlmread] MATLAB/Octave function\nto open files containing simulation output. As such, these functions expect text\nfiles with numeric values delimited by a separator (automatically inferred by\n[dlmread]). The files should contain data values in tabular format, with one\ncolumn per output and one row per iteration.\n\n\u003ca name=\"howtousetheutilities\"\u003e\u003c/a\u003e\n\n## 3\\. How to use the utilities\n\nClone or download the utilities to any folder. Then, either start \n[MATLAB]/[Octave] directly in this folder, or `cd` into this folder and execute\nthe [startup] script:\n\n```\nstartup\n```\n\n\u003ca name=\"examples\"\u003e\u003c/a\u003e\n\n## 4\\. Examples\n\nThe examples use the following datasets:\n\n1. [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.34053.svg)](http://dx.doi.org/10.5281/zenodo.34053)\n2. [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.34049.svg)](http://dx.doi.org/10.5281/zenodo.34049)\n3. [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.46848.svg)](http://dx.doi.org/10.5281/zenodo.46848)\n\nThese datasets correspond to the results presented in references [\\[2\\]][ref2],\n[\\[3\\]][ref3] and [\\[4\\]][ref4], respectively.\n\nUnpack the datasets to any folder and put the complete path to these folders in\nvariables `datafolder1`, `datafolder2` and `datafolder3`, respectively:\n\n```matlab\ndatafolder1 = 'path/to/dataset1';\ndatafolder2 = 'path/to/dataset2';\ndatafolder3 = 'path/to/dataset3';\n```\n\nThe datasets contain output from several implementations of the [PPHPC]\nagent-based model. [PPHPC] is a realization of prototypical predator-prey\nsystem with six outputs: \n\n1. Sheep population\n2. Wolves population\n3. Quantity of available grass\n4. Mean sheep energy\n5. Mean wolves energy\n6. Mean value of the grass countdown parameter\n\nDataset 1 contains output from the [NetLogo] implementation of [PPHPC]. It is\nused in the [core functionality](#corefunctionality) and\n[distributional analysis of output](#distributionalanalysisofoutput) examples.\nDataset 2 contains output from the NetLogo implementation and from six variants\nof a parallel Java implementation, namely, ST, EQ, EX, ER and OD. These\nimplementations and variants are *aligned*, i.e., they display the same dynamic\nbehavior. Finally, dataset 3 contains aligned output from the NetLogo and Java\nEX implementations, and also output from two purposefully misaligned versions of\nthe latter. Datasets 2 and 3 are used in the examples concerning the\n[comparison of model implementations](#comparisonofmodelimplementations).\n\nThe datasets were collected under five different model sizes (100 _x_ 100,\n200 _x_ 200, 400 _x_ 400, 800 _x_ 800 and 1600 _x_ 1600) and two distinct\nparameterizations (_v1_ and _v2_).\n\n\u003ca name=\"corefunctionality\"\u003e\u003c/a\u003e\n\n### 4.1\\. Core functionality\n\n\u003ca name=\"plotsimulationoutput\"\u003e\u003c/a\u003e\n\n#### 4.1.1\\. Plot simulation output\n\nUse the [output_plot] function to plot outputs from one replication of the PPHPC\nmodel:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r1.txt', 6);\n```\n\n![simout_ex01_01](https://cloud.githubusercontent.com/assets/3018963/11877081/0209605a-a4e5-11e5-8092-95dfe0bbcd5b.png)\n\nThe third parameter specifies the number of outputs. Alternatively, a cell array\nof strings can be passed in order to display personalized output names.\nFurthermore, outputs 4 to 6 are practically not visible, as they have a very\ndifferent scale from outputs 1 to 3. The 'layout' option defines how many\noutputs to plot per figure, and can be used to solve this problem. As such,\n[output_plot] can be invoked in the following way:\n\n```matlab\noutputs = {'SheepPop', 'WolfPop', 'GrassQty', 'SheepEnergy', 'WolfEnergy', 'GrassEnergy'};\noutput_plot([datafolder1 '/v1'], 'stats100v1r1.txt', outputs, 'layout', [3 3]);\n```\n\n![simout_ex01_02](https://cloud.githubusercontent.com/assets/3018963/11877082/02217ffa-a4e5-11e5-9729-ed5678443c96.png)\n![simout_ex01_021](https://cloud.githubusercontent.com/assets/3018963/12080034/8eabfcf8-b245-11e5-9c28-ad4fc1bbf2fe.png)\n\nThe 'layout' option is one of the several key-value arguments accepted by\n[output_plot]. Another option is the 'Colors' parameter, which specifies the\ncolors used for plotting individual outputs. It can be used, for example, to use\nthe same colors for the outputs in both figures:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r1.txt', outputs, 'layout', [3 3], 'Colors', {'b', 'r', 'g', 'b', 'r', 'g'});\n```\n\n![simout_ex01_02](https://cloud.githubusercontent.com/assets/3018963/11877082/02217ffa-a4e5-11e5-9729-ed5678443c96.png)\n![simout_ex01_03](https://cloud.githubusercontent.com/assets/3018963/11877083/0230e2a6-a4e5-11e5-884f-fc6140e258af.png)\n\nA number of these key-value arguments consist of [LineSpec]s for individual\noutputs ([PatchSpec]s in the case of type **f** plots, discussed further ahead).\nIf there are more outputs than specs in the associated cell array, the given\nspecs are repeated. As such, in the previous command we could have shortened the\ngiven 'Colors' cell array, i.e.:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r1.txt', outputs, 'layout', [3 3], 'Colors', {'b', 'r', 'g'});\n```\n\nThe [output_plot] function recognizes a number of [LineSpec]s and [PatchSpec]s,\nnamely 'Colors', 'LineStyles', 'LineWidths', 'Markers', 'MarkerEdgeColors',\n'MarkerFaceColors' and 'MarkerSizes'. There is also the 'EdgeColors' option,\nwhich is only recognized within the [PatchSpec]s context, i.e. for type **f**\nplots.\n\nReturning to the example, the third and sixth outputs of the last command\n(*GrassQty* and *GrassEnergy*, respectively) are still somewhat out of scale\nwith the remaining outputs. This can be solved by specifying the 'scale' option:\n\n```matlab\noutputs = {'SheepPop', 'WolfPop', 'GrassQty/4', 'SheepEnergy', 'WolfEnergy', '4*GrassEnergy'};\noutput_plot([datafolder1 '/v1'], 'stats100v1r1.txt', outputs, 'layout', [3 3], 'Colors', {'b', 'r', 'g'}, 'scale', [1 1 1/4 1 1 4]);\n```\n\n![simout_ex01_04](https://cloud.githubusercontent.com/assets/3018963/11877084/02356862-a4e5-11e5-8c79-06a85fda0a67.png)\n![simout_ex01_05](https://cloud.githubusercontent.com/assets/3018963/11877085/023607ea-a4e5-11e5-83e2-8807d9927253.png)\n\nThe plot looks good now. In order to plot outputs from multiple replications, we\nsimply use wildcards to load more than one file:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r*.txt', outputs, 'layout', [3 3], 'Colors', {'b', 'r', 'g'}, 'scale', [1 1 1/4 1 1 4]);\n```\n\n![simout_ex01_06](https://cloud.githubusercontent.com/assets/3018963/11877088/023508a4-a4e5-11e5-91d0-1cc2274a3537.png)\n![simout_ex01_07](https://cloud.githubusercontent.com/assets/3018963/11877086/02362194-a4e5-11e5-889d-95f82bd69fac.png)\n\nWhen plotting multiple replications this way, the figures tend to look somewhat\nheavy and are slow to manipulate. We could alternatively plot only the output\nextremes (minimum and maximum of individual outputs at each iteration), and fill\nthe space between with the output color. This can be accomplished by specifying\nthe **f**ill 'type':\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r*.txt', outputs, 'type', 'f', 'layout', [3 3], 'Colors', {'b', 'r', 'g'}, 'scale', [1 1 1/4 1 1 4]);\n```\n\n![simout_ex01_08](https://cloud.githubusercontent.com/assets/3018963/11877087/0238c8b8-a4e5-11e5-9663-bf792e8a289e.png)\n![simout_ex01_09](https://cloud.githubusercontent.com/assets/3018963/11877089/0247e3b6-a4e5-11e5-9be5-aa0b073e185d.png)\n\nFinally, it is also possible to visualize the moving average of each output over\nmultiple replications by passing a positive integer as the 'type' option. This \npositive integer is the window size with which to smooth the output. A value of \nzero is equivalent to no smoothing, i.e. the function will simply plot the \naveraged outputs. A value of 10 offers a good balance between rough and overly \nsmooth plots:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r*.txt', outputs, 'type', 10, 'layout', [3 3], 'Colors', {'b', 'r', 'g'}, 'scale', [1 1 1/4 1 1 4]);\n```\n\n![simout_ex01_10](https://cloud.githubusercontent.com/assets/3018963/11877090/024d2362-a4e5-11e5-908f-533e5dca8d8a.png)\n![simout_ex01_11](https://cloud.githubusercontent.com/assets/3018963/11877091/025138f8-a4e5-11e5-88fb-ffa524459581.png)\n\nThe moving average type of plot is useful for empirically selecting a \nsteady-state truncation point.\n\nThe following command plots only the first 3 outputs in black color, with\ndifferent line styles:\n\n```matlab\noutput_plot([datafolder1 '/v1'], 'stats100v1r*.txt', outputs(1:3), 'type', 10, 'Colors', 'k', 'scale', [1 1 1/4], 'LineStyles', {'-','--',':'});\n```\n\n![simout_ex01_12](https://cloud.githubusercontent.com/assets/3018963/12080126/2982dee2-b249-11e5-8b0a-a55230d2f32a.png)\n\n\nFigures generated with [output_plot] can be converted to LaTeX with the\nexcellent [matlab2tikz] script. For the previous figure, the following commands\nwould perform this conversion, assuming [matlab2tikz] is in [MATLAB]'s path:\n\n```matlab\ncleanfigure();\nmatlab2tikz('standalone', true, 'filename', 'simout_bw.tex');\n```\n\nCompiling the `simout_bw.tex` file with LaTeX would produce the following\nfigure:\n\n![simout_ex01_13](https://cloud.githubusercontent.com/assets/3018963/12067963/73c55840-affb-11e5-840a-74c18d3cad30.png)\n\n\u003ca name=\"getstatisticalsummariesfromonereplication\"\u003e\u003c/a\u003e\n\n#### 4.1.2\\. Get statistical summaries from one replication\n\nThe [stats_get] function is the elementary building block of _SimOutUtils_ for\nanalyzing simulation output. It is indirectly used by most package functions\n(via the higher-level [stats_gather] function). The goal of [stats_get] is to\nextract statistical summaries from simulation outputs from one file. It does\nthis through ancillary `stats_get_*` functions which perform the actual\nextraction. The exact function to use (and consequently, the concrete\nstatistical summaries to extract) is specified in the `simoututils_stats_get_`\nglobal variable, defined in the [startup] script when _SimOutUtils_ is loaded.\n\nThe [stats_get_pphpc] function is the package default. This function returns six\nstatistical summaries, namely the maximum (**max**), iteration where maximum\noccurs (**argmax**), minimum (**min**), iteration where minimum occurs\n(**argmin**), mean (**mean**), and standard deviation (**std**). The **mean**\nand **std** summaries are obtained during the (user-specified) steady-state\nstage of the output. These summaries were selected for the PPHPC model\n[\\[2\\]][ref2], but are appropriate for any model with tendentiously stable\ntime series outputs.\n\nThe following instruction gets the statistical summaries of the first\nreplication of the PPHPC model for size 100 and parameter set 1:\n\n```matlab\nsdata = stats_get(1000, [datafolder1 '/v1/stats100v1r1.txt'], 6)\n```\n\nThe first argument is dependent on the actual `stats_get_*` being used. In this\ncase, we are using the package default [stats_get_pphpc] function, which\nrequires the user to specify the steady-state truncation point (i.e., 1000). The\nlast argument specifies the number of outputs. The function returns a _n_ x _m_\nmatrix of focal measures, with _n_=6 statistical summaries and _m_=6 outputs:\n\n```\nsdata =\n\n   1.0e+03 *\n\n    2.5160    0.5260    8.6390    0.0190    0.0331    0.0035\n    0.1530    3.3130    0.0120    0.0690    0.2550    0.1590\n    0.3050    0.0180    3.6530    0.0045    0.0122    0.0007\n    0.0070    0.0860    0.1590         0    0.0150    0.0100\n    1.1854    0.3880    6.2211    0.0164    0.0244    0.0021\n    0.1211    0.0487    0.2731    0.0007    0.0016    0.0002\n```\n\nIn order to use alternative statistical summaries, the user should specify\nanother function by setting the appropriate function handle in the\n`simoututils_stats_get_` global variable:\n\n```matlab\nsimoututils_stats_get_ = @stats_get_iters;\n```\n\nThe previous instruction configures [stats_get_iters] as the `stats_get_*`\nfunction to use. The statistical summaries fetched by this function are simply\nthe output values at user-specified iterations. Invoking [stats_get] again, the\nfirst argument now specifies the iterations at which to get output values:\n\n```matlab\nsdata = stats_get([10 100 1000], [datafolder1 '/v1/stats100v1r1.txt'], 6)\n```\n\nThe returned _n_ x _m_ matrix of focal measure now has _n_=3 statistical \nsummaries and _m_=6 outputs:\n\n```\nsdata =\n\n   1.0e+03 *\n\n    0.3180    0.2160    8.5940    0.0115    0.0139    0.0007\n    1.9110    0.0240    4.9280    0.0160    0.0246    0.0028\n    1.0060    0.4690    6.6110    0.0170    0.0207    0.0018\n```\n\nTo permanently use another `stats_get_*` function as default, edit the [startup]\nscript and change the value of the `simoututils_stats_get_` global variable as\ndesired. For the remainder of this discussion it is assumed that the\n[stats_get_pphpc] function is being used.\n\n\u003ca name=\"getandanalyzestatisticalsummariesfrommultiplereplications\"\u003e\u003c/a\u003e\n\n#### 4.1.3\\. Get and analyze statistical summaries from multiple replications\n\nThe [stats_gather] function extracts statistical summaries from simulation\noutputs from multiple files. The following instruction obtains statistical\nsummaries for 30 runs of the PPHPC model for size 100 and parameter set 1:\n\n```matlab\ns100v1 = stats_gather('100v1', [datafolder1 '/v1'], 'stats100v1r*.txt', 6, 1000);\n```\n\nThe fourth parameter, 6, corresponds to the number of outputs of the PPHPC\nmodel. Instead of the number of outputs, the function alternatively accepts a\ncell array of strings containing the output names, which can be useful for\ntables and figures. The fifth and last parameter, 1000 , corresponds to the\niteration after which the outputs are in steady-state. The [stats_gather]\nfunction returns a _struct_ with several fields, of which the following are\nimportant to this discussion:\n\n* `name` contains the name with which the data was tagged, '100v1' in this case;\n* `outputs` is a cell array containing the output names (which default to 'o1', \n'o2', etc.); \n* `sdata` is a 30 x 36 matrix, with 30 observations (from 30 files) and 36 focal\nmeasures (six statistical summaries for each of the six outputs).\n\nNext, we analyze the focal measures (i.e., statistical summaries for each\noutput):\n\n```matlab\n[m, v, cit, ciw, sw, sk] = stats_analyze(s100v1.sdata', 0.05);\n```\n\nThe 0.05 value in the second parameter is the significance level for the\nconfidence intervals and the Shapiro-Wilk test. The variables returned by the \n[stats_analyze] function have 36 rows, one per focal measure. The `m` (mean),\n`v` (variance), `sw` (_p_-value of the Shapiro-Wilk test) and `sk` (skewness)\nvariables have only one column, i.e. one value per focal measure, while the\n`cit` (_t_-confidence interval) and `ciw` (Willink confidence interval\n[\\[5\\]][ref5]) variables have two columns, which correspond to the lower and\nupper limits of the respective intervals.\n\n\u003ca name=\"distributionalanalysisofoutput\"\u003e\u003c/a\u003e\n\n### 4.2\\. Distributional analysis of output\n\n\u003ca name=\"distributionalanalysistables\"\u003e\u003c/a\u003e\n\n#### 4.2.1\\. Distributional analysis tables\n\nWhile the data returned by the [stats_analyze] is in a format adequate for\nfurther processing and/or analysis, it is not very human readable. For this\npurpose, we can use the [stats_table_per_setup] function to output an\ninformative plain text table:\n\n```matlab\nstats_table_per_setup(s100v1, 0.05, 0)\n```\n\n```\n-----------------------------------------------------------------------------------------\n|   Output   | Stat.    |    Mean    |  Variance  |    95.0% Conf. interval   | SW test |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o1 |      max |       2517 |       6699 | [       2486,       2547] |  0.8287 |\n|            |   argmax |      145.2 |      91.36 | [      141.7,      148.8] |  0.8255 |\n|            |      min |        317 |      204.9 | [      311.7,      322.3] |  0.8227 |\n|            |   argmin |        6.8 |       6.51 | [      5.847,      7.753] |  0.0326 |\n|            |     mean |       1186 |      65.54 | [       1183,       1189] |  0.9663 |\n|            |      std |      107.9 |      223.9 | [      102.3,      113.5] |  0.3534 |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o2 |      max |      530.5 |      435.8 | [      522.7,      538.3] |  0.0026 |\n|            |   argmax |       2058 |  8.845e+05 | [       1707,       2409] |  0.1654 |\n|            |      min |       19.9 |      58.58 | [      17.04,      22.76] |  0.6423 |\n|            |   argmin |      71.93 |      105.7 | [       68.1,      75.77] |  0.1912 |\n|            |     mean |      390.5 |      6.518 | [      389.5,      391.4] |  0.1380 |\n|            |      std |      44.93 |       25.6 | [      43.04,      46.82] |  0.0737 |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o3 |      max |       8624 |       4097 | [       8600,       8647] |  0.3778 |\n|            |   argmax |       11.7 |     0.2862 | [       11.5,       11.9] |  0.0000 |\n|            |      min |       3745 |   1.66e+04 | [       3697,       3793] |  0.5270 |\n|            |   argmin |      148.2 |      94.14 | [      144.5,      151.8] |  0.6463 |\n|            |     mean |       6216 |      285.7 | [       6210,       6222] |  0.6502 |\n|            |      std |      247.3 |       1128 | [      234.7,      259.8] |  0.0824 |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o4 |      max |      19.74 |     0.5092 | [      19.47,         20] |  0.1594 |\n|            |   argmax |      53.07 |      36.96 | [       50.8,      55.34] |  0.3321 |\n|            |      min |      4.461 |    0.01765 | [      4.412,      4.511] |  0.9519 |\n|            |   argmin |          0 |          0 | [          0,          0] |    NaN |\n|            |     mean |      16.38 |   0.003763 | [      16.36,      16.41] |  0.9614 |\n|            |      std |      0.653 |   0.004133 | [      0.629,      0.677] |  0.4578 |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o5 |      max |      41.86 |      41.39 | [      39.46,      44.26] |  0.0761 |\n|            |   argmax |      135.7 |       1075 | [      123.4,      147.9] |  0.0021 |\n|            |      min |      11.31 |     0.9338 | [      10.95,      11.67] |  0.1280 |\n|            |   argmin |      24.33 |      142.7 | [      19.87,      28.79] |  0.0000 |\n|            |     mean |      24.61 |    0.02589 | [      24.55,      24.67] |  0.6280 |\n|            |      std |      1.673 |    0.01815 | [      1.623,      1.723] |  0.0457 |\n|------------|----------|------------|------------|---------------------------|---------|\n|         o6 |      max |      3.455 |   0.005314 | [      3.428,      3.482] |  0.5257 |\n|            |   argmax |      148.9 |      109.8 | [        145,      152.8] |  0.5714 |\n|            |      min |     0.7595 |   0.001429 | [     0.7454,     0.7736] |  0.2921 |\n|            |   argmin |      10.33 |     0.2989 | [      10.13,      10.54] |  0.0000 |\n|            |     mean |      2.081 |  8.627e-05 | [      2.078,      2.085] |  0.6190 |\n|            |      std |     0.1371 |  0.0003382 | [     0.1302,      0.144] |  0.0794 |\n-----------------------------------------------------------------------------------------\n```\n\nThe last parameter, 0, specifies plain text output. This function can also \noutput a publication quality LaTeX table by setting the last argument to 1:\n\n```matlab\nstats_table_per_setup(s100v1, 0.05, 1)\n```\n\n![simout_ex03](https://cloud.githubusercontent.com/assets/3018963/11901414/689d8b34-a5a3-11e5-803a-e5fc0688d09d.png)\n\nThe produced LaTeX table requires the [siunitx], [multirow], [booktabs] and\n[ulem] packages to compile.\n\n\u003ca name=\"visuallyanalyzethedistributionalpropertiesofafocalmeasure\"\u003e\u003c/a\u003e\n\n#### 4.2.2\\. Visually analyze the distributional properties of a focal measure\n\nThe [dist_plot_per_fm] function offers a simple way of assessing the\ndistributional properties of a focal measure for different model configurations\n(i.e., different model sizes, different parameter set, etc). For each\nconfiguration the function shows an approximate probability density function\n(PDF), a histogram, and a QQ-plot. The [dist_plot_per_fm] function works with\nthe data returned by [stats_gather].\n\nFor example, let us assess the distributional properties of the PPHPC focal\nmeasure given by the **argmin** of the _grass quantity_ output for parameter set\n2 and a number of different model sizes:\n\n```matlab\n% Get statistical summaries for different model sizes, parameter set 2\noutputs = {'SheepPop', 'WolfPop', 'GrassQty', 'SheepEn', 'WolfEn', 'GrassEn'};\ns100v2 = stats_gather('100v2', [datafolder1 '/v2'], 'stats100v2r*.txt', outputs, 2000);\ns200v2 = stats_gather('200v2', [datafolder1 '/v2'], 'stats200v2r*.txt', outputs, 2000);\ns400v2 = stats_gather('400v2', [datafolder1 '/v2'], 'stats400v2r*.txt', outputs, 2000);\ns800v2 = stats_gather('800v2', [datafolder1 '/v2'], 'stats800v2r*.txt', outputs, 2000);\ns1600v2 = stats_gather('1600v2', [datafolder1 '/v2'], 'stats1600v2r*.txt', outputs, 2000);\n\n% Group them into a cell array\nsv2 = {s100v2, s200v2, s400v2, s800v2, s1600v2};\n```\n\nThe **argmin** of the *grass quantity* output is the third statistical summary\nof the fourth output, as indicated in the second and third arguments of\n[dist_plot_per_fm]:\n\n```matlab\n% Plot distributional properties\ndist_plot_per_fm(sv2, 3, 4);\n```\n\n![simout_ex04](https://cloud.githubusercontent.com/assets/3018963/12080546/07401900-b256-11e5-8bfc-e868ce1f53b8.png)\n\nNote that in this example we explicitly specified the output names when calling\nthe [stats_gather] function. Also, for parameter set 2, we set the steady-state\ntruncation point to iteration 2000.\n\n\u003ca name=\"latextablewithdistributionalanalysisofallfocalmeasuresforonesetup\"\u003e\u003c/a\u003e\n\n#### 4.2.3\\. LaTeX table with distributional analysis of all focal measures for one setup\n\nIn reference [\\[2\\]][ref2], a number of [tables][ref2tables] containing a\ndetailed distributional analysis of all PPHPC focal measures are provided as\nsupplemental information. Each table displays a distributional analysis for one\nsetup, i.e., for one size/parameter set combination. The [dist_table_per_setup]\nfunction produces these tables, accepting a single parameter which corresponds\nto the output of [stats_gather]. For example, to get a table with the\ndistributional analysis of all PPHPC focal measures for model size 1600,\nparameter set 2, only two commands are required:\n\n```matlab\noutputs = {'$P^s_i$', '$P^w_i$', '$P^c_i$', '$\\bar{E}^s_i$', '$\\bar{E}^w_i$', '$\\bar{C}_i$'};\ns1600v2 = stats_gather('1600v2', [datafolder1 '/v2'], 'stats1600v2r*.txt', outputs, 2000);\ndist_table_per_setup(s1600v2)\n```\n\n![simout_ex05](https://cloud.githubusercontent.com/assets/3018963/11902078/432d565a-a5a7-11e5-877f-9e1fe65bfc62.png)\n\nWe specify the output names in LaTeX math mode so they appear in the produced\ntable as they appear in the article.\n\n\u003ca name=\"latextablewithadistributionalanalysisofonefocalmeasureformultiplesetups\"\u003e\u003c/a\u003e\n\n#### 4.2.4\\. LaTeX table with a distributional analysis of one focal measure for multiple setups\n\nA distributional analysis of a focal measure for multiple setups is often useful\nfor evaluating how its distributional properties vary with different model\nconfigurations/setups. The [dist_table_per_fm] function fits this purpose.\nHowever, this function returns a partial table, which can have additional\ncolumns (specified with the 'pre' parameter) prior to the distributional data\nitself, as well as additional rows, such as headers, footers, similar partial\ntables for other focal measures, and so on.\n\nUsing the PPHPC model as an example, let us generate a table with the\ndistributional analysis of the steady-state **mean** of the *sheep population*,\nfor all tested model sizes and both parameter sets. Model sizes are specified as\ncolumns, while parameter sets are obtained with two separate partial tables,\nwhich together form the final table:\n\n```matlab\n% Get stats data for parameter set 1, all sizes\ns100v1 = stats_gather('100v1', [datafolder1 '/v1'], 'stats100v1r*.txt', outputs, 1000);\ns200v1 = stats_gather('200v1', [datafolder1 '/v1'], 'stats200v1r*.txt', outputs, 1000);\ns400v1 = stats_gather('400v1', [datafolder1 '/v1'], 'stats400v1r*.txt', outputs, 1000);\ns800v1 = stats_gather('800v1', [datafolder1 '/v1'], 'stats800v1r*.txt', outputs, 1000);\ns1600v1 = stats_gather('1600v1', [datafolder1 '/v1'], 'stats1600v1r*.txt', outputs, 1000);\ndatas1 = {s100v1, s200v1, s400v1, s800v1, s1600v1};\n\n% Get stats data for parameter set 2, all sizes\ns100v2 = stats_gather('100v2', [datafolder1 '/v2'], 'stats100v2r*.txt', outputs, 2000);\ns200v2 = stats_gather('200v2', [datafolder1 '/v2'], 'stats200v2r*.txt', outputs, 2000);\ns400v2 = stats_gather('400v2', [datafolder1 '/v2'], 'stats400v2r*.txt', outputs, 2000);\ns800v2 = stats_gather('800v2', [datafolder1 '/v2'], 'stats800v2r*.txt', outputs, 2000);\ns1600v2 = stats_gather('1600v2', [datafolder1 '/v2'], 'stats1600v2r*.txt', outputs, 2000);\ndatas2 = {s100v2, s200v2, s400v2, s800v2, s1600v2};\n\n% Specify the focal measure: steady-state mean of the sheep population\nout = 1;   % Sheep population\nssumm = 5; % Steady-state mean\n\n% Table headers\nt = sprintf('\\n\\\\begin{table}[ht]');\nt = sprintf('%s\\n\\\\centering', t);\nt = sprintf('%s\\\\begin{tabular}{ccrrrrrr}\\n', t);\nt = sprintf('%s\\\\toprule\\n', t);\nt = sprintf('%sSet \u0026 Stat. \u0026 100 \u0026 200 \u0026 400 \u0026 800 \u0026 1600\\\\\\\\\\n', t);\nt = sprintf('%s\\\\midrule\\n\\\\multirow{4}{*}{v1} ', t);\n\n% First partial table, for parameter set 1\nt = sprintf('%s%s', t, dist_table_per_fm(datas1, out, ssumm, 1));\n\n% A midrule to separate the partial tables\nt = sprintf('%s\\\\midrule\\n\\\\multirow{4}{*}{v2}', t);\n\n% Second partial table, for parameter set 2\nt = sprintf('%s%s', t, dist_table_per_fm(datas2, out, ssumm, 1));\n\n% Table footers and caption\nt = sprintf('%s\\\\bottomrule\\n', t);\nt = sprintf('%s\\n\\\\end{tabular}', t);\nt = sprintf('%s\\n\\\\caption{Distributional analysis of sheep population steady-state mean for different model sizes and parameter sets.}\\n', t);\nt = sprintf('%s\\n\\\\end{table}\\n', t);\n\n% Show the table\nt\n```\n\n![simout_ex06](https://cloud.githubusercontent.com/assets/3018963/11902170/d16d1e46-a5a7-11e5-82a7-f97f74a2982a.png)\n\n\u003ca name=\"comparisonofmodelimplementations\"\u003e\u003c/a\u003e\n\n### 4.3\\. Comparison of model implementations\n\n\u003ca name=\"comparetheoutputsoftwoormoremodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.1\\. Compare the outputs of two or more model implementations\n\nThe [output_compare_plot] function can be used to graphically compare outputs\nfrom two or more model implementations. Multiple replications from each\nimplementation are averaged, and an optional moving average filter can be used\nto smooth the per implementation output plots. It works in a similar fashion to\n[output_plot], but is oriented towards multiple model implementations.\n\nIn the following example we compare the outputs of the NetLogo, Java EX (no\nagent shuffling) and Java EX (different parameter), using dataset 3.\n\n```matlab\n% Specify output names\noutputs = {'SheepPop', 'WolfPop', 'GrassQty', 'SheepEnergy', 'WolfEnergy', 'GrassEnergy'};\n\n% Compare outputs\noutput_compare_plot({'NetLogo','Java-NS', 'Java-DIFF'}, ...\n    {[datafolder3 '/nl_ok'], [datafolder3 '/j_ex_noshuff'], [datafolder3 '/j_ex_diff']}, ...\n    {'stats400v1*.txt', 'stats400v1*.txt', 'stats400v1*.txt'}, outputs, ...\n     'ws', 10, 'Colors', {'b','k','g'}, 'LineWidths', {2,1,3});\n\n```\n\n![compare_plot_01](https://cloud.githubusercontent.com/assets/3018963/20432922/5be6760e-ad99-11e6-893c-8dc40ceff77f.png)\n![compare_plot_02](https://cloud.githubusercontent.com/assets/3018963/20432923/5be6fce6-ad99-11e6-8576-ccb6f7763c6d.png)\n![compare_plot_03](https://cloud.githubusercontent.com/assets/3018963/20432926/5beb5232-ad99-11e6-9ecc-8a6d2a7da311.png)\n![compare_plot_04](https://cloud.githubusercontent.com/assets/3018963/20432925/5beab322-ad99-11e6-92e4-168b9f67fb6c.png)\n![compare_plot_05](https://cloud.githubusercontent.com/assets/3018963/20432924/5be96ed6-ad99-11e6-9de4-dab34b418989.png)\n![compare_plot_06](https://cloud.githubusercontent.com/assets/3018963/20432927/5becb0fa-ad99-11e6-8728-3c0005477867.png)\n\n\u003ca name=\"comparefocalmeasuresoftwomodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.2\\. Compare focal measures of two model implementations\n\nThe [stats_compare] function is used for comparing focal measures from two or\nmore model implementations. For this purpose, it applies statistical tests to\ndata obtained with the [stats_gather] function. Currently, [stats_compare] and\nthe remaining functions for model comparison are limited to comparing samples of\nthe same size.\n\nIn this example we compare the NetLogo and Java EX implementations of the PPHPC\nmodel for model size 400, parameter set 1 (as described in reference\n[\\[3\\]][ref3]). Replications of the Java EX variant were performed with 12\nthreads. First, we need to obtain the focal measures (i.e., statistical\nsummaries of simulation outputs) with the [stats_gather] function:\n\n```matlab\n% Get stats data for NetLogo implementation, parameter set 1, all sizes\nsnl400v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats400v1r*.txt', 6, 1000);\n\n% Get stats data for the Java implementation, EX strategy (12 threads), parameter set 1, all sizes\nsjex400v1 = stats_gather('JEX', [datafolder2 '/simout/EX'], 'stats400v1pEXt12r*.txt', 6, 1000);\n```\n\nThe fourth parameter, 6, corresponds to the number of model outputs, while the\nlast, 1000, is the steady-state truncation point. We can now perform the\ncomparison using the [stats_compare] function:\n\n```matlab\n% Perform comparison\n[ps, h_all] = stats_compare(0.01, {'p', 'np', 'p', 'np', 'p', 'p'}, 'none', snl400v1, sjex400v1)\n```\n\nThe first parameter specifies the significance level for the statistical tests.\nThe second parameter specifies the tests to apply on individual statistical\nsummaries for each output. In this case we are performing the _t_-test to all\nsummaries, except **argmax** and **argmin**, to which the Mann-Whitney test\n[\\[6\\]][ref6] is applied instead. The options 'p' and 'np' stand for parametric\nand non-parametric, respectively. The third parameter specifies the _p_-value\nadjustment method for comparing multiple focal measures. No correction is\nperformed in this case.\n\nThe [stats_compare] function return `ps`, a matrix of _p_-values for the\nrequested tests (rows correspond to outputs, columns to statistical summaries),\nand `h_all`, containing the number of tests failed for the specified\nsignificance level.\n\n```\nps =\n\n    0.1784    0.8491    0.4536    1.0000    0.9560    0.1666\n    0.0991    0.4727    0.5335    0.0752    0.7231    0.1859\n    0.2515    0.3006    0.2312    0.0852    0.8890    0.1683\n    0.4685    0.8496    0.9354    1.0000    0.8421    0.4394\n    0.7973    0.8796    0.0009    0.3534    0.2200    0.5757\n    0.2443    0.0750    0.1719    1.0000    0.9009    0.1680\n\n\nh_all =\n\n     1\n```\n\n\u003ca name=\"comparefocalmeasuresofmultiplemodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.3\\. Compare focal measures of multiple model implementations\n\nThe [stats_compare] function also allows to compare focal measure from more than\ntwo model implementations. If more than two [stats_gather] structs are passed as\narguments, the [stats_compare] function automatically uses _n_-sample\nstatistical tests, namely ANOVA [\\[7\\]][ref7] as a parametric test, and\nKruskal-Wallis [\\[8\\]][ref8] as a non-parametric test. In the following, we\ncompare all Java variants of the PPHPC model for size 800, parameter set 2:\n\n```matlab\n% Get stats data for Java implementation, ST strategy\nsjst800v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats800v2pSTr*.txt', 6, 2000);\n\n% Get stats data for the Java implementation, EQ strategy (12 threads)\nsjeq800v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats800v2pEQt12r*.txt', 6, 2000);\n\n% Get stats data for the Java implementation, EX strategy (12 threads)\nsjex800v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats800v2pEXt12r*.txt', 6, 2000);\n\n% Get stats data for the Java implementation, ER strategy (12 threads)\nsjer800v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats800v2pERt12r*.txt', 6, 2000);\n\n% Get stats data for the Java implementation, OD strategy (12 threads, b = 500)\nsjod800v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats800v2pODb500t12r*.txt', 6, 2000);\n\n% Perform comparison\nps = stats_compare(0.05, {'p', 'np', 'p', 'np', 'p', 'p'}, 'none', sjst800v2, sjeq800v2, sjex800v2, sjer800v2, sjod800v2)\n```\n\n```\nps =\n\n    0.8735    0.5325    1.0000    1.0000    0.7132    0.7257\n    0.4476    0.9051    0.3624    0.5947    0.7011    0.6554\n    0.4227    0.6240    0.8860    0.2442    0.5945    0.6785\n    0.0124    0.5474    0.6447    0.5238    0.7038    0.6182\n    0.8888    0.9622    0.1410    0.1900    0.7182    0.6825\n    0.9306    0.6286    0.4479    0.8377    0.5785    0.6785\n```\n\n\u003ca name=\"pairwisecomparisonofmodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.4\\. Pairwise comparison of model implementations\n\nWhen comparing multiple model implementations, if one or more are misaligned, \nthe [stats_compare] function will detected a misalignment, but will not provide\ninformation regarding which implementations are misaligned. The\n[stats_compare_pw] function performs pairwise comparisons of multiple model\nimplementations and outputs a table of failed tests for each pair of\nimplementations, allowing to detect which ones are misaligned. The following\ninstruction outputs this table for the data used in the previous example:\n\n```matlab\n% Output table of pairwise failed tests for significance level 0.05\nstats_compare_pw(0.05, {'p', 'np', 'p', 'np', 'p', 'p'}, 'none', sjst800v2, sjeq800v2, sjex800v2, sjer800v2, sjod800v2)\n```\n\n```\n             -----------------------------------------------------------------------\n             |          ST |          EQ |          EX |          ER |          OD |\n------------------------------------------------------------------------------------\n|         ST |           0 |           1 |           1 |           1 |           2 |\n|         EQ |           1 |           0 |           0 |           0 |           1 |\n|         EX |           1 |           0 |           0 |           0 |           0 |\n|         ER |           1 |           0 |           0 |           0 |           1 |\n|         OD |           2 |           1 |           0 |           1 |           0 |\n------------------------------------------------------------------------------------\n```\n\nSince each pairwise comparison involves the comparison of multiple focal\nmeasures, it can be useful to correct the _p_-values to account for multiple\ncomparisons, e.g., using the [Bonferroni] procedure:\n\n```matlab\n% Output table of pairwise failed tests for significance level 0.05 with Bonferroni correction\nstats_compare_pw(0.05, {'p', 'np', 'p', 'np', 'p', 'p'}, 'bonferroni', sjst800v2, sjeq800v2, sjex800v2, sjer800v2, sjod800v2)\n```\n\n```\n             -----------------------------------------------------------------------\n             |          ST |          EQ |          EX |          ER |          OD |\n------------------------------------------------------------------------------------\n|         ST |           0 |           0 |           0 |           0 |           0 |\n|         EQ |           0 |           0 |           0 |           0 |           0 |\n|         EX |           0 |           0 |           0 |           0 |           0 |\n|         ER |           0 |           0 |           0 |           0 |           0 |\n|         OD |           0 |           0 |           0 |           0 |           0 |\n------------------------------------------------------------------------------------\n```\n\nNo single test fails after the Bonferroni correction is applied to the\n_p_-values, strengthening the conclusion that the compared model implementations\nare aligned.\n\n\u003ca name=\"plotthepdfandcdfoffocalmeasuresfromoneormoremodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.5\\. Plot the PDF and CDF of focal measures from one or more model implementations\n\nIn this example we have two PPHPC implementations which produce equivalent\nresults (NLOK and JEXOK), and two other which display slightly different\nbehavior (JEXNS and JEXDIFF), as discussed in reference [\\[4\\]][ref4]. The\nfollowing code loads simulation output data from these four implementations, and\nplots, using the [stats_compare_plot] function, the PDF and CDF of the\nrespective focal measures. Plots for each focal measure are overlaid, allowing\nthe modeler to observe distributional output differences between the various\nimplementations.\n\n```matlab\n% Specify output names\noutputs = {'SheepPop', 'WolfPop', 'GrassQty', 'SheepEnergy', 'WolfEnergy', 'GrassEnergy'};\n\n% Determine focal measures of four PPHPC implementations\nsnl800v2 = stats_gather('NL', [datafolder3 '/nl_ok'], 'stats800v2*.txt', outputs, 2000);\nsjexok800v2 = stats_gather('JEXOK', [datafolder3 '/j_ex_ok'], 'stats800v2*.txt', outputs, 2000);\nsjexns800v2 = stats_gather('JEXNS', [datafolder3 '/j_ex_noshuff'], 'stats800v2*.txt', outputs, 2000);\nsjexdiff800v2 = stats_gather('JEXDIFF', [datafolder3 '/j_ex_diff'], 'stats800v2*.txt', outputs, 2000);\n\n% Plot PDF and CDF of focal measures\nstats_compare_plot(snl800v2, sjexok800v2, sjexns800v2, sjexdiff800v2);\n```\n\n_Sheep population_\n![compare_ex04_01](https://cloud.githubusercontent.com/assets/3018963/11904411/d91d552e-a5b7-11e5-8cb2-fcaa8687291d.png)\n\n_Wolf population_\n![compare_ex04_02](https://cloud.githubusercontent.com/assets/3018963/11904410/d9180984-a5b7-11e5-9cf2-15d8eeb50a3a.png)\n\n_Quantity of available grass_\n![compare_ex04_03](https://cloud.githubusercontent.com/assets/3018963/11904409/d915f0fe-a5b7-11e5-87d8-0577c57265bf.png)\n\n_Mean sheep energy_\n![compare_ex04_04](https://cloud.githubusercontent.com/assets/3018963/11904408/d9155f18-a5b7-11e5-9570-95488f6f7642.png)\n\n_Mean wolves energy_\n![compare_ex04_05](https://cloud.githubusercontent.com/assets/3018963/11904406/d914c22e-a5b7-11e5-9de4-4226eb2789e4.png)\n\n_Mean value of the countdown parameter in all cells_\n![compare_ex04_06](https://cloud.githubusercontent.com/assets/3018963/11904407/d915052c-a5b7-11e5-927a-f8fdc73ac497.png)\n\n\u003ca name=\"tablewith_p_-valuesfromcomparisonoffocalmeasuresfrommodelimplementations\"\u003e\u003c/a\u003e\n\n#### 4.3.6\\. Table with _p_-values from comparison of focal measures from model implementations\n\nThe [stats_compare_table] function produces publication quality tables of\n_p_-values in LaTeX. This function accepts four parameters:\n\n1. `tests` - Type of statistical tests to perform (parametric or\nnon-parametric).\n2. `adjust` - Adjustment to _p_-values for comparison of multiple focal\nmeasures: 'holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY', 'sidak' or\n'none'.\n3. `pthresh` - Minimum value of _p_-values before truncation (e.g., if this\nvalue is set to 0.001 and a certain _p_-value is less than that, the table will\ndisplay \"\u0026lt; 0.001\".\n4. `tformat` - Specifies if outputs appear in the header (0) or in the first\ncolumn (1).\n5. `varargin` - Variable number of cell arrays containing the following two\nitems defining a comparison: \n   * Item 1 can take one of three formats: a) zero, 0, which is an indication \n     not to print any type of comparison name; b) a string describing the \n     comparison name; or, c) a cell array of two strings, the first describing a \n     comparison group name, and the second describing a comparison name.\n   * Item 2, a cell array of statistical summaries (given by the \n     [stats_gather] function) of the implementations \n     to be compared.\n\nThe following command uses data from a [previous example](#comparefocalmeasuresofmultiplemodelimplementations)\nand outputs a table of _p_-values returned by the non-parametric, multi-sample\nKruskal-Wallis test for individual focal measures:\n\n```matlab\ns800v2 = {sjst800v2, sjeq800v2, sjex800v2, sjer800v2, sjod800v2};\nstats_compare_table('np', 'none', 0.001, 0, {0, s800v2})\n```\n\n![compare_ex05](https://cloud.githubusercontent.com/assets/3018963/11904709/e54bee80-a5b9-11e5-9c18-feab61382675.png)\n\nAs we are only performing one comparison (for model size 800, parameter set 2),\nthe third argument is set to 0. For multiple comparisons, it is preferable to\nset this parameter to 1, as it puts comparisons along columns and outputs along\nrows. The first item in the final argument is set to 0, such that the comparison\nname is not printed (which makes sense when the table only contains a single\ncomparison).\n\n\u003ca name=\"multiplecomparisonsandcomparisonnames\"\u003e\u003c/a\u003e\n\n#### 4.3.7\\. Multiple comparisons and comparison names\n\nIn Table 1 of reference [\\[4\\]][ref4], three comparisons, I, II, and III, are\nperformed. The comparison name can be specified in item 1 of the variable\nargument cell arrays, as shown in the following code:\n\n```matlab\n% Specify output names\noutputs = {'$P^s$', '$P^w$', '$P^c$', '$\\overline{E}^s$', '$\\overline{E}^w$', '$\\overline{C}$'};\n\n% Determine focal measures\nsnl400v1 = stats_gather('NL', [datafolder3 '/nl_ok'], 'stats400v1*.txt', outputs, 1000);\nsjexok400v1 = stats_gather('JEXOK', [datafolder3 '/j_ex_ok'], 'stats400v1*.txt', outputs, 1000);\nsjexns400v1 = stats_gather('JEXNS', [datafolder3 '/j_ex_noshuff'], 'stats400v1*.txt', outputs, 1000);\nsjexdiff400v1 = stats_gather('JEXDIFF', [datafolder3 '/j_ex_diff'], 'stats400v1*.txt', outputs, 1000);\n\n% Comparisons to perform, specify name in item 1\ncmp1 = {'I', {snl400v1, sjexok400v1}};\ncmp2 = {'II', {snl400v1, sjexns400v1 }};\ncmp3 = {'III', {snl400v1, sjexdiff400v1}};\n\n% Output comparison table\nstats_compare_table({'p', 'np', 'p', 'np', 'p', 'p'}, 'none', 0.000001, 0, cmp1, cmp2, cmp3)\n```\n\n![compare_ex06](https://cloud.githubusercontent.com/assets/3018963/11904749/39f23ba6-a5ba-11e5-9f10-d1d42fbd39f8.png)\n\nHere we specify comparison names, I, II, and II, which will be printed in the\ntable. Note that each comparison tests two model implementations. As such the \nresulting _p_-values come from two-sample tests, i.e., from the parametric \n_t_-test and from the non-parametric Mann-Whitney test.\n\n\u003ca name=\"comparisongroups\"\u003e\u003c/a\u003e\n\n#### 4.3.8\\. Comparison groups\n\nIn Table 8 of reference [\\[3\\]][ref3], ten comparisons are performed. Each\ncomparison is associated with a model size and parameter set, and tests for\ndifferences between six model implementations. Comparisons are divided in two\ngroups, according to the parameter set used. This is accomplished by passing a\ncell array of two strings (comparison group and comparison name) to the first\nitem of each comparison. The following code outputs this table:\n\n```matlab\n% Specify output names\noutputs = {'$P_i^s$', '$P_i^w$', '$P_i^c$', '$\\overline{E}^s_i$', '$\\overline{E}^w_i$', '$\\overline{C}_i$'};\n\n% Determine focal measures for NetLogo replications\nsnl100v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats100v1*.txt', outputs, 1000);\nsnl200v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats200v1*.txt', outputs, 1000);\nsnl400v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats400v1*.txt', outputs, 1000);\nsnl800v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats800v1*.txt', outputs, 1000);\nsnl1600v1 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats1600v1*.txt', outputs, 1000);\nsnl100v2 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats100v2*.txt', outputs, 2000);\nsnl200v2 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats200v2*.txt', outputs, 2000);\nsnl400v2 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats400v2*.txt', outputs, 2000);\nsnl800v2 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats800v2*.txt', outputs, 2000);\nsnl1600v2 = stats_gather('NL', [datafolder2 '/simout/NL'], 'stats1600v2*.txt', outputs, 2000);\n\n% Determine focal measures for Java ST replications\nsjst100v1 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats100v1*.txt', outputs, 1000);\nsjst200v1 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats200v1*.txt', outputs, 1000);\nsjst400v1 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats400v1*.txt', outputs, 1000);\nsjst800v1 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats800v1*.txt', outputs, 1000);\nsjst1600v1 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats1600v1*.txt', outputs, 1000);\nsjst100v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats100v2*.txt', outputs, 2000);\nsjst200v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats200v2*.txt', outputs, 2000);\nsjst400v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats400v2*.txt', outputs, 2000);\nsjst800v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats800v2*.txt', outputs, 2000);\nsjst1600v2 = stats_gather('ST', [datafolder2 '/simout/ST'], 'stats1600v2*.txt', outputs, 2000);\n\n% Determine focal measures for Java EQ replications, 12 threads\nsjeq100v1 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats100v1pEQt12r*.txt', outputs, 1000);\nsjeq200v1 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats200v1pEQt12r*.txt', outputs, 1000);\nsjeq400v1 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats400v1pEQt12r*.txt', outputs, 1000);\nsjeq800v1 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats800v1pEQt12r*.txt', outputs, 1000);\nsjeq1600v1 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats1600v1pEQt12r*.txt', outputs, 1000);\nsjeq100v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats100v2pEQt12r*.txt', outputs, 2000);\nsjeq200v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats200v2pEQt12r*.txt', outputs, 2000);\nsjeq400v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats400v2pEQt12r*.txt', outputs, 2000);\nsjeq800v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats800v2pEQt12r*.txt', outputs, 2000);\nsjeq1600v2 = stats_gather('EQ', [datafolder2 '/simout/EQ'], 'stats1600v2pEQt12r*.txt', outputs, 2000);\n\n% Determine focal measures for Java EX replications, 12 threads\nsjex100v1 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats100v1pEXt12r*.txt', outputs, 1000);\nsjex200v1 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats200v1pEXt12r*.txt', outputs, 1000);\nsjex400v1 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats400v1pEXt12r*.txt', outputs, 1000);\nsjex800v1 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats800v1pEXt12r*.txt', outputs, 1000);\nsjex1600v1 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats1600v1pEXt12r*.txt', outputs, 1000);\nsjex100v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats100v2pEXt12r*.txt', outputs, 2000);\nsjex200v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats200v2pEXt12r*.txt', outputs, 2000);\nsjex400v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats400v2pEXt12r*.txt', outputs, 2000);\nsjex800v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats800v2pEXt12r*.txt', outputs, 2000);\nsjex1600v2 = stats_gather('EX', [datafolder2 '/simout/EX'], 'stats1600v2pEXt12r*.txt', outputs, 2000);\n\n% Determine focal measures for Java ER replications, 12 threads\nsjer100v1 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats100v1pERt12r*.txt', outputs, 1000);\nsjer200v1 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats200v1pERt12r*.txt', outputs, 1000);\nsjer400v1 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats400v1pERt12r*.txt', outputs, 1000);\nsjer800v1 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats800v1pERt12r*.txt', outputs, 1000);\nsjer1600v1 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats1600v1pERt12r*.txt', outputs, 1000);\nsjer100v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats100v2pERt12r*.txt', outputs, 2000);\nsjer200v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats200v2pERt12r*.txt', outputs, 2000);\nsjer400v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats400v2pERt12r*.txt', outputs, 2000);\nsjer800v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats800v2pERt12r*.txt', outputs, 2000);\nsjer1600v2 = stats_gather('ER', [datafolder2 '/simout/ER'], 'stats1600v2pERt12r*.txt', outputs, 2000);\n\n% Determine focal measures for Java OD replications, 12 threads, b = 500\nsjod100v1 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats100v1pODb500t12r*.txt', outputs, 1000);\nsjod200v1 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats200v1pODb500t12r*.txt', outputs, 1000);\nsjod400v1 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats400v1pODb500t12r*.txt', outputs, 1000);\nsjod800v1 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats800v1pODb500t12r*.txt', outputs, 1000);\nsjod1600v1 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats1600v1pODb500t12r*.txt', outputs, 1000);\nsjod100v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats100v2pODb500t12r*.txt', outputs, 2000);\nsjod200v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats200v2pODb500t12r*.txt', outputs, 2000);\nsjod400v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats400v2pODb500t12r*.txt', outputs, 2000);\nsjod800v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats800v2pODb500t12r*.txt', outputs, 2000);\nsjod1600v2 = stats_gather('OD', [datafolder2 '/simout/OD'], 'stats1600v2pODb500t12r*.txt', outputs, 2000);\n\n% Group same size/param.set focal measures into comparisons to be performed\ns100v1 = {snl100v1, sjst100v1, sjeq100v1, sjex100v1, sjer100v1, sjod100v1};\ns200v1 = {snl200v1, sjst200v1, sjeq200v1, sjex200v1, sjer200v1, sjod200v1};\ns400v1 = {snl400v1, sjst400v1, sjeq400v1, sjex400v1, sjer400v1, sjod400v1};\ns800v1 = {snl800v1, sjst800v1, sjeq800v1, sjex800v1, sjer800v1, sjod800v1};\ns1600v1 = {snl1600v1, sjst1600v1, sjeq1600v1, sjex1600v1, sjer1600v1, sjod1600v1};\ns100v2 = {snl100v2, sjst100v2, sjeq100v2, sjex100v2, sjer100v2, sjod100v2};\ns200v2 = {snl200v2, sjst200v2, sjeq200v2, sjex200v2, sjer200v2, sjod200v2};\ns400v2 = {snl400v2, sjst400v2, sjeq400v2, sjex400v2, sjer400v2, sjod400v2};\ns800v2 = {snl800v2, sjst800v2, sjeq800v2, sjex800v2, sjer800v2, sjod800v2};\ns1600v2 = {snl1600v2, sjst1600v2, sjeq1600v2, sjex1600v2, sjer1600v2, sjod1600v2};\n\n% Comparisons to perform\ncmp1 = {{'Param. set 1', '100'}, s100v1};\ncmp2 = {{'Param. set 1', '200'}, s200v1};\ncmp3 = {{'Param. set 1', '400'}, s400v1};\ncmp4 = {{'Param. set 1', '800'}, s800v1};\ncmp5 = {{'Param. set 1', '1600'}, s1600v1};\ncmp6 = {{'Param. set 2', '100'}, s100v2};\ncmp7 = {{'Param. set 2', '200'}, s200v2};\ncmp8 = {{'Param. set 2', '400'}, s400v2};\ncmp9 = {{'Param. set 2', '800'}, s800v2};\ncmp10 = {{'Param. set 2', '1600'}, s1600v2};\n\n% Output comparison table\nstats_compare_table('np', 'none', 1e-6, 1, cmp1, cmp2, cmp3, cmp4, cmp5, cmp6, cmp7, cmp8, cmp9, cmp10)\n```\n\n![compare_ex07](https://cloud.githubusercontent.com/assets/3018963/11904817/a80b1860-a5ba-11e5-9bb0-38a9ce329b85.png)\n\nWe set the `tformat` parameter to 1, as this is more appropriate when many\ncomparisons are performed.\n\n\u003ca name=\"unittests\"\u003e\u003c/a\u003e\n\n## 5\\. Unit tests\n\nThe _SimOutUtils_ unit tests require the [MOxUnit] framework. Set the\nappropriate path to this framework as specified in the respective instructions,\n`cd` into the [tests] folder and execute the following instruction:\n\n```\nmoxunit_runtests\n```\n\nThe tests can take a few minutes to run.\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n\n## 6\\. License\n\n[MIT License](LICENSE)\n\n\u003ca name=\"references\"\u003e\u003c/a\u003e\n\n## 7\\. References\n\n\u003ca name=\"ref1\"\u003e\u003c/a\u003e\n\n[\\[1\\]][ref1] Fachada N, Lopes VV, Martins RC, Rosa AC. (2016) SimOutUtils -\n Utilities for analyzing simulation output. *Journal of Open Research Software*\n4(1):e38. http://doi.org/10.5334/jors.110\n\n\u003ca name=\"ref2\"\u003e\u003c/a\u003e\n\n[\\[2\\]][ref2] Fachada N, Lopes VV, Martins RC, Rosa AC. (2015) Towards a\nstandard model for research in agent-based modeling and simulation. *PeerJ\nComputer Science* 1:e36. https://doi.org/10.7717/peerj-cs.36\n\n\u003ca name=\"ref3\"\u003e\u003c/a\u003e\n\n[\\[3\\]][ref3] Fachada N, Lopes VV, Martins RC, Rosa AC. (2017)\nParallelization strategies for spatial agent-based models. *International\nJournal of Parallel Programming*. 45(3):449–481.\nhttp://dx.doi.org/10.1007/s10766-015-0399-9\n([arXiv preprint](http://arxiv.org/abs/1507.04047))\n\n\u003ca name=\"ref4\"\u003e\u003c/a\u003e\n\n[\\[4\\]][ref4] Fachada N, Lopes VV, Martins RC, Rosa AC. (2017)\nModel-independent comparison of simulation output. *Simulation Modelling\nPractice and Theory*. 72:131–149. http://dx.doi.org/10.1016/j.simpat.2016.12.013\n([arXiv preprint](http://arxiv.org/abs/1509.09174))\n\n\u003ca name=\"ref5\"\u003e\u003c/a\u003e\n\n[\\[5\\]][ref5] Willink R. (2005) A Confidence Interval and Test for the Mean of\nan Asymmetric Distribution. *Communications in Statistics - Theory and Methods*\n34 (4): 753–766. https://doi.org/10.1081%2FSTA-200054419\n\n\u003ca name=\"ref6\"\u003e\u003c/a\u003e\n\n[\\[6\\]][ref6] Gibbons JD, Chakraborti S. (2010) *Nonparametric statistical\ninference*. Chapman and Hall/CRC\n\n\u003ca name=\"ref7\"\u003e\u003c/a\u003e\n\n[\\[7\\]][ref7] Montgomery DC, Runger GC. (2014) *Applied statistics and\nprobability for engineers*. John Wiley \\\u0026 Sons\n\n\u003ca name=\"ref8\"\u003e\u003c/a\u003e\n\n[\\[8\\]][ref8] Kruskal WH, Wallis WA. (1952) Use of Ranks in One-Criterion\nVariance Analysis. *Journal of the American Statistical Association* 47 (260): \n583–621\n\n[ref1]: #ref1\n[ref2]: #ref2\n[ref3]: #ref3\n[ref4]: #ref4\n[ref5]: #ref5\n[ref6]: #ref6\n[ref7]: #ref7\n[ref8]: #ref8\n[ref2tables]: https://doi.org/10.7717/peerj-cs.36/supp-2\n[Matlab]: http://www.mathworks.com/products/matlab/\n[Octave]: https://gnu.org/software/octave/\n[NetLogo]: https://ccl.northwestern.edu/netlogo/\n[dlmread]: http://www.mathworks.com/help/matlab/ref/dlmread.html\n[PPHPC]: https://github.com/fakenmc/pphpc\n[matlab2tikz]: http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz\n[siunitx]: https://www.ctan.org/pkg/siunitx\n[ulem]: https://www.ctan.org/pkg/ulem\n[multirow]: https://www.ctan.org/pkg/multirow\n[booktabs]: https://www.ctan.org/pkg/booktabs\n[LineSpec]: http://www.mathworks.com/help/matlab/ref/linespec.html\n[PatchSpec]: http://www.mathworks.com/help/matlab/ref/patch-properties.html\n[Willink confidence interval]: https://doi.org/10.1081%2FSTA-200054419\n[Bonferroni]: https://en.wikipedia.org/wiki/Bonferroni_correction\n[startup]: startup.m\n[output_plot]: core/output_plot.m\n[stats_get]: core/stats_get.m\n[stats_gather]: core/stats_gather.m\n[stats_get_pphpc]: core/stats_get_pphpc.m\n[stats_get_iters]: core/stats_get_iters.m\n[stats_analyze]: core/stats_analyze.m\n[stats_table_per_setup]: dist/stats_table_per_setup.m\n[dist_plot_per_fm]: dist/dist_plot_per_fm.m\n[dist_table_per_setup]: dist/dist_table_per_setup.m\n[dist_table_per_fm]: dist/dist_table_per_fm.m\n[output_compare_plot]: compare/output_compare_plot.m\n[stats_compare]: compare/stats_compare.m\n[stats_compare_pw]: compare/stats_compare_pw.m\n[stats_compare_plot]: compare/stats_compare_plot.m\n[stats_compare_table]: compare/stats_compare_table.m\n[tests]: tests\n[MOxUnit]: https://github.com/MOxUnit/MOxUnit\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnunofachada%2Fsimoututils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnunofachada%2Fsimoututils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnunofachada%2Fsimoututils/lists"}