Admin G/B/U Tying Tying R: Functions

Lecture 11: Last Lecture: Putting Things Together

April 23, 2018 Admin G/B/U Tying Tying R: Functions Overview

Course Administration

Good, Bad and Ugly

Tying Things Together: Stories

Tying Things Together: Visualizations that Communicate

R Functions Admin G/B/U Tying Tying R: Functions Course Administration

1. Presentations next week 2. Policy brief and presentation handout 3. Updated (?) grades online 4. Online evaluations open! Please give feedback 5. Missing anything from me? Admin G/B/U Tying Tying R: Functions Today’s Final Good Bad and Ugly

• Alex Sexton Admin G/B/U Tying Tying R: Functions Alex’s Chart

From https://howmuch.net/articles/international-trade-as-a-share-of-state-GDP Admin G/B/U Tying Tying R: Functions

Knaflic: Graphics to Tell Stories Admin G/B/U Tying Tying R: Functions Knaflic’s 5 Case Studies

1. Color considerations with a dark background 2. Leveraging animation in the visuals you present 3. Establishing logic in order 4. Strategies for avoiding the spaghetti graph 5. Alternatives to pie charts Wording is all Knaflic’s. Admin G/B/U Tying Tying R: Functions Knaflic’s 5 Case Studies

1. Color considerations with a dark background 2. Leveraging animation in the visuals you present 3. Establishing logic in order 4. Strategies for avoiding the spaghetti graph 5. Alternatives to pie charts Wording is all Knaflic’s. Admin G/B/U Tying Tying R: Functions 2. Animation

• Don’t use animation – figures that move without your guidance • Do use sequential reveal • Great example of same figure in presentation and paper Admin G/B/U Tying Tying R: Functions How Do You Get People to Pay Attention to the Important Parts? Admin G/B/U Tying Tying R: Functions Frame the Analysis Admin G/B/U Tying Tying R: Functions Start at the Beginning Admin G/B/U Tying Tying R: Functions Add Step by Step Admin G/B/U Tying Tying R: Functions Step by Step Admin G/B/U Tying Tying R: Functions Step by Step Admin G/B/U Tying Tying R: Functions Till the End Admin G/B/U Tying Tying R: Functions And For Print Admin G/B/U Tying Tying R: Functions 3. Logic in order

• Highlight what you want people to focus on • With order • With color • With text Admin G/B/U Tying Tying R: Functions What’s Important Here? Admin G/B/U Tying Tying R: Functions Suppose We Care Most About User Satisfaction Admin G/B/U Tying Tying R: Functions Suppose We Care Most About User Dissatisfaction Admin G/B/U Tying Tying R: Functions Or About Which Feature is Least Used Admin G/B/U Tying Tying R: Functions What if You Want to Highlight All Three? Admin G/B/U Tying Tying R: Functions What if You Want to Highlight All Three? Admin G/B/U Tying Tying R: Functions Highlighting All Three, Part 2 Admin G/B/U Tying Tying R: Functions Highlighting All Three, Part 3 Admin G/B/U Tying Tying R: Functions Putting It All Together: Best for Print Admin G/B/U Tying Tying R: Functions 4. No Spaghetti

• Instead of the book’s example, another from her website • Transforming hard-to-read bars to easier-to-read formats • Many similar ideas apply Admin G/B/U Tying Tying R: Functions Pew Charts on Number of Newly Married Adults What’s Wrong and How to Fix? Admin G/B/U Tying Tying R: Functions Show Change Over Time Admin G/B/U Tying Tying R: Functions Can You Pick Out the Point Here? Admin G/B/U Tying Tying R: Functions Highlighting the Increase for You Guys Admin G/B/U Tying Tying R: Functions What Would You Want to Pull Out? Admin G/B/U Tying Tying R: Functions Highlighting Peak and Trough Admin G/B/U Tying Tying R: Functions

Mulbrandon’s Graphics Admin G/B/U Tying Tying R: Functions Visualizing Economics

