Bayesian workflow. Andrew Gelman Dept of Statistics and Dept of Political Science Columbia University, New York

Similar documents
2018 HR & PAYROLL Deadlines

COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*

Clubhouse Reservations Calendar

Utility Debt Securitization Authority 2013 T/TE Billed Revenues Tracking Report

NASDAQ DUBAI TRADING HOLIDAYS AND SETTLEMENT CALENDAR 2018 For Equities Outsourced to the DFM (T+2)

Calendar On US Federal Reserve Holidays, no settlements will take place for USD.

January 2018 Sun Mon Tue Wed Thu Fri Sat Week 2 1 New Year's Day

March High Start Race Day Date Water Time Type Event Sat 03-Mar Dinghy Show - Alexandra Palace Sun 04-Mar Dinghy Show - Alexandra Palace Mon 05-Mar

Step On Stage Dance Company

LOST SPRINGS GOLF 2018 CALENDAR OF EVENTS

Wisconsin 511 Traveler Information Annual Usage Summary January 3, Wisconsin 511 Phone Usage ( )

U14 HL1. + Lein U15 HL2. U12 HL1 Lein U13 HL3. + Lein U15 HL3. Lein U15 FL Finals

NEVADA SLOT MACHINES: HISTORICAL HOLD PERCENTAGE VARIATIONS ANNUAL AND MONTHLY HOLD PERCENTAGES, CENTER FOR GAMING RESEARCH, NOVEMBER 2017

2019 Class Schedule. Teaching Locations. New to The First Tee? Two Options To Begin... Participation Fees

SWISS Traffic Figures May 2004

May 2018 MLS Statistical Report

KC Scout Kansas City s Bi-State Transportation Management Center

Offaly GAA Master Fixtures Plan 2018

Competition Meeting 7pm

Montgomery County Pedestrian Safety. Seneca Valley High School PTSA November 20, 2012

Offaly GAA Master Fixtures Plan 2018

SWISS reports stable load factors

CAIRNS YACHT CLUB 2015 SCHEDULE OF ACTIVITIES

1 PEW RESEARCH CENTER

PROPOSED EP BOWLS CALENDAR; January 2019 Version 2 Approved 22 November 2018

January 2017 Calendar MAJORS FIELD LITTLE LEAGUE

July 2015 Sept Cork City Pedestrian Counter Report

3. EXCEL FORMULAS & TABLES

How customer behaviour is changing

ENERGY BILL ORGANIZATION

Important Dates for Season for JC and COP

Useful Tools in Mosquito Surveillance

*Fixtures may be changed at Committee's discretion

Mon Tue Wed Thu Fri Sat Sun Week 1 17-Jun 18-Jun 19-Jun 20-Jun 21-Jun 22-Jun 23-Jun Total

Apr-13 Mon 1 Tue 2 Ladies Stableford Cup 1 L Wed 3 Thu 4 Seniors LMS Round 1 S Fri 5 Ladies Shield Match (RUNCORN HOME) L Sat 6 Monthly Medal M Sat 6

Wed 9am - 8pm :30-6pm Ladies Merchandise Sale- Golf Shop 6-7pm Ladies Clinic pm Ladies Clinic Thanksgiving Club Closed

Little Athletics NSW. 2018/2019 Season. Age Group Information Handbook / 1

Foreign overnights in the Nordic countries 2015

Bluetongue Disease (BT)

02 Apr 18 Mon GOOD FRIDAY GOOD FRIDAY GOOD FRIDAY GOOD FRIDAY EASTER SUNDAY EASTER SUNDAY EASTER SUNDAY - 9 & 18 HOLE MEDAL EASTER SUNDAY

TRAINING LOG BOOK NAME:

Marathon walk's Complete Performance Training Plan

2018 Exhibition Schedule Black = Upstairs Gallery Green = Stewart Gallery

DEC DASHBOARD. Positive Response Compliance DEC. Compliant Tickets : On-Time Performance Analysis. December % Late.

Wetland Training Institute: 2018 Calendar of Courses

MAR DASHBOARD MAR. Compliant % Breakdown Mar % Late % On-time MAR APR MAY JUN JUL AUG SEP OCT NOV DEC

PUBLIC MEETINGS. Please see the City of Geneva Public Meeting Guide for more information regarding City Council and Committee of the Whole meetings.

Nasdaq Dubai AED TRADING HOLIDAYS AND SETTLEMENT CALENDAR 2018 For Equities Outsourced to the DFM (T+2)

1 PEW RESEARCH CENTER

FREEDOM OF INFORMATION REQUEST

KC Scout Kansas City s Bi-State Transportation Management Center

NCC Cable System Order

Tue, Jun 28, 2011 Scotland vs Netherlands Venue: Mannofield Park, Aberdeen Result: Scotland won by 15 runs

