Environmental Stochasticity: Roc Flu Macro

Similar documents
Try what you learned (and some new things too)

Assignment 5 due Monday, May 7

Graphs and Charts: Creating the Football Field Valuation Graph

Microsoft Excel Lab Two (Completed 03/02/18) Transcript by Rev.com. Page 1 of 6

PowerPoint Pro: Grouping and Aligning Objects

Spreadsheets 3: Charts and Graphs

The Slide Master and Sections for Organization: Inserting, Deleting, and Moving Around Slides and Sections

Microsoft Excel Lab Three (Completed 03/02/18) Transcript by Rev.com. Page 1 of 5

Term Definition Introduced in: Tab(s) along the ribbon that show additional programs or features (e.g. Acrobat )

The lump sum amount that a series of future payments is worth now; used to calculate loan payments; also known as present value function Module 3

QUICKSTART COURSE - MODULE 7 PART 3

Hello and welcome to the CPA Australia podcast. Your weekly source of business, leadership, and public practice accounting information.

BEST PRACTICES COURSE WEEK 14 PART 2 Advanced Mouse Constraints and the Control Box

Excel Tool: Plots of Data Sets

Excel Lab 2: Plots of Data Sets

Blend Photos Like a Hollywood Movie Poster

Formulas: Index, Match, and Indirect

NCSS Statistical Software

7-1-The_Best_Practices_Course--Week_7--Part_1--Interactive_Legends_Part_1

CHM 109 Excel Refresher Exercise adapted from Dr. C. Bender s exercise

How to Make a Run Chart in Excel

1 Best Practices Course Week 12 Part 2 copyright 2012 by Eric Bobrow. BEST PRACTICES COURSE WEEK 12 PART 2 Program Planning Areas and Lists of Spaces

EXERCISE 1: CREATE LINE SPARKLINES

dotted line kind of in the middle of my screen. And what that dotted line represents is where the page ends. Ok, so that s the very end of my page.

Student Hub Live interface guide transcript

Excel Manual X Axis Scales 2010 Graph Two X-

UNIT TWO: Data for Simple Calculations. Enter and format a title Modify font style and size Enter column headings Move data Edit data

Step 1: Set up the variables AB Design. Use the top cells to label the variables that will be displayed on the X and Y axes of the graph

Graphing with Excel. Data Table

QUICKSTART COURSE - MODULE 1 PART 2

Excel Manual X Axis Scale Start At Graph

Proven Performance Inventory

Excel Manual Page Breaks Don't Work

MATHEMATICAL FUNCTIONS AND GRAPHS

copyright Karen Hinrichs, 2011 all rights reserved Adding Stops and Stitches Page 1 of 5 Adding Stops and Stitches to make Applique from Ordinary

CHM 152 Lab 1: Plotting with Excel updated: May 2011

Module All You Ever Need to Know About The Displace Filter

Annex IV - Stencyl Tutorial

MITOCW R22. Dynamic Programming: Dance Dance Revolution

COMPUTING CURRICULUM TOOLKIT

AP Art History Flashcards Program

Okay, that s enough talking. Let s get things started. Here s the photo I m going to be using in this tutorial: The original photo.

Excel 2016 Cell referencing and AutoFill

Autodesk University See What You Want to See in Revit 2016

Instructor (Mehran Sahami):

Office 2016 Excel Basics 24 Video/Class Project #36 Excel Basics 24: Visualize Quantitative Data with Excel Charts. No Chart Junk!!!

MITOCW watch?v=fp7usgx_cvm

MITOCW R3. Document Distance, Insertion and Merge Sort

Excel 2003: Discos. 1. Open Excel. 2. Create Choose a new worksheet and save the file to your area calling it: Disco.xls

Comparing Across Categories Part of a Series of Tutorials on using Google Sheets to work with data for making charts in Venngage

Physics 253 Fundamental Physics Mechanic, September 9, Lab #2 Plotting with Excel: The Air Slide

How to make a pattern for a simple shirt with Seamly2D

Appendix 3 - Using A Spreadsheet for Data Analysis

AutoCAD 2018 Fundamentals

Autodesk University Automated Programming with FeatureCAM

MITOCW watch?v=ir6fuycni5a

OKAY. TODAY WE WANT TO START OFF AND TALK A LITTLE BIT ABOUT THIS MODEL THAT WE TALKED ABOUT BEFORE, BUT NOW WE'LL GIVE IT A