• Mulbrandon has a BA in economics, and a postgraduate degree in design • Experience in finance industry • Now runs a data visualization firm • To make this book she used Excel, OmniGraphSketcher (no longer available), Illustrator, R and InDesign (publishing) Admin G/B/U Tying Tying R: Functions Which Techniques is She Using?

• What’s the story she’s trying to convey? • Look at each graph and think about the underlying techniques • Two static and two building Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

Multiple Sources Individual Income Various Bureau of Labor Statistics BLS 1901–2002 CostFamily of Housing Household in the 20th Century BLS F . D L . B G . H W E T . R . R i s e nh o G . W . J o hn s n oo s e v C K oo s e v H T oo l i dg e e nn d R O C H Wilson r a r ea g a n u m a n C l i n . Bu . Bu N i x b a m oo a r d i n g F w T t o r v e l t a f e l t t o n o n s h s h e r e r e r d y t WW II Cold War WW I Korean Persian Afghanistan Vietnam Gulf Iraq

$20,000 1975 Great Great Depression Recession

15,000 2010 US Dollars

10,000 Annual Cost of Housing 5,000 Urban Areas Only, Adjusted for In ation

0 1900 1910 1920 1930 1940 1950 1960 1970 1980 1990 2000

Hot and cold piped water, a bathtub or shower, More homes had a full bathroom. and a ush toilet 55% 99%

More housing built for more people 34 million 112 million

with fewer people living together 3.7 2.6

Median square feet of oor area in new single-family houses while the size of houses increased. ~1,000 2,135 1940 2000

VisualizingEconomics.com 152 Sources: US Bureau of Labor Statistics, “100 Years of US Consumer Spending: Data for the Nation, New York City, and Boston,” Report no. 991 • US Census Bureau Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

2011 Multiple Sources Individual Income Various Wages of All Occupations by Education

MedianMedian Hourly Hourly Wage Wage (2011(2011 US Dollars) USBureau Dollars) of Labor Statistics EstimatedBLSEstimated AnnualAnnual Salary Salary $9 0 $9 Family0 Household $183,600$183,600BLS

Oral and maxillofacialOral and maxillofacial surgeons surgeons

80 80 OrthodontistOrthodontists s 163,200163,200 Physicians Pandhysicians surgeon ands surgeons

70 70 Airline pilots,Airline copilots, pilots, and copilots, flight engineerand flights engineers 142,800142,800 Dentists, generaDentists,l general Dentists, allD entistsother spec, all iotalisthesr specialists