Example Report. EXAMPLE How to perform. infrared trending of Electric Motors. Plant Air Wash Supply Fan. Temperature Rise = High Temp = Ambient =

SEASONAL PRICES for TENNESSEE FEEDER CATTLE and COWS

GALLUP NEWS SERVICE GALLUP POLL SOCIAL SERIES: WORLD AFFAIRS

Agricultural Weather Assessments World Agricultural Outlook Board

Agricultural Weather Assessments World Agricultural Outlook Board

OUTLANE GOLF CLUB DIARY 2018 Day Date EVENT Mon 01 Jan 18 New Years Day Tue 02 Jan 18 Wed 03 Jan 18 Thu 04 Jan 18 Fri 05 Jan 18 Sat 06 Jan 18 Winter

DROWNINGS & OTHER WATER-RELATED INJURIES DURING LAND & AIR TRANSPORT

Understanding Rider Differences in Mileage and Riding Frequency through the MSF100 Motorcyclists Naturalistic Study.

2017: Year of Great Victory but the people that do know their God shall be strong, and do exploits. - Daniel 11:32b

Event. 9- Feb Sun Zone Meeting & AGM Kempsey. 15- Feb Sat Coopernook. 22- Feb Sat Nth Dorrigo Interclub Dorrigo

BOARD MTG 1900 HRS CLUB HOUSE

GALLUP NEWS SERVICE GALLUP POLL SOCIAL SERIES: WORLD AFFAIRS

Bicycle Crashes. Number of Bike Crashes. Total Bike Crashes. are down 21% and severe bike crashes down 8% since 2013 (5 years).

GALLUP NEWS SERVICE GALLUP POLL SOCIAL SERIES: WORK AND EDUCATION

FIXTURES LIST (2018 GOLF SEASON) QUAL

September 2017 MLS Statistical Report. Residential Inventory

CNC 2016 Calendar of events

2018 Program 20/10/17

FOR RELEASE: TUESDAY, DECEMBER 11 AT 4 PM

Nolan Doesken Colorado Climate Center

PEW RESEARCH CENTER FOR THE PEOPLE & THE PRESS 2011 MARCH POLITICAL SURVEY A FINAL TOPLINE Survey A: February 22-March 1, 2011 N=1504

12 13 January 09 Curran 1pm January 17 Elm Park 1pm February 14 - Pleasant Towers at 1 PM.

The Public Schedule 2018 Panama City Beach Aquatics Center

December 25 Christmas Day May 21 Victoria Day December 26 Boxing Day July 1 Canada Day (stat: Mon. July 2)

Summer KOs Sponsors THANK YOU. SUMMER KOs 2019

3. EXCEL FORMULAS & TABLES

English for Academic Purpose - 20 weeks. ATMC CDU Fed Uni USC. Available Intakes. Orientation Date. English for Academic Purpose - 15 weeks

FOR RELEASE: FRIDAY, MARCH 30 AT 5 AM

Schedule GAC Dance Team

African swine fever in domestic pigs and wild boar (ASF)

CYCSA RACING PROGRAM SEASON BY SERIES

Information for Members

16 17 Regional Men s & Women s Midweek 7:30pm

World Leading Traffic Analysis

Competition Fixture List 2019/ 2020 Season

Date Day Mens Competitions Ladies Competitions Seniors Competitions Juniors Competitions 20 Mar 17 Mon 21 Mar 17 Tue 22 Mar 17 Wed Texas Scramble

Jan-18. Red Text = Women's comp / Black Text = Men's Comp. Mens Mid Week Golf sponsored by Carley Advisory (Mike Carley) Mon 1 Tue 2

September 2018 FY Key Performance Report

JAN DASHBOARD. Positive Response Compliance JAN. Compliant Tickets : On-Time Performance Analysis. January % Late.

A review of 2015 fatal collision statistics as of 31 December 2015

DETAILED DESIGNS OF PRACTICAL PERPETUAL CALENDARS

January BBYRA Racing Calendar. Sunday Monday Tuesday Wednesday Thursday Friday Saturday. Feb 2010

CYCSA RACING ASSOCIATION SCHEDULE OF RACES BY DATE

Greater Manchester Police Hate Crime and Hate Incident Data 01/04/14 to 31/03/15

US LODGING INDUSTRY OVERVIEW

VINEYARDS COUNTRY CLUB MASTER GOLF SCHEDULE

6 11:00 4:00 New Years Day-Open House :30 PM Theme Dinner Oscar s Potentate Award Party :00PM House Committee Meeting

Transcription:

Bayesian workflow Andrew Gelman Dept of Statistics and Dept of Political Science Columbia University, New York Department of Biostatistics University of Washington, Seattle 26 Oct 2017

