{"id":1118,"date":"2023-10-01T14:25:44","date_gmt":"2023-10-01T18:25:44","guid":{"rendered":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/?post_type=chapter&#038;p=1118"},"modified":"2025-02-04T14:55:50","modified_gmt":"2025-02-04T19:55:50","slug":"tutorial-monte-carlo-runs","status":"publish","type":"chapter","link":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/chapter\/tutorial-monte-carlo-runs\/","title":{"raw":"Tutorial: Monte Carlo runs","rendered":"Tutorial: Monte Carlo runs"},"content":{"raw":"<div class=\"textbox shaded\">\r\n\r\n<strong>Using Monte Carlo routine on Mac with Apple M chip<\/strong>\r\n\r\nWe have noticed a problem (October 2024) when running the MC routine on newer Macs with Apple M chips using Parallels Desktop: the routine takes many more runs to find a balanced model, and the runs are more chaotic than when run on a native Windows machine.\r\n\r\nIf you are using the MC on an Apple M machine for production runs, we suggest you try to run the simulations on a native Windows machine as well.\r\n\r\nWe have not found any problems for other EwE routines.\r\n\r\n<\/div>\r\n&nbsp;\r\n<p style=\"font-weight: 400\">Ecosim has a Monte Carlo (MC) facility\u00a0\u00a0for evaluating input parameter uncertainty by resampling parameters to search for input parameter combinations that result in better fit to time series.<\/p>\r\n\r\n<div class=\"textbox textbox--sidebar\"><img class=\"alignnone size-full wp-image-2607\" src=\"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26.png\" alt=\"\" width=\"426\" height=\"262\" \/>You can open scenarios and load time series by clicking the down-arrow next to the icons at the top of the EwE interface.<\/div>\r\n<p style=\"font-weight: 400\">The routine requires a balanced model with time series, and we will here use the \u201cAnchovy Bay true.ewemdb\u201d model, with the \u201canch bay\u201d scenario and the \u201canchovy bay true\u201d time series, (download all along with an AIC spreadsheet from <a href=\"https:\/\/ln5.sync.com\/dl\/20358ca30\/9zdktdsp-hiphthjc-gxetndrk-pgr4vvc4\">this link<\/a>). Open the model, and load the scenario and time series. Then open the MC routine from <em>Ecosim &gt; Tools &gt; Monte Carlo simulation<\/em>. Check the <em>Settings<\/em> tab. If you check <em>Retain better fitting estimates<\/em>, the routine will resample parameters from a new better fit whenever such are obtained. This turns the routine into a Markov Chain Monte Carlo (MCMC) routine, which usually will make it possible and easier for the routine to find additional mass-balanced solutions.<\/p>\r\n<p style=\"font-weight: 400\">On the <em>B<\/em> tab, set the <em>CV<\/em> to 0.4 for all groups (just click where it says <em>CV<\/em> in the top row, then enter 0.4 in the <em>Apply<\/em> box, return), and just leave the other parameters as is. Click<em> Run trials<\/em>.<\/p>\r\n<p style=\"font-weight: 400\">Go to the Biomass plot tab. For each run (of the default 20), the routine samples the parameters until it finds a balanced model, (how many tries that takes is given in the <em>Ecopath runs<\/em> field), it then runs Ecosim, and estimates summed squared residuals (SS). If the SS is lower than the previous best, the model will (if <em>Retain better fitting estimates<\/em> is checked), resample the input parameters around the new set of parameters that gives the lower SS. If you select <em>Apply best fit<\/em>\u00a0the routine will transfer the best set of input parameters to the Ecopath model. You should therefore take care not to overwrite your model, so, it really is best to work on a copy of your model.<\/p>\r\n<p style=\"font-weight: 400\">We here use just 20 runs for the simulations; in a real analysis, you may well choose to use thousands.<\/p>\r\n<p style=\"font-weight: 400\">If you want to get statistics for parameter ranges etc., then click the <em>Save output &gt; All results in one file<\/em> option before doing the run. You can locate the saved file from the <em>Menu &gt; Tools &gt; Options &gt; File Management<\/em>. There, click the folder symbol to the right of <em>Monte Carlo trial results<\/em>, and you\u2019ll get to a folder with a file, MonteCarloTrials.csv, which has the results \u2013 in a cumbersome format that requires some manipulation to make sense of. \u00a0For this simple model with just 20 runs, there\u2019s over 1100 lines in the CSV file as parameters are saved for each run.<\/p>\r\n<p style=\"font-weight: 400\">If you instead use the <em>Save File &gt; Separate files per trial<\/em>, the routine will make a folder for each run and then save (in this case) 76 files within each run folder. For instance, biomass annual.csv, which will have the biomass by functional group for each year in the run. To deal with such file complexity: use R (or similar) for analysis.<\/p>\r\n<p style=\"font-weight: 400\">You can use MC with the EcoSampler plug-in to store the samples that the MC runs for further analysis. <span style=\"color: #000000\">See the <a href=\"https:\/\/pressbooks.bccampus.ca\/eweguide\/chapter\/ecosampler\/\">EcoSampler User\u2019s Guide<\/a> for further information.<\/span><\/p>","rendered":"<div class=\"textbox shaded\">\n<p><strong>Using Monte Carlo routine on Mac with Apple M chip<\/strong><\/p>\n<p>We have noticed a problem (October 2024) when running the MC routine on newer Macs with Apple M chips using Parallels Desktop: the routine takes many more runs to find a balanced model, and the runs are more chaotic than when run on a native Windows machine.<\/p>\n<p>If you are using the MC on an Apple M machine for production runs, we suggest you try to run the simulations on a native Windows machine as well.<\/p>\n<p>We have not found any problems for other EwE routines.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"font-weight: 400\">Ecosim has a Monte Carlo (MC) facility\u00a0\u00a0for evaluating input parameter uncertainty by resampling parameters to search for input parameter combinations that result in better fit to time series.<\/p>\n<div class=\"textbox textbox--sidebar\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2607\" src=\"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26.png\" alt=\"\" width=\"426\" height=\"262\" srcset=\"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26.png 426w, https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26-300x185.png 300w, https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26-65x40.png 65w, https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26-225x138.png 225w, https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-content\/uploads\/sites\/1902\/2023\/10\/Screenshot-2024-01-10-at-16.49.26-350x215.png 350w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/>You can open scenarios and load time series by clicking the down-arrow next to the icons at the top of the EwE interface.<\/div>\n<p style=\"font-weight: 400\">The routine requires a balanced model with time series, and we will here use the \u201cAnchovy Bay true.ewemdb\u201d model, with the \u201canch bay\u201d scenario and the \u201canchovy bay true\u201d time series, (download all along with an AIC spreadsheet from <a href=\"https:\/\/ln5.sync.com\/dl\/20358ca30\/9zdktdsp-hiphthjc-gxetndrk-pgr4vvc4\">this link<\/a>). Open the model, and load the scenario and time series. Then open the MC routine from <em>Ecosim &gt; Tools &gt; Monte Carlo simulation<\/em>. Check the <em>Settings<\/em> tab. If you check <em>Retain better fitting estimates<\/em>, the routine will resample parameters from a new better fit whenever such are obtained. This turns the routine into a Markov Chain Monte Carlo (MCMC) routine, which usually will make it possible and easier for the routine to find additional mass-balanced solutions.<\/p>\n<p style=\"font-weight: 400\">On the <em>B<\/em> tab, set the <em>CV<\/em> to 0.4 for all groups (just click where it says <em>CV<\/em> in the top row, then enter 0.4 in the <em>Apply<\/em> box, return), and just leave the other parameters as is. Click<em> Run trials<\/em>.<\/p>\n<p style=\"font-weight: 400\">Go to the Biomass plot tab. For each run (of the default 20), the routine samples the parameters until it finds a balanced model, (how many tries that takes is given in the <em>Ecopath runs<\/em> field), it then runs Ecosim, and estimates summed squared residuals (SS). If the SS is lower than the previous best, the model will (if <em>Retain better fitting estimates<\/em> is checked), resample the input parameters around the new set of parameters that gives the lower SS. If you select <em>Apply best fit<\/em>\u00a0the routine will transfer the best set of input parameters to the Ecopath model. You should therefore take care not to overwrite your model, so, it really is best to work on a copy of your model.<\/p>\n<p style=\"font-weight: 400\">We here use just 20 runs for the simulations; in a real analysis, you may well choose to use thousands.<\/p>\n<p style=\"font-weight: 400\">If you want to get statistics for parameter ranges etc., then click the <em>Save output &gt; All results in one file<\/em> option before doing the run. You can locate the saved file from the <em>Menu &gt; Tools &gt; Options &gt; File Management<\/em>. There, click the folder symbol to the right of <em>Monte Carlo trial results<\/em>, and you\u2019ll get to a folder with a file, MonteCarloTrials.csv, which has the results \u2013 in a cumbersome format that requires some manipulation to make sense of. \u00a0For this simple model with just 20 runs, there\u2019s over 1100 lines in the CSV file as parameters are saved for each run.<\/p>\n<p style=\"font-weight: 400\">If you instead use the <em>Save File &gt; Separate files per trial<\/em>, the routine will make a folder for each run and then save (in this case) 76 files within each run folder. For instance, biomass annual.csv, which will have the biomass by functional group for each year in the run. To deal with such file complexity: use R (or similar) for analysis.<\/p>\n<p style=\"font-weight: 400\">You can use MC with the EcoSampler plug-in to store the samples that the MC runs for further analysis. <span style=\"color: #000000\">See the <a href=\"https:\/\/pressbooks.bccampus.ca\/eweguide\/chapter\/ecosampler\/\">EcoSampler User\u2019s Guide<\/a> for further information.<\/span><\/p>\n<div class=\"media-attributions clear\" prefix:cc=\"http:\/\/creativecommons.org\/ns#\" prefix:dc=\"http:\/\/purl.org\/dc\/terms\/\"><h2>Media Attributions<\/h2><ul><li >EwE interface shortcut for loading files, scenarios and time series       <\/li><\/ul><\/div>","protected":false},"author":1909,"menu_order":9,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"class_list":["post-1118","chapter","type-chapter","status-publish","hentry","chapter-type-numberless"],"part":1094,"_links":{"self":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapters\/1118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/wp\/v2\/users\/1909"}],"version-history":[{"count":7,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapters\/1118\/revisions"}],"predecessor-version":[{"id":4116,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapters\/1118\/revisions\/4116"}],"part":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/parts\/1094"}],"metadata":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapters\/1118\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/wp\/v2\/media?parent=1118"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/pressbooks\/v2\/chapter-type?post=1118"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/wp\/v2\/contributor?post=1118"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/ewemodel\/wp-json\/wp\/v2\/license?post=1118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}