60 60 Natural sciencesNatural manager sciencess managers EngineeringEngineering managers managers 122,400122,400 PetroleumP engineeretroleums engineers Computer Caonmd pinfuteormr aatndio infn ormation systems manager systemss managers ProsthodontistProsthodontists s Air trac controllerAir tracs controllers MarketingM managerarketings managers Lawyers Lawyers Physicists Physicists PharmacistPsharmacists 50 50 Chief executiveChiefs executives Computer Chardwareomputer hardwareengineers engineerSaless managerSaless managers Computer Caonmd pinfuteormr aationnd inf ormation 102,000102,000 Political sciPenoltistiticals scientists scientists, researcscientists,h research OptometriOstptos metrists Industrial productionIndustrial production managers managers Geoscientists,Geoscientists, except except AerospaceA engineererospaces engineers Public relatPiuoblnsi cm relatanageionrs managers hydrologists hydrologists and geographer and geographers s Nuclear engineerNuclears engineers PurchasingP urchasingmanagers managers PostsecondaryPostsecondary teachers teachers Sales engineerSaless engineers PodiatristsPodiatrists Engineers,E allngineers, other all other Medical andM edicalhealth and services health manager servicess managerMathematicians Mathematicians s EconomistsEconomists Medical scientists,Medical scientists, VeterinarianVeterinarians s 40 40 Geological Gandeological petroleum and petroleum technician stechnicians Materials scientistsMaterials scientists AdvertisingA dvertisingand promotions and promotions managers manager excepts epidemiologist except epidemiologists s Mining machineMining operators, machine operators,all other all other First-line supervisors/managersFirst-line supervisors/managers of of Civil engineerCivils engineers 83,20083,200 Gas compressorGas compressor and and police and policedetective ands detectives Radiation therapistRadiations therapists AdministrativeAdministrative services manager servicess managers ChiropractorChiropractors s gas pumping gas station pumping operator stations operators CommercialCommercial pilots pilots OperationsO researchperations analyst researchs analystsComputer Csystemsomputer analyst systemss analysts Nuclear powerNuclear reactor power operator reactors operators First-line supervisors/managersFirst-line supervisors/managers of of Chemists Chemists fire fighting fire and fighting prevention and prevention workers workers StatisticiansStatisticians VocationalV educatocationioaln educatteacheiros,n teachers, Ship engineerShips engineers Nuclear medNuiccleainer tec medhniologcine itecstshnologists LogisticianLsogisticians seconda r y secondaschool ry school MicrobiologistMicrobiologists s Athletes andAthletes sports and competitor sports competitors s OccupationalOccupational therapists therapists Detectives Dandetectives criminal and investigator criminal investigators s Credit analystCredits analysts Producers Pandroducers director ands directors AudiologistAsudiologists Helpers, extractionHelpers, extractionworkers workers Rotary drillR operators,otary drill operators,oil and ga soil and gas Electrical andElectrical electronics and electronics repairers, repairers,Gas plant operatorGas plants operators Diagnostic Dmiagednicalost isoc mnogedriapcalh soernsographersUrban andU regionalrban and planner regionals plannersTechnical writerTechnicals writers 30 30 Wellhead pumperWellheads pumpers powerhouse, powerhouse, substation, substation, and relay and relaPyower plantPowe operatorr plants operators Cost estimatorCost sestimators Speech-languageSpeech-language pathologist pathologists Lsoan ocerLoans ocers Flight attendantFlight sattendants Arbitrators,A rbitrators,mediators, mediators, and conciliator and conciliators s 62,40062,400 Drafters, allD rafters,other all other EmergencyE mergencymanagement management specialists specialists Fashion designerFashions designers InstructionalInst cooructrdionalinator coos rdinators SurveyorsSurveyors Clinical, counseling,Clinical, counseling, and school andpsychologist school psychologists s AdvertisingA dvertisingsales agent saless agents Chemical plantChemical and systemplant and operator systems operators Forensic scienceForensic technician science stechnicians LibrariansLibrarians Postal servicePostal clerk services clerks Fire inspectorsFire inspectorsand investigator and investigators s Curators Curators Dietitians andDietitians nutritionist and nutritionists s Postal servPiceostal mail ser cavicerrie mailrs carriers Roof bolters,Roof minin bolters,g mining MechanicalM drafterechanicals drafters ElectriciansElectricians Paralegals Pandaralegals legal assistantand legals assistants LegislatorsLegislators Shuttle carS huttleoperator cars operators Fire fighterFsire fighters Aircraft cargoAircraft handling cargo supervisor handling ssupervisors Interior designerInteriors designers Archivists Archivists Editors Editors Tapers Tapers CarpenterCsarpenters Graphic designerGraphics designers Broadcast Bnewsroadcast analyst newss analysts Riggers Riggers PaperhangerPaperhangers s Legal secretarieLegal ssecretaries Lodging managerLodgings managers Chemical technicianChemical stechnicians Marriage andMarriage family and therapist familys therapists Bridge andB lockridge tender and locks tenders Radio mechanicRadios mechanics StonemasonStonemasons s 20 20 Roofers Roofers Chefs and Cheadhefs cookand heads cooks Biological technicianBiological stechnicians Mental healthMental counselor healths counselors RecreationalRecreational therapists therapists Education Eadministrators,ducation administrators, preschool andpreschool child careand center/prograchild care center/program m Sailors andS marineailors and oiler marines oilers Barbers Barbers Actors Actors Fence erectorFences erectors Coaches andCoaches scouts and scouts Food serviceFood manager services managers Forest andF conservationorest and conservation technician technicians s Set and exhibitSet and designer exhibits designers Art directorAsrt directors 41,60041,600 ProcurementProcurement clerks clerks Desktop publisherDesktops publishers Job printerJsob printers CorrespondenceCorrespondence clerks clerks Dental assistantDentals assistants Medical secretarieMedicals secretaries ChoreographerChoreographers s SemiconductorSemiconductor processors processors RehabilitationRehabilitation counselors counselors Library technicianLibrary stechnicians Multi-mediaMult artistsi-media and artists animator ands animators Order clerkOsrder clerks Tax preparerTaxs preparers UpholstererUpholsterers s New accountsNew clerks accounts clerks Veterinary Vtechnologistseterinary technologists and technician and stechnicians File clerks File clerks Models Models Medical transcriptionistsMedical transcriptionists Dancers Dancers Gaming supervisorGaming supervisors s Writers andW authorriters ands authors Tellers Tellers Pest controlPest worker controls workers Farmers andFarmers rancher ands ranchers Real estateR ealbroker estates brokers BartenderBsartenders Floral desigFnloralers designers Craft artistCsraft artists Clergy Clergy Directors, Directors, Music directorsMusic and directors composer ands composers 10 10 Laundry andLaundry dry-cleaning and dry-cleaning workers workerGsaming dealerGamings dealers Graders andGraders sorters, and sorters, religious activities religious and activities educatio andn education Child care Cworkerhild cares workers Cooks, privCateook hos, upserivhateold household agricultural agricultural products products Door-to-doorDoor-to-door sales workers sales, workers, 20,10020,100 news and streetnews andvendors, street and vendors, related and worker relateds workers