Quilt Pro 6 Lesson Quilt in a Quilt

PivotTables PivotCharts (Chapter 5)

Excel Manual X Axis Label Below Chart 2010 >>>CLICK HERE<<<

MITOCW R7. Comparison Sort, Counting and Radix Sort

BEST PRACTICES COURSE WEEK 21 Creating and Customizing Library Parts PART 7 - Custom Doors and Windows

Lab 15: EXL3 Microsoft Excel s AutoFill Tool, Multiple Worksheets, Charts and Conditional Formatting

ArchiCAD Tutorial: How to Trace 2D Drawings to Quickly Create a 3D Model

How to make a pattern for a simple shirt with Valentina / Seamly2D

Scratch for Beginners Workbook

Term Definition Introduced in:

Autodesk University Automating Plumbing Design in Revit

Introduction. The basics

Advanced Excel. Table of Contents. Lesson 3 Solver

Photoshop Backgrounds: Turn Any Photo Into A Background

An Introduction to Programming using the NXT Robot:

Chapter 2. The Excel functions, Excel Analysis ToolPak Add-ins or Excel PHStat2 Add-ins needed to create frequency distributions are:

Laboratory 1: Motion in One Dimension

Easily Smooth And Soften Skin In A Photo With Photoshop

Welcome to our first of webinars that we will. be hosting this Fall semester of Our first one

Add Rays Of Sunlight To A Photo With Photoshop

1 of 14. Lesson 2 MORE TOOLS, POLYGONS, ROOF. Updated Sept. 15, By Jytte Christrup.

I'm going to set the timer just so Teacher doesn't lose track.

AutoCAD 2D. Table of Contents. Lesson 1 Getting Started

Overview. The Game Idea

Clickteam Fusion 2.5 [Fastloops ForEach Loops] - Guide

Plotting scientific data in MS Excel 2003/2004

AutoCAD 2020 Fundamentals

MITOCW ocw lec11

The D70 only controls one external group of flashes. You can use many external flashes, but they will fire at the same power.

Car Ad Photoshop Tutorial Miss Van Lenten Tools: Paint brush, Eraser, Quick Selection/Magic Wand, Quick Mask, Layer Mask

Building a Chart Using Trick or Treat Data a step by step guide By Jeffrey A. Shaffer

BEST PRACTICES COURSE WEEK 26 In-Office Project Management - Part 1 - Redlines and the Markup Palette

Autodesk University Advanced Topics Using the Sheet Set Manager in AutoCAD

SCRAPENDIPITY Designs. Electric Quilt 7 Tutorial. Building a Quilt

SolidWorks 95 User s Guide

Vectorworks / MiniCAD Tutorials

Freezer Paper Piecing with Tara Faughnan

Chapter 2: PRESENTING DATA GRAPHICALLY

Game Design Curriculum Multimedia Fusion 2. Created by Rahul Khurana. Copyright, VisionTech Camps & Classes

Honors Chemistry Summer Assignment

How to define Graph in HDSME

Quilt-Pro 6. Creating a Panel Quilt

Moving Man Introduction Motion in 1 Direction

Transcription:

POPULATION MODELS Environmental Stochasticity: Roc Flu Macro Terri Donovan recorded: January, 2010 All right - let's take a look at how you would use a spreadsheet to go ahead and do many, many, many simulations of the roc flu problem. As we've said, pressing F9 gives you one scenario, one result of many, many potential results. And what you're most interested in, in this problems with stochasticity, is running many, many replicates of a particular model. And then summarizing the results so you get a feel for what's the range of values that are possible and also what are the most likely outcomes that are possible. And so we're going to do that by using the Macro function in Excel. And this is a huge time saver and a very important skill if you're going to be doing a lot of modeling. So we're going to set up our macro by first setting up some column headings. And so in cell G6, I'd like you to enter the word Trial. And we are going to run 1000 trials of a roc population with stochasticity. So if I press F9 and I look and see, well, my Ending Population Size is 626 and there was one flu epidemic, that represents one trial. If I press F9 again, there's a second trial. If I press F9 again, there's a third trial. And you can see this would become quite a chore to record those by hand, and so it's in your best interest to use a macro to let the computer do the work for you. So we're going to run 1000 trials. I'm going to start a series, and I'm going to then grab the Fill handle and drag all the way down to the year 1000. And you want to run enough trials so that you get a really good handle on what the variation in results could be. And truly we could run fewer than 1000. We could a hundred, and that would be enough for you to get an idea, but when you're doing these in a real scenario, you want to aim for a number of replicates that gives you a really good idea of what the possible values and outcomes could be. So there we have a trial, 1 through 1000, and what we're going to record are the number of rocs - this is again the year 2000 - and we are also going to just record the number of flu epidemics. Because we have that information handy and we just might want to graph, whether or not, how many flu epidemics is most likely. You can probably guess what these graphs might look like, just based on the numbers that are entered here, but let's go ahead and run it anyway. 1