The (abridged) model in Stan parameters { real b; real<lower=0> sigma_a; real<lower=0> sigma_y; vector[nteams] eta_a; } transformed parameters { vector[nteams] a; a = b*prior_score + sigma_a*eta_a; } model { eta_a ~ normal(0,1); sqrt_dif ~ student_t(df, a[team1] - a[team2], sigma_y); }

Load Stan and data into R library("rstan") rstan_options(auto_write = TRUE) options(mc.cores = parallel::detectcores()) teams <- as.vector(unlist(read.table("soccerpowerindex.txt", header=false))) nteams <- length(teams) prior_score <- rev(1:nteams) prior_score <- (prior_score - mean(prior_score))/ (2*sd(prior_score)) data2014 <- read.table("worldcup2014.txt", header=false) ngames <- nrow (data2014) team1 <- match (as.vector(data2014[[1]]), teams) score1 <- as.vector(data2014[[2]]) team2 <- match (as.vector(data2014[[3]]), teams) score2 <- as.vector(data2014[[4]]) df <- 7

Fit the model fit <- stan("worldcup_first_try.stan") print(fit)

Check convergence Inference for Stan model: worldcup_first_try. 4 chains, each with iter=2000; warmup=1000; thin=1; post-warmup draws per chain=1000, total post-warmup draws=4000. mean se_mean sd 25% 50% 75% n_eff Rhat b 0.46 0.00 0.09 0.40 0.46 0.52 1369 1 sigma_a 0.13 0.00 0.07 0.08 0.13 0.18 653 1 sigma_y 0.42 0.00 0.05 0.39 0.42 0.45 1560 1 eta_a[1] -0.18 0.02 0.84-0.74-0.18 0.38 2506 1 eta_a[2] 0.18 0.01 0.82-0.35 0.18 0.73 3219 1 eta_a[3] 0.58 0.02 0.91 0.00 0.60 1.20 1864 1 eta_a[4] -0.59 0.02 1.00-1.28-0.62 0.10 2284 1 eta_a[5] 0.03 0.02 0.88-0.54 0.00 0.58 3163 1...

Graph the estimates

Compare to model fit without prior rankings

Compare model to predictions

After finding and fixing a bug

Data on putts in pro golf Probability of success 0.0 0.2 0.4 0.6 0.8 1.0 1346/1443 577/694 337/455 208/353 149/272 136/256 111/240 69/217 67/200 75/237 52/202 46/192 54/174 28/167 31/195 33/191 27/201 20/147 24/152 0 5 10 15 20 Distance from hole (feet)

What's the probability of making a golf putt? Probability of success 0.0 0.2 0.4 0.6 0.8 1.0 Logistic regression, a = 2.2, b = 0.3 0 5 10 15 20 Distance from hole (feet)

Geometry-based model r R x 2σ 0 2σ

Stan code data { int J; int n[j]; real x[j]; int y[j]; real r; real R; } parameters { real<lower=0> sigma; } model { real p[j]; p = 2*Phi(asin((R-r)/x) / sigma) - 1; y ~ binomial(n, p); }

Fit the model golf <- read.table("golf.txt", header=true, skip=2) x <- golf$x y <- golf$y n <- golf$n J <- length(y) r <- (1.68/2)/12 R <- (4.25/2)/12 fit1 <- stan("golf1.stan")

Check convergence > print(fit1) Inference for Stan model: golf1. 4 chains, each with iter=2000; warmup=1000; thin=1; post-warmup draws per chain=1000, total post-warmup draws=4000. mean se_mean sd 25% 50% 75% n_eff Rhat sigma 0.03 0.00 0.00 0.03 0.03 0.03 1692 1 sigma_degrees 1.53 0.00 0.02 1.51 1.53 1.54 1692 1

What's the probability of making a golf putt? Probability of success 0.0 0.2 0.4 0.6 0.8 1.0 Geometry based model, sigma = 1.5 0 5 10 15 20 Distance from hole (feet)

Two models fit to the golf putting data Probability of success 0.0 0.2 0.4 0.6 0.8 1.0 Logistic regression, a = 2.2, b = 0.3 Geometry based model, sigma = 1.5 0 5 10 15 20 Distance from hole (feet)

Birthdays!

The published graphs show data from 30 days in the year

Day of year effect Seasonal effect Day of week effect Trends 120 Relative Number of Births 100 80 60 120 100 80 60 120 Slow trend Fast non-periodic component Mean 1970 1972 1974 1976 1978 1980 1982 1984 1986 1988 1972 1976 1980 1984 1988 Mon Tue Wed Thu Fri Sat Sun 100 80 60 120 100 80 60 1972 1976 1980 1984 1988 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec New year Valentine's day Leap day April 1st Memorial day Independence day Labor day Halloween Thanksgiving Christmas Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Day of year effect Seasonal effect Day of week effect Trends 120 Relative Number of Births 100 80 60 Slow trend Fast non-periodic component Mean 2000 2002 2004 2006 2008 2010 2012 2014 120 100 80 60 120 2002 2006 2010 2014 Mon Tue Wed Thu Fri Sat Sun 100 80 60 120 100 80 60 2002 2006 2010 2014 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec New year Valentine's day April 1st Memorial day Leap day Independence day 9/11 Labor day Halloween Thanksgiving Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Christmas