0 0 Short-termShort-term Moderate-termModerate-term PostsecondaryPostsecondary Long-termLong-term WorkW experiencork experience e Associate’sAssociate’s Master’sMaster’s Bachelor’sBachelor’s DegreeDegree plus plus DoctoralDoctoral ProfessionalProfessional on-the-jobon-the-job trainin training on-the-jobg on-the-job trainin training vocationalg vocational awar award don-the-jobon-the-job trainin training ing a related in a related field field degredegree e degredegree e degredegree e workwork experienc experience edegredegree e degredegree e

VisualizingEconomics.com 100 Source: EMSI EconomicModeling.com (Compiled from data collected by BLS, BEA and US Census Bureau) 101 Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census 2010 Census Bureau Household Census Demographics of All Incomes

0 10 20 30 40 50 60 70 80 90 100% Census Bureau FamilyRace of Householder Census White 71% Black 13% CongresstionalHisp aBudgetnic 12% O ce Household CBO Asian 4% Education of Householder No High School Diploma 11% 040 IRS Returns 1 IRS High School Graduate 28% Some College or 27% Associate’s Degree Bachelor's Degree or More 28% 040 IRS Returns Filing Jointly 1 IRS Age of Householder 15 to 24 years 5% 25 to 34 years 17% CIA Factbook 35 to 44 years 18% CIA 45 to 54 years 20% 55 to 64 years 18% 65 to 74 years 11% Bureau of 75 Economic years and over 10% Analysis BEA Work History of Householder Worked (Full- or Part-Time) 65% BureauDid No tof Wor kLabor for Pay in 2010 Statistics35% BLS Number of Earners in Household No Earners 24% One Earner 38% Two Earners (or More) 38%

Various Multiple Sources Summary Statistics Type of Household Married-Couple Family 48% MultipleNo Spo uSourcesse Present Family Individual18% Income Various Singles/Unrelated People 35%

Urban Location of Household (Inside principal cities) 33% Bureau of LaborSurburban Statistics 50% (Outside principal cities) BLS Rural 17% (Outside metro statisitcal areas) Housing (Less than 2% do not pay cash rent ) Owner Occupied 65% Family Household BLS Renter Occupied 33% 0 10 20 30 40 50 60 70 80 90 100%