A macro is just a series of recorded keystrokes that Microsoft Excel will record for you. And as you go through a macro, it's recording your keystrokes as a set of instructions. And when you're finished recording and then play that macro, the computer will just repeat very faithfully that particular series of keystrokes. And so let's talk through what we'd like the computer to do, as we do this macro, and as we press and run a simulation for roc flu. So what we want to do first is press F9 to generate a new trial. Then we want to go over to cell E2 and E3, copy those values, come over to Trial 1 and paste in the numbers that we just recorded in cells E2 and E3. We're going to paste those in there. Then we want to do that again. Press F9, take the next results, and paste them in there. Press F9, paste them in the next results. I'm going to walk through how I typically do these kinds of macros. First, I'm going to highlight these and give them the same border as the other parts of my spreadsheet. And I want to point out that the macro tab is under the View tab up in the Ribbon - and it's to the far right-hand corner and it's called Macros. And, if you click on that button, you can see a list of the macros that are currently in your workbook. And you should have no macros that are there at this time. If you click on the [Macros] drop-down button, you'll see you can just view the macros. Or you can record a new macro, and that's the button we're going to push. This option, Use Relative Reference, is another extremely useful button to know. We're not going to need it in this particular exercise, but we will potentially use it later on. For us to start a new macro, we choose Record Macro, and we give the macro a name. And let's just call this macro Trial. You can enter a shortcut key here, so that would be Ctrl-plus and pick a letter, G. And when I press those two keys together, it's going to run the macro. I want to store this macro in this workbook, which means I need to save this workbook as a macro-enabled workbook. And I want to enter a description of the macro down in this particular box. Now you'd want to get in the habit of doing this, if you were somebody who does a lot of population modeling and would ever want to refer to your old models or share your models with somebody else, "This macro runs the roc population model over 1000 replicates or trials." And click OK. And now you are recording every little keystroke you make with your mouse; you are recording that in your macro file. So if I wanted to take a trip to the end of the spreadsheet page and back, it would faithfully record that. And that's okay; I just want you to know that you're recording everything. 2

So the first thing we said we wanted to do was to press F9 and generate some new random numbers so let's do that. There's my new random numbers. I'm going to take my mouse and copy those cells - and I need to go back to my Home tab and press the Copy button. Then I want to come down to cell H6. I want to find a blank cell and move into that blank cell. So I do that by going over to the Find & Select button, and I want to just find, and I want to find the next blank cell, but I want to search down by rows. So I want to find a blank cell within this sheet, and I want to search down the rows as opposed to across columns. And I just press Find Next, and the spreadsheet should go to the next cell. Now I must have clicked on something incorrectly so I'm going to press Close. I'm going to start that again. I can start this whole macro over again, but since I haven't really made any major mistakes, I'm just going to keep going with this. So I'm going to press F9. I'm going to copy those values - Copy. I'm going to select cell H1. Oh, I'm sorry. I did want to select down by columns so stay within the same column. That was my mistake. I want to Find the next blank. And I want to search down the column, Find Next one, and hop down to the next blank cell. I press Close. Then I want to come up to Paste / Paste Special, and I want to paste the values. I don't want to paste the actual formula because it won't paste correctly. And I also want to transpose those values so that the results for one trial are in a row, and that result is pasted in there. Notice that, when I'm pressing these buttons, Excel's keeping, generating brand new sets of random numbers. That doesn't really matter. All we need to do is generate 1000 of these trials. In theory, I'm done, and so I can go back to my Macro tab, click on the button, and now I have a Stop Recording button, and I press that, and my macro has been stopped and saved. Now what I want to do here is format these cells so that they are numbers. So again, that's back at the Home tab, and the Numbers are going to just hide the decimal points there. Now, if I press my Macro Control button, and mine was Control G, the macro runs and just pastes that value straight in. And we can press that 1000 times and then we're able at this point, then, to summarize those results. And get a really good look at okay this is a stochastic process - and I need to run this many, many times. And I want to look, then, across many, many trials and see - well, what's the worse-case scenario, what's the best-case scenario. And really get a feel for what the range and values might be. Now there are ways to make this process easier. And, if you go back to the Macro page - let's view that macro now. So my macro was called Trial, and what I'm going to do is edit this. And what this does is, it pops up the visual basic code. This is Visual Basic for Applications - it's Visual Basic that runs within an application, in this case, Microsoft Excel. This is the code. This 3