Day of year effect 120 110 Valentine's day 100 9/11 90 Leap day April 1st Memorial day Labor day Halloween 80 Thanksgiving 70 60 New year Independence day 50 13th day of month Christmas Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

A surprisingly tricky model Sum of declining exponentials: y = a 1 e b 1x + a 2 e b 2x Statistical version: y i = (a 1 e b 1x i + a 2 e b 2x i ) ɛ i 0.0 0.5 1.0 1.5 y = 1e 0.1x + 0.8e 2x 0 2 4 6 8 10 x

Stan code data { int N; vector[n] x; vector[n] y;} parameters { vector[2] a; positive_ordered[2] b; } model { vector[n] ypred; ypred = a[1]*exp(-b[1]*x) + a[2]*exp(-b[2]*x); y ~ lognormal(log(ypred), sigma); }

Simulate fake data in R a <- c(1, 0.8) b <- c(0.1, 2) sigma <- 0.2 x <- (1:1000)/100 N <- length(x) ypred <- a[1]*exp(-b[1]*x) + a[2]*exp(-b[2]*x) y <- ypred*exp(rnorm(n, 0, sigma)) 0 2 4 6 8 10 0.0 0.5 1.0 1.5 x y = 1e 0.1x + 0.8e 2x

Fit the model in Stan Remember true values: a <- c(1, 0.8) b <- c(0.1, 2) sigma <-.2 Inference for Stan model: exponentials. 4 chains, each with iter=1000; warmup=500; thin=1; post-warmup draws per chain=500, total post-warmup draws=2000. mean se_mean sd 25% 50% 75% n_eff Rhat a[1] 1.00 0.00 0.03 0.99 1.00 1.02 494 1 a[2] 0.70 0.00 0.08 0.65 0.69 0.75 620 1 b[1] 0.10 0.00 0.00 0.10 0.10 0.10 532 1 b[2] 1.71 0.02 0.34 1.48 1.67 1.90 498 1 sigma 0.19 0.00 0.00 0.19 0.19 0.20 952 1

Try again with new parameter values Simulate new data using these new parameter values: a <- c(1, 0.8) b <- c(0.1, 0.2) Then fit the model: mean se_mean sd 25% 50% 75% n_eff Rhat a[1] 1.33e+00 0.54 0.77 1.28 1.77e+00 1.79e+00 2 44.2 a[2] 2.46e+294 Inf Inf 0.00 0.00e+00 1.77e+00 2000 NaN b[1] 1.00e-01 0.04 0.06 0.10 1.30e-01 1.30e-01 2 33.6 b[2] 3.09e+305 Inf Inf 0.50 1.15e+109 4.77e+212 2000 NaN sigma 2.00e-01 0.00 0.00 0.19 2.00e-01 2.00e-01 65 1.0

What went wrong? 0.0 0.5 1.0 1.5 y = 1e 0.1x + 0.8e 0.2x 0 2 4 6 8 10 x

What went wrong? 0.0 0.5 1.0 1.5 y = 1.8e 0.135x y = 1e 0.1x + 0.8e 0.2x 0 2 4 6 8 10 x

Informative prior distribution log_a ~ normal(0, 1); log_b ~ normal(0, 1);

Happy ending a <- c(1, 0.8) b <- c(0.1, 0.2) sigma <- 0.2 mean se_mean sd 25% 50% 75% n_eff Rhat a[1] 1.56 0.09 0.32 1.52 1.72 1.75 13 1.25 a[2] 0.32 0.08 0.28 0.14 0.22 0.37 13 1.20 b[1] 0.13 0.00 0.01 0.12 0.13 0.13 22 1.14 b[2] 1.94 0.20 2.29 0.22 1.26 3.00 127 1.05 sigma 0.20 0.00 0.00 0.19 0.20 0.20 656 1.00

Skewed posterior distribution 0.06 0.08 0.10 0.12 0.14 Posterior simulations for b 1 and b 2 b 1 b 2 0 10 20 30 (Red dot indicates true parameter values.) 8 10 12 14 16 0 2 4 6 Posterior simulations for 1 b 1 and 1 b 2 1 b 1 1 b 2 (Red dot indicates true parameter values.)

Some ideas in Bayesian workflow Putting parameters on unit scale Weakly informative priors Predictive model checking Predictive model evaluation Predictive model averaging Fake-data checking The network of models

Let us have the serenity to embrace the variation that we cannot reduce, the courage to reduce the variation we cannot embrace, and the wisdom to distinguish one from the other.