VisualizingEconomics.com 62 Source: US Census Bureau, 2006–2010 American Community Survey Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census 2010 Census Bureau Household Census Demographics of Incomes below $30,000

0 10 20 30 40 50 60 70 80 90 100% Census Bureau FamilyRace of Householder Census White 63% Black 19% CongresstionalHisp aBudgetnic 15% O ce Household All Households CBO Asian 3% Education of Householder No High School Diploma 22% 040 IRS Returns 1 IRS High School Graduate 34% Some College or 23% Associate’s Degree Bachelor's Degree or More 13% 040 IRS Returns Filing Jointly 1 IRS Age of Householder 15 to 24 years 9% 25 to 34 years 15% CIA Factbook 35 to 44 years 13% CIA 45 to 54 years 15% 55 to 64 years 16% 65 to 74 years 14% Bureau of 75 Economic years and over 19% Analysis BEA Work History of Householder Worked (Full- or Part-Time) 40% BureauDid No tof Work Labor for Pay in 2010 Statistics60% Number of Earners in Household BLS No Earners 52% One Earner 39% Two Earners (or More) 8%

Various Multiple Sources Summary Statistics Type of Household Married-Couple Family 23% MultipleNo Spo uSourcesse Present Family Individual23% Income Various Singles/Unrelated People 54%

Urban Location of Household (Inside principal cities) 38% Bureau of LaborSurburban Statistics 42% (Outside principal cities) BLS Rural 20% (Outside metro statisitcal areas) Housing (Less than 2% do not pay cash rent ) Owner Occupied 47% Family Household BLS $30,000 Renter Occupied 50% 0 10 20 30 40 50 60 70 80 90 100%

VisualizingEconomics.com Source: US Census Bureau, 2006–2010 American Community Survey 63 Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

2010 Multiple Sources Individual Income Various Top Major League Baseball Salaries Bureau of Labor Statistics BLS Family Household $32BLS million Alex Rodriguez IBM Starbucks

CEOs of Publicly Traded Companies $28 million s Well Vernon a Sabathi a CC r Teixeir $24 million ark Maue M Joe a Santan Johan ton d y a Hel owar abrer H Hallada C n Todd yan oy o o R R Miguel eltra e orian B Le S r $20 million arlos Zambrano C Carlos lfonso Zit unte i A Carlos rii H Bay zuk Barry To Su ason iro J Ich t Becket t g Josh Burnet olliday Youn t y .J. H eav y A att Oswal P acke M Michaeloy ake L $16 million R J John Baseball Players Salary only, does not $12 million include endorsements

$8 million

$4 million Average Salary of All Major League Players 2010 ($3.3 million)

$0

VisualizingEconomics.com 26 Sources: AR: Absolute Return + Alpha, “The Rich List,” April 2011 • , “ 100, 2011” • Forbes, “CEO Compensation, 2011.” • USA Today, “USATODAY Salaries Databases” Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

2010 Multiple Sources Individual Income Various Top CEO Compensation Bureau of Labor Statistics BLS Family Household UnitedHealth $100BLS million Group

$90 million CEOs of Publicly Traded James Patterson Companies $80 million

s $70 million Communication Qwest

$60 million y s Bethenny isne ipt Frankel lt D Scr Wa Express h oac n $50 million C aure s L m Ralph Science olo etroleus P Gilead P System nadarko logiesy $40 million A Cisco n Verizon echn oEnergn y y l llerga T esso Int m A Life cK Energ Energ s NobleM C a Morrisetroleus EM P Branda Baseball Players NvidiPeabodyIBM Cimarexhilip ltra Vit P U StarbuckYum Da $30 million Emersontric Elec

$20 million

$10 million

$0

VisualizingEconomics.com Sources: AR: Absolute Return + Alpha, “The Rich List,” April 2011 • Forbes, “Celebrity 100, 2011” • Forbes, “CEO Compensation, 27 2011.” • USA Today, “USATODAY Salaries Databases” Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