is the formula, the Visual Basic code that tells the computer what instructions to do. So you can even see this is a really nice way to quickly get a feel for what Visual Basic does. The first thing I did was press the Calculate key. Then I selected cells E2 and E3, and I copied them. Then I went to cell H6. I went down, and I searched by rows. That's where I made my mistake so I'm going to take these out, and then I started the process again. So these are where I made a mistake, and so I'm going to go ahead and delete those pieces of code. You probably didn't make that mistake, but it's good to know you can edit your macros. So now, as I read through this, we calculated a new trial, a new set of values. We went to cells E2 and E3, and we copied the Ending Population Size and the ending number of flu epidemics. We went to cell H6. We searched for the next blank cell in that particular column, then we pasted the values into that, and then this is the end of the macro. Now I can make my macro run way more quickly if I insert a counter button, and you can do this by typing in the words, "For counter = 1 to 1000." And what this does is when the macro starts, it hits this line of code. It invokes a counter. It sets it at 1. It goes all the way through this code, and then, after it's done, it finds the word Next. And then it repeats it again, but now the counter's incremented to 2, and it just keeps looping through this code until it hits 1000. And, after it hits 1000, it pops out of this macro - this subroutine. And you're finished with that particular set of instructions. Now it looks like I'm going to close the spreadsheet, but I'm not. I'm just closing the Visual Basic dialogue box. And now, if I run this particular macro, it's going to loop through all 1000 trials. So let's try that. I'm going to push Control G. PAUSE the video: This is a good time for you to start working on your own macro, and seeing if you can get it to work for you, as well. So now we're done with our 1000 trials of the roc flu population model. And we have a whole slough of results. And I wanted to show you a quick way to add a button to your spreadsheet. And that would help you to just press the button to run a macro as opposed to remembering the shortcut commands - which, I don't know about you, but I always forget them. So you can do this in a number of ways. And what we'll do right now is, we'll go to the Insert tab, and we'll just insert a shape. And pick any shape you like. I'm going to choose a smiley face and pop it on my spreadsheet, and make that a little bit smaller. And if I right-click on this, then I can go down to the Assign Macro option, and I can assign the macro Trial to that smiley face and press OK. 4

Now when I press the smiley face, it's going to run that particular macro. There are other ways to run and add buttons and forms to your spreadsheet. We won't do that right now, but we'll probably do that in later exercises. Now what do you need to do? Well, we've got results for 1000 trials, and we need to summarize the data in some way. One way we can do this is by using a Frequency function that just tracks how many trials ended up with roc populations that were between 100 and 200 or 200 and 300. And we can use the Frequency function to do that. And the Frequency function is a different kind of function in Excel. It's called an Array function, and so it's entered a little bit differently than other functions. But what we need to do first is to set up what are called Bins. And I'm going to enter the word Bins in cell K6. And I'm going to let my Bins start with the number 100 and go to 200, 300, and let's let that go all the way up - let's just try to capture the range we see. There's a 900. Let's let these Bins go up to, say, 1400. And what we're going to do is take our results and count how many of all of these trials ended up with values that fit in these particular Bins. And I like to think of the Bins as buckets. And what I need to do is look at this particular number, and here's a bucket that holds all of the roc population sizes from zero to 100. And here's a bin that holds all of the outcomes that were between 100 and 200. And here's a bin that holds all of the outcomes between 200 and 300, and so on. So what we're going to do is enter a formula that counts. Okay, here's an example from Trial 1, and it's going to go into this bin right here. It's a number whose value falls between 300 and 400, and so it's counting a Frequency of 1. My next result also fell within that bin. This result falls within the first bin, and the Frequency function is an easy way for you to tabulate and get a very quick, graphical view of what your data look like. Now to enter this Frequency function as an Array function - you don't just select one cell, you select multiple cells at one time and then enter your function. So I'm going to select cells L7 through L20. I'm going to go up to my Insert Function button, and I'm going to search for the Frequency button. And, once I find it, I open it up and the dialogue box asks me to choose first the array of data, and that's going to be all the data you want evaluated. If I choose to click on the red arrow, the dialogue box shrinks. And now I'm free to select all of my data, and I'm going to go down and select the results for all 1000 trials. If you are keyboard shortcut person, you can just press Control/Shift and the down-arrow, and it'll take you down to the last record very quickly. When I'm finished, I click on the arrow again. It opens up the dialogue box, and now I 5

