This file is indexed.

/usr/share/help/C/gnumeric/analysis-simulation.xml is in gnumeric-doc 1.12.35-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
<?xml version="1.0" encoding="UTF-8"?>
<sect1 id="sect-advanced-analysis-simulation">
  <title>Simulation Analysis</title>

  <sect2 id="sect-advanced-analysis-simulation-intro">
    <title>Introduction to simulation analysis</title>
    <para>A simulation is the imitation of the operation of a real-world process or system.  The behavior of a system is studied by generating an artificial history of the system through the use of random numbers.  These numbers are used in the context of a simulation model, which is the mathematical, logical and symbolic representation of the relationships between the objects of interest of the system.  After the model has been validated, the effects of changes in the environment on the system, or the effects of changes in the system on system performance can be predicted using the simulation model.
    <footnote>
      <para>Adapted from Banks, Carson, Nelson and Nicol (2001), Discrete-Event System Simulation, 3rd ed.</para>
    </footnote>
    </para>
    <para>Gnumeric includes a facility for performing Monte Carlo Simulation.  Monte Carlo simulation involves the sampling of random numbers to solve a problem where the passage of time plays no substantive role.
    <footnote>
      <para>Definition from Law and Kelton (1991), Simulation Modeling &amp; Analysis, 2nd ed, pp. 113.</para>
    </footnote>  In other words, each sample is not effected by prior samples.  This is in contrast to discrete event simulation or continuous simulation where the results from earlier in the simulation can effect successive samples within a simulation experiment.  The Monte Carlo simulation will be enabled through the use of the Random Number functions as described in ??? <!--<xref linkend="CATEGORY_Random_Numbers"/> --> and the results presented along with statistics for use in analysis.    
    <footnote>
      <para>Gnumeric random numbers are generated using the Mersenne twister MT19937 pseudo-random number generator as implemented in the GNU Scientific Library.</para>
    </footnote>
    </para>
  </sect2>
  <sect2 id="sect-advanced-analysis-simulation-setup">
    <title>Setting up the simulation model</title>
    <para>The remainder of this chapter will illustrate use of the simulation tool using an example from Banks et. al.  
      <footnote>
        <para>Adapted from Banks, Carson, Nelson and Nicol (2001), Discrete-Event System Simulation, 3rd ed. pp. 42-45.</para>
      </footnote> 
    A classic inventory problem is the newsvendor problem.  A newsvendor buys papers for 33 cents each and sells for 50 cents.  Newspapers not sold are sold as scrap (recycled) for 5 cents.  Newspapers are purchased by the paper seller in bundles of 10.  Demand for newspapers can be categorized as “good,” “fair,” or “poor” with probability 0.35, 0.45 and 0.20 respectively, with each day's demand being independent of prior days.  The problem for the newsvendor is to determine the optimal number of papers to purchase when the day's demand is not yet known.</para>
    
    <para>The daily profit equation for the newsvendor is:</para>
    <informalequation>
     <alt>Profit = [(Sale revenue) - (Cost) - (Scrap value)]</alt>
     <mathphrase>Profit = [(Sale revenue) - (Cost) - (Scrap value)]</mathphrase>
    </informalequation> 

    <para>To set up the model, this example will use two tabs in Gnumeric, a tab labeled 'Profit' to calculate profit, and a tab labeled 'Demand Tables' to store the various tables needed to calculate the demand for any given sampling.</para>

    <para>For the Profit tab, set up the profit tab as in <xref linkend="fig-simulation-example-profit-table" />.</para>
    
    <para>At the top of the Profit' tab, the Profit table will be entered .  There are three variables: Sale revenue, Cost and Scrap value, and they take the per unit coefficients of 0.5, 0.33 and 0.05 respectively.  Enter the coefficients in cells B13 through D13.  In cells B12 through D12, enter the equations for sale revenue, cost and Scrap value that are in the list below.  In cell E12, enter the equation for Profit</para>
    
    <para>Next, we add the values for the decision variable, which is the amount purchased, and the amount sold.  </para>
    
    <itemizedlist>
      <listitem><para>B12: =B13*min(B16,B20)</para></listitem>
      <listitem><para>C12: =C13*B16</para></listitem>
      <listitem><para>D12: =D13*max(0,B16-B20)</para></listitem>
      <listitem><para>E12: =B12-C12+D12</para></listitem>
      <listitem><para>B13: 0.5</para></listitem>
      <listitem><para>C13: 0.33</para></listitem>
      <listitem><para>D13: 0.05</para></listitem>
      <listitem><para>B16: 50</para></listitem>
    </itemizedlist>

    <figure id="fig-simulation-example-profit-table">
      <title>Profit table for newsvendor example</title>
      <screenshot>
        <mediaobject>
          <imageobject>
            <imagedata fileref="figures/analysis-simulation-profit-ex1.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              This screenshot depicts the profit table from the newsvendor simulation example after the set of entries in cells B12 through E13 and Cell B16 have been filled in.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure>
    
    <tip>
      <title> Using SIMTABLE for parameter values.</title>
      <para>Sometimes, there is a need to try a number of different values for a single parameter. In <xref linkend="sect-advanced-analysis-simulation-simtable" /> the <function>SIMTABLE</function> function will be used to automate the use of a set of values for a parameter such as purchase quantity.  For now, set the purchase quantity to 50 in cell C16.</para>
    </tip>
    
    <para>Next, create the demand tables from which the demand will be generated.  In the tab 'Demand Tables' enter the values of the probability in cells B4 through B6 (B4: 0.35; B5: 0.45; B6: 0.2).  In cells C4, C5 and C6 enter the cumulative probability values (C4: 0.35; C5: 0.8; C6: 1) as shown in <xref linkend="fig-simulation-example-demand-newsday-type" />. </para>
		
    <itemizedlist>
      <listitem><para>B4: 0.35</para></listitem>
      <listitem><para>B5: 0.45</para></listitem>
      <listitem><para>B6: 0.2</para></listitem>
      <listitem><para>C4: 0.35</para></listitem>
      <listitem><para>C5: 0.8</para></listitem>
      <listitem><para>C6: 1.0</para></listitem>
    </itemizedlist>
			
    
    <figure id="fig-simulation-example-demand-newsday-type">
      <title>Probability distribution for type of newsday</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-demand-ex1.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Screenshot depicts Demand Tables tab of simulation worksheet with the cells B4 through C6 filled in with probability distribution for type of newsday.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure>
    
    <para>The next table is the daily demand for newspapers based on the type of news day.  The table Distribution of Newspapers Demanded is in cells A11 through D18 of the Demand Tables worksheet as shown in <xref linkend="table-analysis-simulation-daily-demand"/> and contains the daily demand distribution values.  The cumulative distribution tables in cells A21 through G29, shown in <xref linkend="table-analysis-simulation-cumulative-demand"/> are derived values from the Distribution of Newspapers Demanded using values in the top Distribution of Newspapers demanded table.</para>

    <table frame="all" id="table-analysis-simulation-daily-demand"> 
      <title>Daily newspaper demand distribution table in Demand Tables worksheet</title>
      <tgroup cols="4"><tbody>

      <row>
        <entry>
          <para/>
        </entry>
        <entry>
          <para><emphasis>A</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>B</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>C</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>D</emphasis></para>
        </entry>
      </row>

      <row>
        <entry>
          <para><emphasis>11</emphasis></para>
        </entry>
        <entry>
          <para>Demand</para>
        </entry>
        <entry>
          <para>Good</para>
        </entry>
        <entry>
          <para>Fair</para>
        </entry>
        <entry>
          <para>Poor</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>12</emphasis></para>
        </entry>
        <entry>
          <para>40</para>
        </entry>
        <entry>
          <para>0.03</para>
        </entry>
        <entry>
          <para>0.1</para>
        </entry>
        <entry>
          <para>0.44</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>13</emphasis></para>
        </entry>
        <entry>
          <para>50</para>
        </entry>
        <entry>
          <para>0.05</para>
        </entry>
        <entry>
          <para>0.18</para>
        </entry>
        <entry>
          <para>0.22</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>14</emphasis></para>
        </entry>
        <entry>
          <para>60</para>
        </entry>
        <entry>
          <para>0.15</para>
        </entry>
        <entry>
          <para>0.4</para>
        </entry>
        <entry>
          <para>0.16</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>15</emphasis></para>
        </entry>
        <entry>
          <para>70</para>
        </entry>
        <entry>
          <para>0.2</para>
        </entry>
        <entry>
          <para>0.2</para>
        </entry>
        <entry>
          <para>0.16</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>16</emphasis></para>
        </entry>
        <entry>
          <para>80</para>
        </entry>
        <entry>
          <para>0.35</para>
        </entry>
        <entry>
          <para>0.08</para>
        </entry>
        <entry>
          <para>0.06</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>17</emphasis></para>
        </entry>
        <entry>
          <para>90</para>
        </entry>
        <entry>
          <para>0.15</para>
        </entry>
        <entry>
          <para>0.04</para>
        </entry>
        <entry>
          <para>0</para>
        </entry>
      </row>
      <row>
        <entry>
          <para><emphasis>18</emphasis></para>
        </entry>
        <entry>
          <para>100</para>
        </entry>
        <entry>
          <para>0.07</para>
        </entry>
        <entry>
          <para>0</para>
        </entry>
        <entry>
          <para>0</para>
        </entry>
      </row>
    </tbody></tgroup>
    </table>

    
    <table frame="all" id="table-analysis-simulation-cumulative-demand"> <title>Cumulative demand distribution table in Demand Tables worksheet</title>
    <tgroup cols="8"><tbody>

      <row>
        <entry>
          <para/>
        </entry>
        <entry>
          <para><emphasis>A</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>B</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>C</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>D</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>E</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>F</emphasis></para>
        </entry>
        <entry>
          <para><emphasis>G</emphasis></para>
        </entry>
      </row>

  
      <row>
        <entry>
          <para><emphasis>21</emphasis></para>
        </entry>
        <entry>
          <para/>
        </entry>
        <entry>
          Cumulative Distribution
        </entry>
        <entry>
          <para/>
        </entry>
        <entry>
          <para/>
        </entry>
        <entry>
          <para>Values</para>
        </entry>
        <entry>
          <para/>
        </entry>
        <entry>
          <para/>
        </entry>
      </row>
  
      <row>
        <entry>
          <para><emphasis>22</emphasis></para>
        </entry>
        <entry>
          <para>Demand</para>
        </entry>
        <entry>
          <para>Good</para>
        </entry>
        <entry>
          <para>Fair</para>
        </entry>
        <entry>
          <para>Poor</para>
        </entry>
        <entry>
          <para>Good</para>
        </entry>
        <entry>
        <para>Fair</para>
        </entry>
        <entry>
          <para>Poor</para>
        </entry>    
      </row>
  
      <row>
        <entry>
          <para><emphasis>23</emphasis></para>
        </entry>
        <entry>
          <para>40</para>
        </entry>
        <entry>
          <para>0.03</para>
        </entry>
        <entry>
          <para>0.1</para>
        </entry>
        <entry>
          <para>0.44</para>
        </entry>
        <entry>
          <para>0</para>
        </entry>
        <entry>
        <para>0</para>
        </entry>
        <entry>
          <para>0</para>
        </entry>    
      </row>

      <row>
        <entry>
          <para><emphasis>24</emphasis></para>
        </entry>
        <entry>
          <para>50</para>
        </entry>
        <entry>
          <para>0.08</para>
        </entry>
        <entry>
          <para>0.28</para>
        </entry>
        <entry>
          <para>0.66</para>
        </entry>
        <entry>
          <para>0.03</para>
        </entry>
        <entry>
        <para>0.1</para>
        </entry>
        <entry>
          <para>0.44</para>
        </entry>
      </row>
  
      <row>
        <entry>
          <para><emphasis>25</emphasis></para>
        </entry>
        <entry>
          <para>60</para>
        </entry>
        <entry>
          <para>0.23</para>
        </entry>
        <entry>
          <para>0.68</para>
        </entry>
        <entry>
          <para>0.82</para>
        </entry>
        <entry>
          <para>0.08</para>
        </entry>
        <entry>
        <para>0.28</para>
        </entry>
        <entry>
          <para>0.66</para>
        </entry>
      </row>

      <row>
        <entry>
          <para><emphasis>26</emphasis></para>
        </entry>
        <entry>
          <para>70</para>
        </entry>
        <entry>
          <para>0.43</para>
        </entry>
        <entry>
          <para>0.88</para>
        </entry>
        <entry>
          <para>0.94</para>
        </entry>
        <entry>
          <para>0.23</para>
        </entry>
        <entry>
        <para>0.68</para>
        </entry>
        <entry>
          <para>0.82</para>
        </entry>
      </row>

      <row>
        <entry>
          <para><emphasis>27</emphasis></para>
        </entry>
        <entry>
          <para>80</para>
        </entry>
        <entry>
          <para>0.78</para>
        </entry>
        <entry>
          <para>0.96</para>
        </entry>
        <entry>
          <para>1</para>
        </entry>
        <entry>
          <para>0.43</para>
        </entry>
        <entry>
        <para>0.88</para>
        </entry>
        <entry>
          <para>0.94</para>
        </entry>
      </row>

      <row>
        <entry>
          <para><emphasis>28</emphasis></para>
        </entry>
        <entry>
          <para>90</para>
        </entry>
        <entry>
          <para>0.93</para>
        </entry>
        <entry>
          <para>1</para>
        </entry>
        <entry>
          <para></para>
        </entry>
        <entry>
          <para>0.78</para>
        </entry>
        <entry>
        <para>0.96</para>
        </entry>
        <entry>
          <para>1</para>
        </entry>
      </row>

      <row>
        <entry>
          <para><emphasis>29</emphasis></para>
        </entry>
        <entry>
          <para>100</para>
        </entry>
        <entry>
          <para>1</para>
        </entry>
        <entry>
          <para></para>
        </entry>
        <entry>
          <para></para>
        </entry>
        <entry>
          <para>0.93</para>
        </entry>
        <entry>
          <para>1</para>
        </entry>
        <entry>
          <para></para>
        </entry>
      </row>
    </tbody></tgroup>
    </table>
    
    <para>When these values are entered, the final results will look like <xref linkend="fig-simulation-example-daily-demand" />.</para>
    
    <figure id="fig-simulation-example-daily-demand">
      <title>Completed probability distribution tables in Demand Tables worksheet</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-demand-ex2.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Screenshot of Demand tab for the newsvendor example with probability distribution for type of newsday in cells A21 through G29.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure>
    
    <para>Finally, back in the Profit tab, the demand data will be filled in through the use of references to the Demand Tables tab as shown in <xref linkend="fig-simulation-example-profit-sheet" />. </para>

    <para>In the following cells, enter the equations below in the 'Profit' tab:</para>

    <itemizedlist>
      <listitem><para>B17: =rand()</para></listitem>
      <listitem><para>C17: =if(B17&lt;'Demand Tables'!C4,"Good",if(C19&lt;'Demand Tables'!C5,"Fair","Poor"))</para></listitem>
      <listitem><para>B18: =rand()</para></listitem>
      <listitem><para>B20: =lookup($C17,$B23:$D23,$B24:$D24)</para></listitem>
      <listitem><para>B21: =E12</para></listitem>
      <listitem><para>B24: =lookup(Profit!$B18,'Demand Tables'!E23:E29,'Demand Tables'!$A23:$A29)</para></listitem>
      <listitem><para>C24: =lookup(Profit!$B18,'Demand Tables'!F23:F29,'Demand Tables'!$A23:$A29)</para></listitem>
      <listitem><para>D24: =lookup(Profit!$B18,'Demand Tables'!G23:G29,'Demand Tables'!$A23:$A29)</para></listitem>
    </itemizedlist>
        
    <figure id="fig-simulation-example-profit-sheet">
      <title>Profit table for newsvendor example</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-profit-ex2.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              This screenshot depicts the profit sheet for the newsvendor example after references to demands are included in cells B17 through B21 and cells B24 through D24.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure>
    
    <para>When done, the Profit spreadsheet will be setup with a profit equation, decision variables, and random events as shown in <xref linkend="fig-simulation-example-profit-sheet" />.  The <function>rand()</function> functions in cells C17 and C18 return a random value between 0 and 1, which are used by the <function>lookup()</function> functions in cells B20, B24, C24 and D24 to calculate a randomly determined daily demand.  Next, this sheet will be used for analysis through the use of simulation.</para>
  </sect2>
  <sect2 id ="sect-advanced-analysis-simulation-running">
    <title>Running the simulation</title>
    <para>To run the simulation, from the Gnumeric toolbar, select Tools → Simulation.  In the Risk Simulation dialog box that appears, the first tab is the Variables tab.  There are two entries in the Variables tab:  Input variables and Output variables (<xref linkend="analysis-simulation-variables-dialog" />).</para>
    

    <figure id="analysis-simulation-variables-dialog">
      <title>Variables tab in simulation dialog box</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-variables-dialog.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Screenshot of the simulation dialog with input and output variables filled in for the newsvendor example.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure>    
    
    <para>Input variables are the cells which hold the functions based on random numbers of the type described in Section A.14.  In this case, they are the cells B17 and B18 in the Profit worksheet, which hold the rand() function.  Later, when the quantity purchased is a parameter set by the <function>SIMTABLE</function> function, cell B16 which holds the purchase quantity will be added to the range of input variables.</para>
    
    <para>Output variables are the results of interest, or the dependent variable.  In this case, the dependent variables are the demand and the profit, which are in cells B20 and B21.</para>
    
    <para>The next tab is the Options tab .  There are four settings in the options as shown in <xref linkend="fig-analysis-simulation-options-dialog" />. </para>
    
    <figure id="fig-analysis-simulation-options-dialog">
      <title>Options tab in Simulation dialog box for newsvendor simulation example</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-options-dialog.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Options tab in simulations dialog showing Rounds and number of iterations.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure> 
    
    <para>The second pair of options are the number of iterations and the Max time.  In a simulation, each iteration is the equivalent of a sample.  A sample from a random distribution is taken for each of the input values (as specified in the Variables tab) and the resulting output value(s).  The more iterations, the better the estimate of the output value.  However, this also takes more time to run.  A Max time value is specified in seconds where the simulation will end without output if an individual simulation takes longer then the Max time allotted.  If this occurs (see <xref linkend="fig-analysis-simulation-maximumtime-dialog" />), the options are to either increase the Max time value, or decrease the number of iterations.  A more drastic option is to change the model so that fewer calculations or samples of random numbers need to be made.</para>
    
    <figure id="fig-analysis-simulation-maximumtime-dialog">
      <title>Maximum time for simulation exceeded message box</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-maximumtime-dialog.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Dialog to warn that the maximum time for the simulation was exceeded.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure> 
    
    <para>The next tab is the Summary.  There are two boxes in this tab, the Simulation Summary and the Summary of results (see <xref linkend="fig-analysis-simulation-summary-dialog" />).  In simulation summary, there is a description of the simulation parameters.</para>
    
    <note> 
      <para>Due to the random nature of the simulation, the output may vary between simulation runs). </para>
    </note>
    
    <figure id="fig-analysis-simulation-summary-dialog">
      <title>Summary tab for simulation tool</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-summary-dialog.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
              Simulation summary tab inside of simulation dialog box including summary of simulation options and summary of results.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure> 
    
    <itemizedlist>
      <listitem><para>Simulations:  Number of rounds as determined in the Simulation Options box.
      </para></listitem>
      <listitem><para>
      Iterations:  Number of iterations in a single simulation round.
      </para></listitem>
      <listitem><para>
      # input variables:  Number of random numbers sampled for each iteration. 
      </para></listitem>
      <listitem><para># output variables:  Number of outputs recorded for simulation</para></listitem>
      <listitem><para>Runtime: Runtime of simulations in seconds.</para></listitem>
      <listitem><para>Run on: Date and time simulation was run.</para></listitem>
    </itemizedlist>

    <para>In the summary of results window, there are summary statistics for each round of the simulation.  If multiple rounds were done, the results of each round can be browsed by using the 'Prev. Sim.' and 'Next Sim.' buttons below the Summary of results box.  For each output and input variable, the summary shows the Min,  Average and the Max value across the iterations for that round of the simulation.  Note that for the input variables, this shows the random number that is the average, max and min.  If the statistics on intermediate values, such as a cost distribution, was desired, these intermediate values should be added to the list of output variables.</para>
    
    <para>The last tab is labeled 'Output'.  This tab identifies the location where the output table will be generated.  There are two sets of options, first the Output Placement then Output Formatting as shown in <xref linkend="fig-analysis-simulation-output-dialog" />.</para>
    
    <figure id="fig-analysis-simulation-output-dialog">
      <title>Output options tab for simulation</title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-output-dialog.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
            Output tab inside of simulation dialog box showing options for output placement and output formatting.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure> 
    
    <para>The default output placement is 'New sheet'.  This will create a new sheet in the Gnumeric workbook labeled 'Simulation Report (1)', where '1' can be replaced with another number if a tab labeled 'Simulation Report (1)' already exists.  The option 'New workbook' creates a Gnumeric workbook named 'Book2.gnumeric' with a tab labeled 'Simulation Report.'</para>
    
    <para>The third option is to embed the output table into an existing worksheet.  This is done by specifying the 'Output range'.  Note that the output range must be large enough to include the entire table, including heading information.  For a single round this requires 11 rows and 16 columns.  For example, the range Profit!A24:P35 would contain the statistics for one round with the three input variables and two output variables.  As input and output variables change, or the number of rounds of the simulation change, the number of rows required will change.</para>
    
    <para>For output formatting, their are four options.</para>

    <itemizedlist>
      <listitem><para>'Autofit columns' automatically makes each column long enough to include the largest entry in that column.  Note that column 'A' in the resulting spreadsheet used to save run information such as date and time and is kept narrow.</para></listitem>
      <listitem><para>'Clear output range' is in effect if the Output Placement option chosen is Output range.  It clears the selected cells in the spreadsheet before putting the output table in its place.</para></listitem>
      <listitem><para>'Retain output range formatting' retains formatting for cells such as number formatting.</para></listitem>
      <listitem><para>'Retain output range comments' retains comments that have been placed in output cells.  This is most useful when the input and output variables remained the same.</para></listitem>
    </itemizedlist>
    </sect2>
    <sect2 id="sect-advanced-analysis-simulation-output">
      <title>Simulation output</title>
      <para>The simulation output provides statistics on the output and input variables for each round.  The statistics are calculated over the iterations in a single round of the simulation.  These statistics for each variable are:</para>
      
      <itemizedlist>
        <listitem><para>Variable type and name - input variables are labeled as '(Input)'.</para></listitem>
        <listitem><para>Min – Minimum value of variable among iterations of round.</para></listitem>
        <listitem><para>Mean – Arithmetic mean of variable among iterations of round.</para></listitem>
        <listitem><para>Max – Maximum value of variable among all iterations of round.</para></listitem>
        <listitem><para>Median – Median of variable among iterations of round.</para></listitem>
        <listitem><para>Mode – Mode value among iterations of round.  For the input variable, this will be “#N/A”.</para></listitem>
        <listitem><para>Std. Dev. - Standard deviation of the variable.</para></listitem>
        <listitem><para>Variance – Second moment of variable.</para></listitem>
        <listitem><para>Skewness -  Third moment of variable.</para></listitem>
        <listitem><para>Kurtosis – Fourth moment of variable.</para></listitem>
        <listitem><para>Range – Difference between min and max of variable among iterations of the round.</para></listitem>
        <listitem><para>Count – Number of iterations in round.</para></listitem>
        <listitem><para>Confidence (95%) - 95% confidence interval of value, centered on mean.</para></listitem>
        <listitem><para>Lower Limit (95%) - Lower limit of 95% confidence interval of the value, centered on the mean.</para></listitem>
        <listitem><para>Upper Limit (95%) - Upper limit of 95% confidence interval of the value, centered on the mean.</para></listitem>
      </itemizedlist>
      
			
      <figure id="fig-analysis-simulation-report-screen">
        <title>Simulation output example</title>
        <screenshot>
          <mediaobject>
            <imageobject>
                <imagedata fileref="figures/analysis-simulation-report-screen.png" format="PNG" />
            </imageobject>
            <textobject>
              <para>
              Simulation output spreadsheet including input and output variable statistics.
              </para>
            </textobject>
          </mediaobject>
        </screenshot>
      </figure> 
      
      <para>The output will include a heading, then a table for each round of the simulation.  Judicious choice of output variables will also include any intermediate values of interest in the simulation in this table.  Each row of the output table has statistics of the values of a variable over the iterations of the simulation as shown in <xref linkend="fig-analysis-simulation-report-screen"/>. </para>
      
      <para>The output will be of the input variables and the output variables that were variables tab of the Simulation window .  For the input variables, the output will be the statistics of the random variable used in modeling the input variables.  For the output variables, the statistics will be of the output variable.  These statistics, in particular the standard deviation and confidence interval, should be examined to ensure the simulation was at a precision adequate for the purpose.  Some notes on how to use these statistics for refining the simulation design can be found in <xref linkend="sect-advanced-analysis-simulation-iterations"/>. </para>

    </sect2>
  <sect2 id="sect-advanced-analysis-simulation-simtable">
    <title>Using SIMTABLE</title>
    
    <para>The <function>SIMTABLE</function> function is intended to change a variable in the simulation so that each round of the simulation can be used to evaluate a different scenario.  This automates the use of simulation for what-if questions or to create a set of possible outcomes to a situation.</para>
    
    <para>In this example, we will use the <function>SIMTABLE</function> function to find the optimal quantity of newspapers to buy.  For the purchase quantity in our spreadsheet, we will replace '50' with the following formula in Profit!B16:</para>
    
    <programlisting>
    Profit!B16 = SIMTABLE(50,60,70,80,90)
    </programlisting>
      
    <para>Each entry in the list of the <function>SIMTABLE</function> arguments is a value that will be used for the purchased quantity.  Each entry corresponds to one round of simulation, as used in <xref linkend="fig-analysis-simulation-options-dialog" />.  In this example there are 5 entries to the SIMTABLE list, so '5' will be entered into the 'Last Round #' option in the Options tab of the Simulation dialog. </para>
    
    <figure id="fig-analysis-simulation-simtable-screen">
      <title>Simulation output example using SIMTABLE and several rounds </title>
      <screenshot>
        <mediaobject>
          <imageobject>
              <imagedata fileref="figures/analysis-simulation-simtable-screen.png" format="PNG" />
          </imageobject>
          <textobject>
            <para>
            Simulation output example using SIMTABLE and several rounds.
            </para>
          </textobject>
        </mediaobject>
      </screenshot>
    </figure> 
    
    <para>When this simulation is run with 5 rounds, the summary of results  will have one entry for each round, with each round using a different entry from the <function>SIMTABLE</function> function for the purchase quantity.  The results for the various rounds can be previewed using the 'Prev. Sim.' and 'Next Sim.' buttons.  The output also has one table for each round of the simulation.</para>
    
    <para>As seen in <xref linkend="fig-analysis-simulation-simtable-screen" />, each value in the original SIMTABLE statement corresponds to a simulation round, with the Purchase Quantity taking on the value from the SIMTABLE list.  The analyst can then record the Profit statistics (mean, variance, skewness, kurtosis, 95% confidence intervals) and determine if the simulation results are of sufficient resolution for the analysts purposes.</para>
    
    <para>The use of SIMTABLE to change parameters within the simulation provides a convenient method to do what-if analysis, and analyze the results as a whole.</para>
  </sect2>
  
  <sect2 id="sect-advanced-analysis-simulation-iterations">
    <title>Determining the number of iterations</title>
    
    <para>In simulation, one major question is how many iterations are needed to reach a chosen level of precision in the results.  Simulation as a tool provides an approximation of the actual relationship between the input and output variables.  The precision of the approximation is based on the number of iterations of the simulation done.   More iterations in the sample lead to greater precision.  But the relationship between iterations and precision depends on the relationship between the variables in the precision.  In addition, the analyst must decide which output variable is the variable of interest, and what degree of precision is required.  The next step is to determine a sufficiently large number of iterations
      <inlineequation>
        <alt>$R$</alt>
        <mathphrase>R</mathphrase>
      </inlineequation> 
    be used to satisfy:    
    <informalequation>
      <alt>\[ P\left(\left|\left(\widehat{\Theta}-\Theta\right)\right| \leq \epsilon \right) \geq 1-\alpha \]</alt>
      <mediaobject>
        <imageobject>
          <imagedata fileref="figures/analysis-simulation-confidence-interval-equation.png"/>
        </imageobject>
        <textobject>
          <para>The probability that the difference between the actual mean and the sample mean is less than epsilon is 1 - alpha.</para>
        </textobject>
      </mediaobject>
    </informalequation>
    </para>		
    <para>Where 
    <inlineequation> 
      <alt>$\widehat{\Theta}$ </alt>
      <mathphrase>&THgr;-hat</mathphrase>
    </inlineequation> is the estimate of the mean, 
    <inlineequation>
      <alt>$\Theta$</alt>
      <mathphrase>&THgr;</mathphrase>
    </inlineequation> is the actual mean, &egr; is the specified error, and (1-&agr;) is the probability that the estimate is within &egr; of the actual value (i.e. the (1-&agr;) confidence interval). 
    Common values of (1-&agr;) are 95% and 99%. 
    The Simulation Report from Gnumeric includes values for the 95% confidence interval as shown in <xref linkend="fig-analysis-simulation-report-screen" />.
		</para>
		
    <para>The general procedure is as follows:<footnote>
    <para>Adapted from Banks et. al. Discrete-Event System Simulation, 3rd Edition, pp. 414-416.</para>
    </footnote>
    </para>
		
    <orderedlist>
    <listitem><para>Run simulation for a sample of
    <inlineequation>
      <alt>$R_0$</alt>
      <mathphrase> R<subscript>0</subscript></mathphrase>
    </inlineequation> iterations. 
    The default value in Gnumeric is 1000, set in the options tab of the Simulation menu, <xref linkend="fig-analysis-simulation-options-dialog"/>. </para></listitem>
    <listitem><para>Take the sample variance
    <inlineequation>
      <alt>$S_0^2$</alt>
      <mathphrase> S<subscript>0</subscript><superscript>2</superscript></mathphrase>
    </inlineequation> from the simulation output spreadsheet and determine the sample standard deviation 
    <inlineequation>
      <alt>$S_0$</alt>
      <mathphrase> S<subscript>0</subscript></mathphrase>
    </inlineequation>
    (see <xref linkend="fig-analysis-simulation-report-screen" />). </para></listitem>
    
    <listitem><para>Using
    <inlineequation>
      <alt>$z_{\alpha/2}$</alt>
      <mathphrase>z<subscript>&agr;/2</subscript></mathphrase>
    </inlineequation>
    as the z-value of the 
    <inlineequation>
      <alt>$(1-(\alpha/2))$</alt>
      <mathphrase>(1-(&agr;/2))</mathphrase>
    </inlineequation> percentile of the standard normal distribution, set the initial estimate of the number of iterations required as the smallest integer 
    <inlineequation>
      <alt> $R$</alt>
      <mathphrase>R</mathphrase>
    </inlineequation> 
    such that 
    <equation><title>Iterations required for simulation</title>
      <alt> $R \geq \left(\frac{z_{\alpha/2}S_0}{\epsilon}\right)^2$</alt>
      <mediaobject>
        <imageobject>
          <imagedata fileref="figures/analysis-simulation-interations-equation1.png" format="PNG"/>
        </imageobject>
        <textobject>
          <para> R is greater than equal to z of alpha divided by 2, times standard deviation, divided by epsilon.  Quantity squared.
          </para>
        </textobject>
      </mediaobject>
    </equation>.  Note that if 
    <inlineequation>
      <alt> $R_0$ </alt>
      <mathphrase>R<subscript>0</subscript></mathphrase>
    </inlineequation> is small, it would be more appropriate to use the student's t-distribution of 
    <inlineequation>
      <alt> $t_{\alpha/2, R_0}$ </alt> 
      <mathphrase>t<subscript>&agr;/2, R<subscript>0</subscript></subscript></mathphrase>
    </inlineequation> instead of  
    <inlineequation>
      <alt> $z_{\alpha/2}$</alt>
      <mathphrase>z<subscript>&agr;/2</subscript></mathphrase>
    </inlineequation>.
    </para></listitem>
    
    </orderedlist>
    
    <para>In this example, to estimate the profit to within
      <inlineequation>
        <alt>$\epsilon = 0.05$</alt>
        <mathphrase>&egr;=0.05</mathphrase>
      </inlineequation>
        , first run the simulation with 1000 iterations and a purchase quantity of 50 results in the following </para>

    <para>
      <informaltable frame="all">
      <tgroup cols="4"><tbody>
      <row>
      <entry>
      <para/>
      </entry>
      <entry>
      <para>Mean</para>
      </entry>
      <entry>
      <para>Variance</para>
      </entry>
      <entry>
      <para>Confidence (95%)</para>
      </entry>
      </row>
      <row>
      <entry>
      <para>Demand QUANTITY</para>
      </entry>
      <entry>
      <para>59.19</para>
      </entry>
      <entry>
      <para>152.4</para>
      </entry>
      <entry>
      <para>0.64</para>
      </entry>
      </row>
      <row>
      <entry>
      <para>Profit QUANTITY</para>
      </entry>
      <entry>
      <para>7.85</para>
      </entry>
      <entry>
      <para>2.51</para>
      </entry>
      <entry>
      <para>0.08</para>
      </entry>
      </row></tbody></tgroup>
      </informaltable>
    </para>
    <para/>
		
    <para>Taking the variance of the table, and setting
      <inlineequation>
        <alt>$\epsilon = 0.05$</alt>
        <mathphrase>&egr;=0.05</mathphrase>
      </inlineequation>
      and 
      <inlineequation>
        <alt>$\alpha = 0.05$</alt>
        <mathphrase>&agr;=0.05</mathphrase>
      </inlineequation>, lookup 
      <inlineequation>
        <alt>$z_{\alpha/2}$</alt> 
        <mathphrase>z<subscript>&agr;/2</subscript></mathphrase>
      </inlineequation> from a standard normal table.  
      <inlineequation>
        <alt>$z_{\alpha/2}=1.96$</alt>
        <mathphrase>z<subscript>&agr;/2=1.96</subscript></mathphrase>
      </inlineequation> so we have</para>
    <para/>  
    <para>
    <informalequation>
      <alt> $R \geq \left(\frac{1.96 \times \sqrt{2.51}}{0.05}\right)^2 \geq 3856.8$</alt> 
      <graphic fileref="figures/analysis-simulation-interations-equation2.png"/>
    </informalequation>.
    </para>
    <para/>
    <para>Therefore, the minimum number of iterations is 3857.  The simulation can then be re-run with 3857 iterations to create a 95% c.i for profit where 
    <inlineequation>
      <alt>$\epsilon \leq 0.05$ </alt>
      <mathphrase>&egr; &lt;=0.05</mathphrase>
    </inlineequation>
         
    In this example with 3857 iterations, we get the following Simulation Report table: </para>
    <para/>
    <informaltable frame="all">
    <tgroup cols="4"><tbody>
    <row>
    <entry>
    <para/>
    </entry>
    <entry>
    <para>Mean</para>
    </entry>
    <entry>
    <para>Variance</para>
    </entry>
    <entry>
    <para>Confidence (95%)</para>
    </entry>
    </row>
    <row>
    <entry>
    <para>Demand QUANTITY</para>
    </entry>
    <entry>
    <para>59.11</para>
    </entry>
    <entry>
    <para>163.9</para>
    </entry>
    <entry>
    <para>0.34</para>
    </entry>
    </row>
    <row>
    <entry>
    <para>Profit QUANTITY</para>
    </entry>
    <entry>
    <para>7.72</para>
    </entry>
    <entry>
    <para>2.88</para>
    </entry>
    <entry>
    <para>0.04</para>
    </entry>
    </row></tbody></tgroup>
    </informaltable>
    <para/>
    <para>As expected, the 95% Confidence interval for Profit is less than 0.05. For the newsvendor example, the next step would be to look at the confidence intervals of the profit for all values of purchase quantity, and verify that this confidence interval is adequate for the decision to be made.  </para>
    <para/>
  <para/></sect2>
</sect1>