2010 Multiple Sources Individual Income Various Top Celebrity Income Bureau of Labor Statistics BLS

$300 millionFamily Household BLS Hedge Fund Managers

$250 million Celebrities

$200 million

$150 million

Tyler Perry

Jerry Bruckheimer CEOs of $100 million Publicly Traded LadySimon Gaga Cowell James Patterson Companies Dr. Phil McGraw LeonardoHoward DicaprioTiger Stern Woods Dick JerryWolf Seinfeld JamesPaul Cameron McCartney Rush Limbaugh Black RyanEyedDonald PeasSeacrest Trump BethennyKobe FrankelJustin Bryant Bieber $50 million

Baseball Players

$0

VisualizingEconomics.com 28 Sources: AR: Absolute Return + Alpha, “The Rich List,” April 2011 • Forbes, “Celebrity 100, 2011” • Forbes, “CEO Compensation, 2011.” • USA Today, “USATODAY Salaries Databases” Person Household 040

1 Tax Unit Family Family Household

Household of unrelated people Household of a single person Household of a family & unrelated people Family Household (unrelated people not included)

040 Tax Units Filing Jointly 1 Census Bureau Income Earner Census Census Bureau Household Census Census Bureau Family Census Congresstional Budget O ce Household CBO

040 IRS Returns 1 IRS

040 IRS Returns Filing Jointly 1 IRS CIA Factbook CIA Bureau of Economic Analysis BEA Bureau of Labor Statistics BLS

Various Multiple Sources Summary Statistics

2010 Multiple Sources Individual Income Various Top Hedge Fund Manager Income Bureau of Labor Statistics BLS

$5 billion FamilyJohn HouseholdPaulson BLS

Hedge Fund Managers $4 billion

Ray Dalio $3 billion

James Simons David Tepper $2 billion

Steve Cohen Eddie Lampert $1 billion Carl Icahn

Bruce Kovner

GeorgePaul S oroKTenudors GMr i narcJones Lasr IIy MichaelWillian HintzD anAckmaeI zzOcyh Ennglander DavidM Sichaelhaw Platt Celebrities StanleyAndrew DruckenmilleSet Hh oinKLlaeonermra CnLoooupermisJ amieBacoan nDDinaan nLoeb CEOs Baseball Players $0

VisualizingEconomics.com Sources: AR: Absolute Return + Alpha, “The Rich List,” April 2011 • Forbes, “Celebrity 100, 2011” • Forbes, “CEO Compensation, 29 2011.” • USA Today, “USATODAY Salaries Databases” Admin G/B/U Tying Tying R: Functions

Tying Things Together: Functions in R Admin G/B/U Tying Tying R: Functions From Animate to Automate

• Today’s R tutorial: functions • How to automate repetitive tasks • Usually slower in the short run • Faster in the long run • Less error prone Admin G/B/U Tying Tying R: Functions Functions Plan

• Introduce a simple function in class • Tutorial takes to you automating graph production Defining a Function

function.name <- function(arg1, arg2){ # stuff your function does }

I function.name: what you call the function I function: needed to tell R this is a function I arg1: first argument of the function I inside the curly braces: what you want the function to do Simple Function Example

summer <- function(x,y){ x^y }

I function name? I arguments? I body of the function? ## [1] 8

summer(3,2)

## [1] 9

Calling a Function

summer <- function(x,y){ x^y }

summer(x=2,y=3) summer(3,2)

## [1] 9

Calling a Function

summer <- function(x,y){ x^y }

summer(x=2,y=3)

## [1] 8 ## [1] 9

Calling a Function

summer <- function(x,y){ x^y }

summer(x=2,y=3)

## [1] 8

summer(3,2) Calling a Function

summer <- function(x,y){ x^y }

summer(x=2,y=3)

## [1] 8

summer(3,2)

## [1] 9 Admin G/B/U Tying Tying R: Functions To the Tutorial!

• Good luck • Do the evaluation • Presentations next week