need to enter and tell it where the Bins Array is. So I'm going to shrink this down again and go find my Bins Array. There they are. I don't know why there's an Okay button here. Because, if you press that, you're not going to get the right answer. What you need to do when you enter an Array function in Excel is - you need to push the Ctrl / Shift and Enter key down at the same time. So hold Control/Shift and Enter, and all the values will be entered and popped into those automatically. Now if you look up at the Formula Bar, you can tell it's an Array function because it has these curly braces around it, and it alerts you that that function - that whole formula, is an Array, and you can't change that Array one cell at a time. It's an equation that's working across multiple cells at the same time. Well, there's our results. So the caliph might be interested in knowing, for example, well how many of these trials resulted in a population size of fewer than 100. And, if that was the case, then you can tell him that 189 of your population runs, out of 1000 trials, resulted in a population size of 100 or less. And so let's go ahead and calculate that as a proportion. So our proportion is just the frequency of the trials, out of 1000 different trials. And, if we drag this down, then you can use these numbers in a way to talk about probability. There was an 18.9 percent probability that the population size would fall below 100 individuals. And that's how you'd basically look at these particular numbers. It's often helpful to graph those. And, to graph those, you just select the Bins and the Frequency. Go to the Insert tab, and you're going to graph this as a column chart, a 2D column. And we don't need to graph the Bins so I can select the Bins and delete those. And what we're graphing here is just the Frequency. I need to insert a proper set of values for the X Axis, and I need to also label the axes as well. To do that, I first can go to the Design tab. And I can select the data, and it pops up a dialogue box. And I want to edit the horizontal Axis labels. So I choose the Edit button, shrink down the dialogue box, and I choose my Bins here as the labels for my horizontal Axis and click OK. And then click OK. And I also, at this point, need to label my Axes. And so I can choose the layout tab, and I can find the Axis Title button. My horizontal Axis is going to be called, Roc Population Sizes - these are our categories though - so this would be Final Population Size Category. And then, on the vertical Axis, we'd want to put Frequency. Looks a little bit messy so I can 6

drag this and make it bigger so that those categories are more clearly readable. So those are the results of our 1000 trials. Over 150-189 to be exact - of our trials, which represented 18.9 percent, resulted in a roc population size that was between zero and 100. And 23 percent, or 23.9 percent, resulted in population sizes between 100 and 200 rocs. And, if you had run your model more times, you'd get a better idea of what the shape of this actual graph would look like. And that's the value in running a macro is that you can do this many, many times without too much worry or fuss. What do you think you should report back to the caliph? Is all well with the roc flu? Or should the Caliph be worried about this in any way? PAUSE the video: Why don't you take a minute and write out what you think a report might be, in just a couple of sentences. Before we go on now, we're going to save the spreadsheet. And you'll want to save this spreadsheet as Roc Flu. And, for this particular spreadsheet, you don't want to save it as an Excel Workbook. You need to select an option that allows you to enable the Macro. So you'd want to choose the option called Excel Macro-Enabled Workbook [.xlsm ] and click Save. And now you have an example of how to use a macro. And also, how do you run a stochastic model where you have an environmental factor, which is the roc flu, that behaves in a stochastic way? And how do you use that model to assess risk to the population, in terms of getting a good sense of what the likely outcomes are and what the likely outcomes are not? And you can use the information from the macro to put some numbers on those particular probabilities or to assign probabilities to those numbers. < 00:25:48 END > 7