A particular type of lamp filament is known to have a life time that is a random quantity with an exponential distribution. The true mean lifetime of the filaments is known to be 1,000 hours.
Simulate a random sample of 100 such lamp filaments by placing
100 values, drawn randomly from an exponential distribution of
mean
On the main menu bar, click on "Calc". Then place the cursor over "Random Data". Then click on "Exponential...". |
![]() |
Click in the box next to
"Generate".
Type 100
Click in the box under "Store in column(s):"
(or just press the Tab
key).
Type C1
Click in the box next to "Scale:"
(or just press the Tab
key).
Type 1000
.
Leave the "Threshold:" box at its default value of
zero.
[The "Threshold:" parameter is the lowest possible
value, which is also the mode for an exponential distribution.]
Click the "OK" button.
Give column [Note that your values will not be identical to the values
that you see here. As the sorted version of these data will appear in column
|
![]() |
(Don’t forget to save your work often!)
A data sheet can be renamed from the default "Worksheet 1" to a more meaningful name in Minitab’s Project Manager.
One way to access the appropriate part of the Project Manager is to click on the "Show Worksheets Folder" icon.
Another way is to summon the Project Manager to the top of the stack of Windows through the "Window" menu (or through the equivalent keystroke
|
![]() |
In the left pane of the Project
Manager, right-click on "Worksheet 1".
In the resulting pop-up menu, click on "Rename".
Type the new name for the worksheet
and press Enter
.
![]() |
The data sheet has now been renamed. |
Although this step is not required by the problem specification, let us sort the data into ascending order.
![]() |
On the main menu bar, click on "Data". Then click on "Sort...". |
In the left pane, double-click
on the variable name for column " Expand the drop down menu for the " Click in the new pane " Expand the drop down menu for the Click in the new pane " The dialog box should now look like this.
Click on the "OK" button. |
![]() |
The sorted version of your data should now be in the second column of your Data window. [Again, your values won’t match the values that you see here!] Note that values in the cells of the Data window are rounded
to two decimal places. In Minitab 14 the active cell,
(row 1
column Through a menu that pops up upon right-clicking on a cell, one can force Minitab to display more or fewer decimal places. |
On the main menu bar, click on "Stat". Then place the cursor over "Basic Statistics". Then click on "Display Descriptive Statistics...". |
![]() |
![]() |
In the left pane, double click on either variable name. It appears in the top right box. [If you wish to change which items are displayed in the summary statistics, then click on the "Statistics..." button, check the boxes for the desired items and uncheck the other boxes.] Then click on the "Graphs..." button. |
Check the boxes beside Then click on the "OK" button for this window. Click on the other "OK" button. |
![]() |
These statistics appear in the Session window.
Two other windows have appeared.
The default boxplot shows four outliers (all more than one and a half
interquartile ranges above the upper quartile and some of them more
than three interquartile ranges above the upper quartile) and a
pronounced positive skew:
Again, by double-clicking on the graph, one can modify various features (not demonstrated here).
The default histogram incorporates many of our other results:
The random sample illustrated here came from an exponentially distributed population with a true mean of 1,000 hours. Yet the sample mean is over 1,150 hours. A good batch, perhaps, but not that unlikely to have occurred by chance, (as we shall be able to prove, after we have studied continuous probability distributions).
The distribution of the sample is clearly inconsistent with a normal distribution (the red bell shaped curve). This is no surprise, as the true exponential distribution is strongly non-normal.
The positive skew is so strong that, although the sample mean lamp filament lifetime is about 1,150 hours, half of all of the lamp filaments in this sample burned out in less than 730 hours!
We require a true histogram (where the area, not the height, of each bar represents the frequency in that interval), with seven to twelve equal-width bars spanning most of the range (0, 5500).
Bar widths of 500, starting at 0, are ideal.
Rather than starting from scratch, let us modify the
default histogram.
Double click on any number by the vertical axis.
On the "Edit Scale" dialog box: Click on the third tab "Type"; Click the third radio button "Density"; and click the "OK" button. |
![]() |
Back on the histogram, double click on any number by the horizontal axis.
![]() |
On the "Edit Scale" dialog box: Click on the third tab "Binning". In the upper group, In the lower group, In the text box, enter values, Click the "OK" button. |
If you wish, you may also modify the visual appearance of the bars. Double-click inside any bar. On the first tab "Attributes" of the "Edit Bars" dialog box, click the respective "Custom" radio buttons |
![]() |
Here is one version of the modified histogram:
You can copy and paste the above results into your Report Pad.
Then save your work and exit.
On the main menu bar, click on
"File". Minitab will give you a last chance to save the active project. A new project will then open, |
![]() |
Copy the following block of text and paste it into a blank
document in a word processor (even Notepad will suffice).
It is also available as a separate file at
this link, (with a file name
"Coins.txt" instead of "Coins.mac",
because programs such as QuickTime insist on hijacking the
".mac" extension for image files instead of plain
text Minitab macros).
gmacro Coins ### Simulation to illustrate the evolution of the relative frequency of ### heads as a fair coin is tossed many times. The relative frequency ### estimates the exact probability of 1/2 . ### Execute this macro in a blank Minitab project. ### Macro created 2003 03 14 and last modified 2010 03 09 by G.H. George erase c1-c3 # needed to ensure clear space in the worksheet ### Constants: ### k1 = coin index number (loop counter) let k2 = 1500 # number of coins let k3 = 0 # accumulator = number of heads in the first k1 coins ### Columns: name c1 'trial' # number of coin tosses so far name c2 'head?' # = 1 if this coin is a head, = 0 if a tail name c3 'Rel.Freq.' # proportion of heads so far ### Place the first (k2) natural numbers into column c1: set c1 1:k2 end. ### assign 0 (tail), 1 (head) randomly to the k2 coins: random k2 c2; integer 0 1. ### toss the coin k2 times, recording number & proportion of heads so far: do k1=1:k2 let k3 = k3 + c2(k1) let c3(k1)=k3/k1 enddo let k1 = c3(k2) note The last estimated probability of a head is print k1 note Compare this with the true probability of 0.500000 ### Plot the relative frequency as a time series plot: Tsplot 'Rel.Freq.'; Scale 2; MODEL 1; Tick 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7; Min 0.3; Max 0.7; EndMODEL; AxLabel 1; ADisplay 1; Label "# coins"; ALevel 1; Index; Connect; Symbol; Type 0; Size 0.7; Grid 2; Title "ENGI 4421 Empirical Probability"; SubTitle "Coin Tossing Experiment"; Footnote; FPanel; NoDTitle. endmacro
If you are using the computers in EN 3000/3029, then save the
file on your Labnet account or on a USB stick, (using the
file name "Coins.mac
").
If you have a copy of Minitab on your own computer, then save the
file in your Minitab Macros directory, (on some computers,
it is at
"C:/Program Files (x86)/Minitab/Minitab 18/English/Macros/
"),
with the name "Coins.mac
".
Ensure that there are no spaces in the file name or in any directory names
in the path.
Minitab does not like spaces in macro file names!
If the file is in a directory such as "My Documents
",
then Minitab will not be able to find it.
By default, Windows / Notepad insists on appending a hidden
extension ".txt
" to the name of
your newly-created macro file.
However, Minitab recognizes only files whose names end with
".mac
" to be macro files.
To escape from this problem,
in Windows 7 or 10:
open Windows Explorer,
go to the directory where your file is located,
click on the item "Organize
" in the
menu bar at the top, click on the item in the drop
down menu, "Folder and search options
",
in the resulting dialog box,
click on the "View
" tab and, in
the "Advanced settings:
" pane,
ensure that the option "Hide
extensions for known file types
" is
not checked.
Click "Apply
"
then "OK
".
Now inspect the name of your file.
If it ends in ".txt
", then
right-click on the file name and rename it to
"Coins.mac
".
The main alternative is to enclose the macro’s filename
in double quotes in the "File name
" field
of the "Save As
" dialog box,
every time that you wish to save a macro file.
The first two lines of most Minitab global macros are
gmacro macroNameand the last line is
endmacro
The line indentation and blank lines are not required.
However, as is the case with any type of computer program,
a macro is much easier to read if these style conventions are
employed.
The comment symbol ("//
" in C++ and
"'
" in Visual Basic) is the hash mark
#
in a Minitab macro.
All text following #
in a line is ignored by
Minitab, (even inside an input prompt or output string).
If you want other readers to know how your macro
achieves its objectives, then make good use of comments.
To give a name to a column, use the structure
name cn 'NameOfColumn'where
n
is the number of the column in the
worksheet in the Data window.
Before naming a column or entering data into it, check if your algorithm requires any existing data to be cleared first. That will be the case here, if the same macro is called a second time inside the same project. The command to clear a range of columns is
erase cm-cn
To output a literal string, use the keyword
note
.
On a line that starts with note
, all text following
on that line, (up to the first #
, if any), will
appear in the Session window exactly as is.
To print the values of constants in the session window, use
print knColumns appear automatically in the spreadsheet in the Data window.
The principle loop structure (essentially a FOR-NEXT loop with unit step size) is
do k1=k2:k3 statements enddo
This macro needs no input at all from the user.
If you do wish your macro to accept input, then
input from the keyboard uses the structure
set cn;
file "terminal";
nobs 1.
The semicolon ";
" indicates that the Minitab
command is not complete and continues with subcommands on the next
line, while the period ".
" closes the
command.
In principle, more than one datum can be input in the same keyboard
response, (separated by a space). In that case the number of
data replaces the "1" in
"nobs 1.
".
However, it is usually safer to ask the user to input the data
one item at a time and to use the note
method to
prompt the user.
Also note how data may be entered directly from the keyboard only
into a worksheet column, not into a constant. Input data may
be copied into a constant using the structure
copy cm kn
where m and n are positive integers.
The lengthy block of command and subcommands
### Plot the relative frequency as a time series plot: Tsplot 'Rel.Freq.'; Scale 2; MODEL 1; Tick 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7; Min 0.3; Max 0.7; EndMODEL; AxLabel 1; ADisplay 1; Label "# coins"; ALevel 1; Index; Connect; Symbol; Type 0; Size 0.7; Grid 2; Title "ENGI 4421 Empirical Probability"; SubTitle "Coin Tossing Experiment"; Footnote; FPanel; NoDTitle.produces a time series plot similar to this
The subcommands were not generated directly.
Instead, the graphical interface of Minitab 14 was used, as illustrated
in this separate web page, to generate
a plot from data placed in column c3
(named
'Rel.Freq.'
) by the preceding part of the macro.
Start Minitab.
Click anywhere on the Session window to ensure that it is the active
window.
On the main menu bar, click on "Editor".
If the MTB>
prompt is not present on the right edge of the
session window,
then click on "Show Command Line".
This step is necessary in order to invoke macros and to enter data from the keyboard directly into the Session window.
The Minitab prompt then |
![]() |
![]() |
In the Command Line pane of the Session window type
" [By default, Minitab searches for macros in its own directory
on the |
The results now appear.
They will usually be slightly different with each run.
You can copy and paste the above results into your Report Pad.
Then save your work and exit.
The next example of the simulation of empirical probability is the famous “birthday problem”: If n randomly chosen people are in a room, then what is the probability that at least two of them will share the same birthday?
Copy the following block of text and paste it into a blank document in a word processor (even Notepad will suffice).
gmacro Birthdays ### Simulation to estimate the probability that at least two of (k1) people ### in a room will share a birthday. The lowest (k1) for which the exact ### probability exceeds 1/2 is k1 = 23 . ### Macro created 2003 03 10 and last modified 2003 03 12 by G.H. George erase c1-c8 # needed to ensure clear space in the worksheet ### Constants: ### k1 = number of people in the room ### k2 = number of trials ### k3 = trial index number (loop counter) ### k4 = relative frequency of shared birthdays ### Columns: name c1 'birthdays' # birthdays of the (k1) people in this trial name c2 'ranks' # ranks of birthday data in this trial name c3 'no ties' # ranks if no ties (1 to #people) name c4 'diff.' # abs.diff. of ranks with and without ties in this trial name c5 'num.shared' # number of duplicates found in each trial name c6 'shared?' # = 1 if any duplicates found, 0 if none found, for each trial name c7 'num.people' # temporary column for input of k1 name c8 'num.trials' # temporary column for input of k2 ### Note that keyboard data entry must be into columns, not constants: note Enter number of people: set c7; file "terminal"; nobs 1. copy c7 k1 note Enter number of trials: set c8; file "terminal"; nobs 1. copy c8 k2 ### Place the first (k1) natural numbers into column c3: set c3 1:k1 end. do k3=1:k2 # conduct the k2 simulations random k1 c1; integer 1 365. # assign random birthdays to the k1 people in this trial sort c1 c1 # sort the birthdays into ascending order rank c1 c2 let c4=abs(c2-c3) # zero unless shared birthdays are present in this trial let c5(k3)=sum(c4) enddo ### Each entry of c6 is 1 (true) if the corresponding entry of c5 is positive, ### 0 (false) otherwise: let c6=(c5>0) let k4=sum(c6)/k2 note The estimated probability that at least two people share the same birthday is print k4 note Compare this with the true probability note p = 1 - (365! / {(365-Num.people)!*(365)^(Num.people)}) note (approximately 0.507 for 23 people) endmacro
Save the file as "h:/Birthdays.mac
"
(or "d:/Birthdays.mac
").
If you have Minitab installed on your computer, then
save the macro in your Minitab Macros directory, (on some computers,
it is at
"C:/Program Files (x86)/Minitab/Minitab 18/English/Macros/
"),
with the name "Birthdays.mac
".
Most of the details of this macro are explained by inline comments in the listing above. One feature deserves additional comment here: the trick used to detect equal values in a column of data.
Use the "rank
" command to create a
column showing the ranks of all entries in the column of
(birthdays sorted into ascending order).
The n ranks will be exactly the first n natural
numbers, unless any ties exist (that is, shared birthdays).
The sum of the absolute differences between the corresponding
entries in the ranks column (c2
) and the column
containing the first n natural numbers (c3
)
will be zero if there are no ties,
but positive if there are one or more ties. This
part of the algorithm is implemented in the lines inside the
do
loop
sort c1 c1 # sort the birthdays into ascending order rank c1 c2 let c4=abs(c2-c3) # zero unless shared birthdays are present in this trial let c5(k3)=sum(c4)Each entry in the column
c6
represents the result of one
simulation. Its value is 1 if any ties were detected and 0 if
not. By adding up all entries in that column, the total
frequency of shared birthdays is calculated.
Start Minitab.
Click anywhere on the Session window to ensure that it is the active
window.
On the main menu bar, click on "Editor".
If the MTB>
prompt is not present on the right edge of the
session window,
then click on "Show Command Line".
This step is necessary in order to invoke macros and to enter data from the keyboard directly into the Session window.
The Minitab prompt then |
![]() |
![]() |
In the Command Line pane of the Session window type
" |
Respond to the first prompt for data.
Note how the first eight columns of the Worksheet have now been named.
Respond to the second |
![]() |
The results
now appear.
They will usually be slightly different with each run.
A major advantage of the macro is that you can repeat this long
sequence of commands by simply retyping
"%d:/Birthdays
" at the Minitab prompt and
entering values again for the number of people in each room and
the number of rooms.
You can copy and paste the above results into your Report Pad.
Then save your work and exit.
A JavaScript simulation is also available.