-
Notifications
You must be signed in to change notification settings - Fork 255
/
examples.Rmd
469 lines (421 loc) · 35.2 KB
/
examples.Rmd
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
---
title: "Regression and Other Stories - Examples"
author: "Andrew Gelman, Jennifer Hill, Aki Vehtari"
date: "Page updated: `r format.Date(file.mtime('index.Rmd'),'%Y-%m-%d')`"
---
-------------
## Introduction
- The code and data are provided to fully reproduce the examples
and figures in the book. They can be a good way to see what the
code does. Different people have different styles of code. The code here
is not supposed to be a model. The statistical analyses and
graphs in the book are intended to be models for good practice,
but the code here is meant to be simple with minimal dependencies.
- For R programming basics see Appendix A of Regression and Other Stories. If you want to learn more, see our recommendations for [R programming and visualization with R](R_visualizaton.html).
- The folders below (ending /) point to the code (.R and .Rmd)
and `data` folders (.csv or .txt) in github, and .html -files
point to knitted notebooks.
- Most examples have cleaned data in .csv file in `data` subfolder
for easy experimenting. For completeness and reproducibility, the
data subfolders have also the raw data and `*_setup.R` file showing
how the data pre-processing has been done (to do the exercises
and follow along with the examples, you don't need to worry about
the setup code).
- For easy access to data sets, there is an R package `rosdata`. You can install it with a command `remotes::install_github("avehtari/ROS-Examples",subdir = "rpackage")`. Then you can access data, for example, as
`library(rosdata)`, `data(wells)`, `head(wells)`. You can get the list of data sets with `?rosdata`.
- When running the notebooks, to avoid need to switch the working directory, `rprojroot` package is used to set the project root directory. The downloaded git repository can be placed anywhere you like and you can rename the ROS-Examples directory if you wish. When running the code, it is sufficient that the working directory is any directory in the ROS-Examples (or renamed). Running
```
library("rprojroot")
root<-has_file(".ROS-Examples-root")$make_fix_file()
```
will find the file `.ROS-Examples-root` which is in the `ROS-Examples` directory, and will set the full path according to that. Then, for example,
```
wells <- read.csv(root("Arsenic/data","wells.csv"))
```
finds the `wells.csv` file, no matter where you have placed or renamed the `ROS-Examples` directory. When you switch to another example, there is no need to switch the working directory.
-------------
## Examples by chapters
### 1 Introduction
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [ElectricCompany/](https://github.com/avehtari/ROS-Examples/tree/master/ElectricCompany/)
- [electric.html](ElectricCompany/electric.html) - Analysis of "Electric company" data
- [Peacekeeping/](https://github.com/avehtari/ROS-Examples/tree/master/Peacekeeping/)
- [peace.html](Peacekeeping/peace.html) - Outcomes after civil war in countries with and without United Nations peacekeeping
- [SimpleCausal/](https://github.com/avehtari/ROS-Examples/tree/master/SimpleCausal/)
- [causal.html](SimpleCausal/causal.html) - Simple graphs illustrating regression for causal inference
- [Helicopters/](https://github.com/avehtari/ROS-Examples/tree/master/Helicopters/)
- [helicopters.html](Helicopters/helicopters.html) - Example data file for helicopter flying time exercise
### 2 Data and measurement
- [HDI/](https://github.com/avehtari/ROS-Examples/tree/master/HDI/)
- [hdi.html](HDI/hdi.html) - Human Development Index - Looking at data in different ways
- [Pew/](https://github.com/avehtari/ROS-Examples/tree/master/Pew/)
- [pew.html](Pew/pew.html) - Miscellaneous analyses using raw Pew data
- [HealthExpenditure/](https://github.com/avehtari/ROS-Examples/tree/master/HealthExpenditure/)
- [healthexpenditure.html](HealthExpenditure/healthexpenditure.html) - Discovery through graphs of data and models
- [Names/](https://github.com/avehtari/ROS-Examples/tree/master/Names/)
- [names.html](Names/names.html) - Names - Distributions of names of American babies
- [lastletters.html](Names/lastletters.html) - Last letters - Distributions of last letters of names of American babies
- [AgePeriodCohort/](https://github.com/avehtari/ROS-Examples/tree/master/AgePeriodCohort/)
- [births.html](AgePeriodCohort/births.html) - Age adjustment
- [Congress/](https://github.com/avehtari/ROS-Examples/tree/master/Congress/)
- [congress_plots.html](Congress/congress_plots.html) - Predictive uncertainty for congressional elections
### 3 Some basic methods in mathematics and probability
- [Mile/](https://github.com/avehtari/ROS-Examples/tree/master/Mile/)
- [mile.html](Mile/mile.html) - Trend of record times in the mile run
- [Metabolic/](https://github.com/avehtari/ROS-Examples/tree/master/Metabolic/)
- [metabolic.html](Metabolic/metabolic.html) - How to interpret a power law or log-log regression
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [height_and_weight.html](Earnings/height_and_weight.html) - Predict weight
- [CentralLimitTheorem/](https://github.com/avehtari/ROS-Examples/tree/master/CentralLimitTheorem/)
- [heightweight.html](CentralLimitTheorem/heightweight.html) - Illustrate central limit theorem and normal distribution
- [Stents/](https://github.com/avehtari/ROS-Examples/tree/master/Stents/)
- [stents.html](Stents/stents.html) - Stents - comparing distributions
### 4 Generative models and statistical inference
- [Coverage/](https://github.com/avehtari/ROS-Examples/tree/master/Coverage/)
- [coverage.html](Coverage/coverage.html) - Example of coverage
- [Death/](https://github.com/avehtari/ROS-Examples/tree/master/Death/)
- [polls.html](Death/polls.html) - Proportion of American adults supporting the death penalty
- [Coop/](https://github.com/avehtari/ROS-Examples/tree/master/Coop/)
- [riverbay.html](Coop/riverbay.html) - Example of hypothesis testing
- [Girls/](https://github.com/avehtari/ROS-Examples/tree/master/Girls/)
### 5 Simulation
- [ProbabilitySimulation/](https://github.com/avehtari/ROS-Examples/tree/master/ProbabilitySimulation/)
- [probsim.html](ProbabilitySimulation/probsim.html) - Simulation of probability models
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [earnings_bootstrap.html](Earnings/earnings_bootstrap.html) - Bootstrapping to simulate the sampling distribution
### 6 Background on regression modeling
- [Simplest/](https://github.com/avehtari/ROS-Examples/tree/master/Simplest/)
- [simplest.html](Simplest/simplest.html) - Linear regression with a single predictor
- [simplest_lm.html](Simplest/simplest_lm.html) - Linear least squares regression with a single predictor
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [earnings_regression.html](Earnings/earnings_regression.html) - Predict respondents' yearly earnings using survey data from 1990.
- [PearsonLee/](https://github.com/avehtari/ROS-Examples/tree/master/PearsonLee/)
- [heights.html](PearsonLee/heights.html) - The heredity of height. Published in 1903 by Karl Pearson and Alice Lee.
- [FakeMidtermFinal/](https://github.com/avehtari/ROS-Examples/tree/master/FakeMidtermFinal/)
- [simulation.html](FakeMidtermFinal/simulation.html) - Fake dataset of 1000 students' scores on a midterm and final exam
### 7 Linear regression with a single predictor
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [hills.html](ElectionsEconomy/hills.html) - Present uncertainty in parameter estimates
- [hibbs_coverage.html](ElectionsEconomy/hibbs_coverage.html) - Checking the coverage of intervals
- [Simplest/](Simplest/)
- [simplest.html](Simplest/simplest.html) - Linear regression with a single predictor
- [simplest_lm.html](Simplest/simplest_lm.html) - Linear least squares regression with a single predictor
### 8 Fitting regression models
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [Influence/](https://github.com/avehtari/ROS-Examples/tree/master/Influence/)
- [influence.html](Influence/influence.html) - Influence of individual points in a fitted regression
### 9 Prediction and Bayesian inference
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [bayes.html](ElectionsEconomy/bayes.html) - Demonstration of Bayesian information aggregation
- [SexRatio/](https://github.com/avehtari/ROS-Examples/tree/master/SexRatio/)
- [sexratio.html](SexRatio/sexratio.html) - Example where an informative prior makes a difference
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [height_and_weight.html](Earnings/height_and_weight.html) - Predict weight
- [earnings_regression.html](Earnings/earnings_regression.html) - Predict respondents' yearly earnings using survey data from 1990.
### 10 Linear regression with multiple predictors
- [KidIQ/](https://github.com/avehtari/ROS-Examples/tree/master/KidIQ/)
- [kidiq.html](KidIQ/kidiq.html) - Linear regression with multiple predictors
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [height_and_weight.html](Earnings/height_and_weight.html) - Predict weight
- [Congress/](https://github.com/avehtari/ROS-Examples/tree/master/Congress/)
- [congress.html](Congress/congress.html) - Predictive uncertainty for congressional elections
- [NES/](https://github.com/avehtari/ROS-Examples/tree/master/NES/)
- [nes_linear.html](NES/nes_linear.html) - Fitting the same regression to many datasets
- [Beauty/](https://github.com/avehtari/ROS-Examples/tree/master/Beauty/)
- [beauty.html](Beauty/beauty.html) - Student evaluations of instructors’ beauty and teaching quality
### 11 Assumptions, diagnostics, and model evaluation
- [KidIQ/](https://github.com/avehtari/ROS-Examples/tree/master/KidIQ/)
- [kidiq.html](KidIQ/kidiq.html) - Linear regression with multiple predictors
- [kidiq_loo.html](KidIQ/kidiq_loo.html) - Linear regression and leave-one-out cross-validation
- [kidiq_R2.html](KidIQ/kidiq_R2.html) - Linear regression and Bayes-R2 and LOO-R2
- [kidiq_kcv.html](KidIQ/kidiq_kcv.html) - Linear regression and K-fold cross-validation
- [Residuals/](https://github.com/avehtari/ROS-Examples/tree/master/Residuals/)
- [residuals.html](Residuals/residuals.html) - Plotting the data and fitted model
- [Introclass/](https://github.com/avehtari/ROS-Examples/tree/master/Introclass/)
- [residual_plots.html](Introclass/residual_plots.html) - Plot residuals vs.\ predicted values, or residuals vs.\ observed values?
- [Newcomb/](https://github.com/avehtari/ROS-Examples/tree/master/Newcomb/)
- [newcomb.html](Newcomb/newcomb.html) - Posterior predictive checking of Normal model for Newcomb's speed of light data
- [Unemployment/](https://github.com/avehtari/ROS-Examples/tree/master/Unemployment/)
- [unemployment.html](Unemployment/unemployment.html) - Time series fit and posterior predictive model checking for unemployment series
- [Rsquared/](https://github.com/avehtari/ROS-Examples/tree/master/Rsquared/)
- [rsquared.html](Rsquared/rsquared.html) - Bayesian R^2
- [CrossValidation/](https://github.com/avehtari/ROS-Examples/tree/master/CrossValidation/)
- [crossvalidation.html](CrossValidation/crossvalidation.html) - Demonstration of cross validation
- [FakeKCV/](https://github.com/avehtari/ROS-Examples/tree/master/FakeKCV/)
- [fake_kcv.html](FakeKCV/fake_kcv.html) - Demonstration of $K$-fold cross-validation using simulated data
- [Pyth/](https://github.com/avehtari/ROS-Examples/tree/master/Pyth/)
### 12 Transformations
- [KidIQ/](https://github.com/avehtari/ROS-Examples/tree/master/KidIQ/)
- [kidiq.html](KidIQ/kidiq.html) - Linear regression with multiple predictors
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [earnings_regression.html](Earnings/earnings_regression.html) - Predict respondents' yearly earnings using survey data from 1990.
- [Gay/](https://github.com/avehtari/ROS-Examples/tree/master/Gay/)
- [gay_simple.html](Gay/gay_simple.html) - Simple models (linear and discretized age) and political attitudes as a function of age
- [Mesquite/](https://github.com/avehtari/ROS-Examples/tree/master/Mesquite/)
- [mesquite.html](Mesquite/mesquite.html) - Predicting the yields of mesquite bushes
- [Student/](https://github.com/avehtari/ROS-Examples/tree/master/Student/)
- [student.html](Student/student.html) - Models for regression coefficients
- [Pollution/](https://github.com/avehtari/ROS-Examples/tree/master/Pollution/)
- [pollution.html](Pollution/pollution.html) - Pollution data.
### 13 Logistic regression
- [NES/](https://github.com/avehtari/ROS-Examples/tree/master/NES/)
- [nes_logistic.html](NES/nes_logistic.html) - Logistic regression, identifiability, and separation
- [LogisticPriors/](https://github.com/avehtari/ROS-Examples/tree/master/LogisticPriors/)
- [logistic_priors.html](LogisticPriors/logistic_priors.html) - Effect of priors in logistic regression
- [Arsenic/](https://github.com/avehtari/ROS-Examples/tree/master/Arsenic/)
- [arsenic_logistic_building.html](Arsenic/arsenic_logistic_building.html) - Building a logistic regression model: wells in Bangladesh
### 14 Working with logistic regression
- [LogitGraphs/](https://github.com/avehtari/ROS-Examples/LogitGraphs/)
- [logitgraphs.html](LogitGraphs/logitgraphs.html) - Different ways of displaying logistic regression
- [NES/](https://github.com/avehtari/ROS-Examples/tree/master/NES/)
- [nes_logistic.html](NES/nes_logistic.html) - Logistic regression, identifiability, and separation
- [Rodents/](https://github.com/avehtari/ROS-Examples/tree/master/Rodents/)
- [Arsenic/](https://github.com/avehtari/ROS-Examples/tree/master/Arsenic/)
- [arsenic_logistic_residuals.html](Arsenic/arsenic_logistic_residuals.html) - Residual plots for a logistic regression model: wells in Bangladesh
- [arsenic_logistic_apc.html](Arsenic/arsenic_logistic_apc.html) - Average predictice comparisons for a logistic regression model: wells in Bangladesh
### 15 Other generalized linear models
- [PoissonExample/](https://github.com/avehtari/ROS-Examples/tree/master/PoissonExample/)
- [PoissonExample.html](PoissonExample/poisson_regression.html) - Demonstrate Poisson regression with simulated data.
- [Roaches/](https://github.com/avehtari/ROS-Examples/tree/master/Roaches/)
- [roaches.html](Roaches/roaches.html) - Analyse the effect of integrated pest management on reducing cockroach levels in urban apartments
- [Storable/](https://github.com/avehtari/ROS-Examples/tree/master/Storable/)
- [storable.html](Storable/storable.html) - Ordered categorical data analysis with a study from experimental economics, on the topic of ``storable votes.''
- [Robit/](https://github.com/avehtari/ROS-Examples/tree/master/Robit/)
- [robit.html](Robit/robit.html) - Comparison of robit and logit models for binary data
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [earnings_compound.html](Earnings/earnings_compound.html) - Compound discrete-continuos model
- [RiskyBehavior/](https://github.com/avehtari/ROS-Examples/tree/master/RiskyBehavior/)
- [risky.html](RiskyBehavior/risky.html) Risky behavior data.
- [NES/](https://github.com/avehtari/ROS-Examples/tree/master/NES/)
- [Lalonde/](https://github.com/avehtari/ROS-Examples/tree/master/Lalonde/)
- [Congress/](https://github.com/avehtari/ROS-Examples/tree/master/Congress/)
- [AcademyAwards/](https://github.com/avehtari/ROS-Examples/tree/master/AcademyAwards/)
### 16 Design and sample size decisions
- [ElectricCompany/](https://github.com/avehtari/ROS-Examples/tree/master/ElectricCompany/)
- [electric.html](ElectricCompany/electric.html) - Analysis of "Electric company" data
- [SampleSize/](https://github.com/avehtari/ROS-Examples/tree/master/SampleSize/)
- [simulation.html](DataCollection/simulation.html) - Sample size simulation
- [FakeMidtermFinal/](https://github.com/avehtari/ROS-Examples/tree/master/FakeMidtermFinal/)
- [simulation_based_design.html](FakeMidtermFinal/simulation_based_design.html) - Fake dataset of a randomized experiment on student grades
### 17 Poststratification and missing-data imputation
- [Poststrat/](https://github.com/avehtari/ROS-Examples/tree/master/Poststrat/)
- [poststrat.html](Poststrat/poststrat.html) - Poststratification after estimation
- [poststrat2.html](Poststrat/poststrat2.html) - Poststratification after estimation
- [Imputation/](https://github.com/avehtari/ROS-Examples/tree/master/Imputation/)
- [imputation.html](Imputation/imputation.html) - Regression-based imputation for the Social Indicators Survey
- [imputation_gg.html](Imputation/imputation_gg.html) - Regression-based imputation for the Social Indicators Survey, dplyr/ggplot version
### 18 Causal inference basics and randomized experiments
- [Sesame/](https://github.com/avehtari/ROS-Examples/tree/master/Sesame/)
- [sesame.html](Sesame/sesame.html) - Causal analysis of Sesame Street experiment
### 19 Causal inference using regression on the treatment variable
- [ElectricCompany/](https://github.com/avehtari/ROS-Examples/tree/master/ElectricCompany/)
- [electric.html](ElectricCompany/electric.html) - Analysis of "Electric company" data
- [Incentives/]((https://github.com/avehtari/ROS-Examples/tree/master/Incentives/))
- [incentives.html](Incentives/incentives.html) - Simple analysis of incentives data
- [Cows/](https://github.com/avehtari/ROS-Examples/tree/master/Cows/)
### 20 Observational studies with all confounders assumed to be measured
- [ElectricCompany/](https://github.com/avehtari/ROS-Examples/tree/master/ElectricCompany/)
- [electric.html](ElectricCompany/electric.html) - Analysis of "Electric company" data
- [Childcare/](https://github.com/avehtari/ROS-Examples/tree/master/Childcare/)
- [childcare.html](Childcare/childcare.html) - Infant Health and Development Program (IHDP) example.
### 21 More advanced topics in causal inference
- [Sesame/](https://github.com/avehtari/ROS-Examples/tree/master/Sesame/)
- [sesame.html](Sesame/sesame.html) - Causal analysis of Sesame Street experiment
- [Bypass/](https://github.com/avehtari/ROS-Examples/tree/master/Pypass/)
- [ChileSchools/](https://github.com/avehtari/ROS-Examples/tree/master/ChileSchools/)
- [chile_schools.html](ChileSchools/chile_schools.html) - ChileSchools example.
### 22 Advanced regression and multilevel models
- [Golf/](https://github.com/avehtari/ROS-Examples/tree/master/Golf/)
- [golf.html](Golf/golf.html) - Gold putting accuracy: Fitting a nonlinear model using Stan
- [Gay/](https://github.com/avehtari/ROS-Examples/tree/master/Gay/)
- [gay.html](Gay/gay.html) - Nonlinear models (Loess, B-spline, GP-spline, and BART) and political attitudes as a function of age
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [Scalability/](https://github.com/avehtari/ROS-Examples/tree/master/Scalability/)
- [scalability.html](Scalability/scalability.html) - Demonstrate computation speed with 100 000 observations.
### Appendix A
- [Coins/](https://github.com/avehtari/ROS-Examples/tree/master/Coins/)
- [Mile/](https://github.com/avehtari/ROS-Examples/tree/master/Mile/)
- [mile.html](Mile/mile.html) - Trend of record times in the mile run
- [Parabola/](https://github.com/avehtari/ROS-Examples/tree/master/Parabola/)
- [parabola.html](Parabola/parabola.html) - Demonstration of using Stan for optimization
- [Restaurant/](https://github.com/avehtari/ROS-Examples/tree/master/Restaurant/)
- [restaurant.html](Restaurant/restaurant.html) - Demonstration of using Stan for optimization
- [DifferentSoftware/](https://github.com/avehtari/ROS-Examples/tree/master/DifferentSoftware/)
- [linear.html](DifferentSoftware/linear.html) - Linear regression using different software options
-------------
## Examples alphabetically
- [AcademyAwards/](https://github.com/avehtari/ROS-Examples/tree/master/AcademyAwards/)
- [AgePeriodCohort/](https://github.com/avehtari/ROS-Examples/tree/master/AgePeriodCohort/)
- [births.html](AgePeriodCohort/births.html) - Age adjustment
- [Arsenic/](https://github.com/avehtari/ROS-Examples/tree/master/Arsenic/)
- [arsenic_logistic_building.html](Arsenic/arsenic_logistic_building.html) - Building a logistic regression model: wells in Bangladesh
- [arsenic_logistic_residuals.html](Arsenic/arsenic_logistic_residuals.html) - Residual plots for a logistic regression model: wells in Bangladesh
- [arsenic_logistic_apc.html](Arsenic/arsenic_logistic_apc.html) - Average predictice comparisons for a logistic regression model: wells in Bangladesh
- [arsenic_logistic_building_optimizing.html](Arsenic/arsenic_logistic_building_optimizing.html) - Building a logistic regression model: wells in Bangladesh. A version with normal approximation at the mode.
- [Balance/](https://github.com/avehtari/ROS-Examples/tree/master/Balance/)
- [treatcontrol.html](Balance/treatcontrol.html)
- [Beauty/](https://github.com/avehtari/ROS-Examples/tree/master/Beauty/)
- [beauty.html](Beauty/beauty.html) - Student evaluations of instructors’ beauty and teaching quality
- [Bypass/](https://github.com/avehtari/ROS-Examples/tree/master/Bypass/)
- [CausalDiagram/](https://github.com/avehtari/ROS-Examples/tree/master/CausalDiagram/)
- [diagrams.html](CausalDiagram/diagrams.html) - Plot causal diagram
- [CentralLimitTheorem/](https://github.com/avehtari/ROS-Examples/tree/master/CentralLimitTheorem/)
- [heightweight.html](CentralLimitTheorem/heightweight.html) - Illustrate central limit theorem and normal distribution
- [Childcare/](https://github.com/avehtari/ROS-Examples/tree/master/Childcare/)
- [childcare.html](Childcare/childcare.html) - Infant Health and Development Program (IHDP) example.
- [ChileSchools/](https://github.com/avehtari/ROS-Examples/tree/master/ChileSchools/)
- [chile_schools.html](ChileSchools/chile_schools.html) - ChileSchools example.
- [Coins/](https://github.com/avehtari/ROS-Examples/tree/master/Coins/)
- [Congress/](https://github.com/avehtari/ROS-Examples/tree/master/Congress/)
- [congress.html](Congress/congress.html) - Predictive uncertainty for congressional elections
- [congress_plots.html](Congress/congress_plots.html) - Predictive uncertainty for congressional elections
- [Coop/](https://github.com/avehtari/ROS-Examples/tree/master/Coop/)
- [riverbay.html](Coop/riverbay.html) - Example of hypothesis testing
- [Coverage/](https://github.com/avehtari/ROS-Examples/tree/master/Coverage/)
- [coverage.html](Coverage/coverage.html) - Example of coverage
- [Cows/](https://github.com/avehtari/ROS-Examples/tree/master/Cows/)
- [CrossValidation/](https://github.com/avehtari/ROS-Examples/tree/master/CrossValidation/)
- [crossvalidation.html](CrossValidation/crossvalidation.html) - Demonstration of cross validation
- [SampleSize/](https://github.com/avehtari/ROS-Examples/tree/master/SampleSize/)
- [simulation.html](DataCollection/simulation.html) - Sample size simulation
- [Death/](https://github.com/avehtari/ROS-Examples/tree/master/Death/)
- [polls.html](Death/polls.html) - Proportion of American adults supporting the death penalty
- [DifferentSoftware/](https://github.com/avehtari/ROS-Examples/tree/master/DifferentSoftware/)
- [linear.html](DifferentSoftware/linear.html) - Linear regression using different software options
- [Earnings/](https://github.com/avehtari/ROS-Examples/tree/master/Earnings/)
- [earnings_regression.html](Earnings/earnings_regression.html) - Predict respondents' yearly earnings using survey data from 1990.
- [earnings_bootstrap.html](Earnings/earnings_bootstrap.html) - Bootstrapping to simulate the sampling distribution
- [earnings_compound.html](Earnings/earnings_compound.html) - Compound discrete-continuos model
- [height_and_weight.html](Earnings/height_and_weight.html) - Predict weight
- [ElectionsEconomy/](https://github.com/avehtari/ROS-Examples/tree/master/ElectionsEconomy/)
- [bayes.html](ElectionsEconomy/bayes.html) - Demonstration of Bayesian information aggregation
- [hibbs.html](ElectionsEconomy/hibbs.html) - Predicting presidential vote share from the economy
- [hills.html](ElectionsEconomy/hills.html) - Present uncertainty in parameter estimates
- [hibbs_coverage.html](ElectionsEconomy/hibbs_coverage.html) - Checking the model-fitting procedure using fake-data simulation.
- [ElectricCompany/](https://github.com/avehtari/ROS-Examples/tree/master/ElectricCompany/)
- [electric.html](ElectricCompany/electric.html) - Analysis of "Electric company" data
- [FakeKCV/](https://github.com/avehtari/ROS-Examples/tree/master/FakeKCV/)
- [fake_kcv.html](FakeKCV/fake_kcv.html) - Demonstration of $K$-fold cross-validation using simulated data
- [FakeMidtermFinal/](https://github.com/avehtari/ROS-Examples/tree/master/FakeMidtermFinal/)
- [simulation.html](FakeMidtermFinal/simulation.html) - Fake dataset of 1000 students' scores on a midterm and final exam
- [simulation_based_design.html](FakeMidtermFinal/simulation_based_design.html) - Fake dataset of a randomized experiment on student grades
- [FrenchElection/](https://github.com/avehtari/ROS-Examples/tree/master/FrenchElection/)
- [ps_primaire.html](FrenchElection/ps_primaire.html) - French Election data
- [Gay/](https://github.com/avehtari/ROS-Examples/tree/master/Gay/)
- [gay_simple.html](Gay/gay_simple.html) - Simple models (linear and discretized age) and political attitudes as a function of age
- [gay.html](Gay/gay.html) - Nonlinear models (Loess, B-spline, GP-spline, and BART) and political attitudes as a function of age
- [Girls/](https://github.com/avehtari/ROS-Examples/tree/master/Girls/)
- [Golf/](https://github.com/avehtari/ROS-Examples/tree/master/Golf/)
- [golf.html](Golf/golf.html) - Gold putting accuracy: Fitting a nonlinear model using Stan
- [HDI/](https://github.com/avehtari/ROS-Examples/HDI/)
- [hdi.html](HDI/hdi.html) - Human Development Index - Looking at data in different ways
- [HealthExpenditure/](https://github.com/avehtari/ROS-Examples/tree/master/HealthExpenditure/)
- [healthexpenditure.html](HealthExpenditure/healthexpenditure.html) - Discovery through graphs of data and models
- [Helicopters/](https://github.com/avehtari/ROS-Examples/tree/master/Helicopters/)
- [helicopters.html](Helicopters/helicopters.html) - Example data file for helicopter flying time exercise
- [Imputation/](https://github.com/avehtari/ROS-Examples/tree/master/Imputation/)
- [imputation.html](Imputation/imputation.html) - Regression-based imputation for the Social Indicators Survey
- [imputation_gg.html](Imputation/imputation_gg.html) - Regression-based imputation for the Social Indicators Survey, dplyr/ggplot version
- [Incentives/]((https://github.com/avehtari/ROS-Examples/tree/master/Incentives/))
- [incentives.html](Incentives/incentives.html) - Simple analysis of incentives data
- [Influence/](https://github.com/avehtari/ROS-Examples/tree/master/Influence/)
- [influence.html](Influence/influence.html) - Influence of individual points in a fitted regression
- [Interactions/](https://github.com/avehtari/ROS-Examples/tree/master/Interactions/)
- [interactions.html](Interactions/interactions.html) - Plot interaction example figure
- [Introclass/](https://github.com/avehtari/ROS-Examples/tree/master/Introclass/)
- [residual_plots.html](Introclass/residual_plots.html) - Plot residuals vs.\ predicted values, or residuals vs.\ observed values?
- [KidIQ/](https://github.com/avehtari/ROS-Examples/tree/master/KidIQ/)
- [kidiq.html](KidIQ/kidiq.html) - Linear regression with multiple predictors
- [kidiq_loo.html](KidIQ/kidiq_loo.html) - Linear regression and leave-one-out cross-validation
- [kidiq_R2.html](KidIQ/kidiq_R2.html) - Linear regression and Bayes-R2 and LOO-R2
- [kidiq_kcv.html](KidIQ/kidiq_kcv.html) - Linear regression and K-fold cross-validation
- [Lalonde/](https://github.com/avehtari/ROS-Examples/tree/master/Lalonde/)
- [LogisticPriors/](https://github.com/avehtari/ROS-Examples/tree/master/LogisticPriors/)
- [logistic_priors.html](LogisticPriors/logistic_priors.html) - Effect of priors in logistic regression
- [Mesquite/](https://github.com/avehtari/ROS-Examples/tree/master/Mesquite/)
- [mesquite.html](Mesquite/mesquite.html) - Predicting the yields of mesquite bushes
- [Metabolic/](https://github.com/avehtari/ROS-Examples/tree/master/Metabolic/)
- [metabolic.html](Metabolic/metabolic.html) - How to interpret a power law or log-log regression
- [Mile/](https://github.com/avehtari/ROS-Examples/tree/master/Mile/)
- [mile.html](Mile/mile.html) - Trend of record times in the mile run
- [Names/](https://github.com/avehtari/ROS-Examples/tree/master/Names/)
- [names.html](Names/names.html) - Names - Distributions of names of American babies
- [lastletters.html](Names/lastletters.html) - Last letters - Distributions of last letters of names of American babies
- [NES/](https://github.com/avehtari/ROS-Examples/tree/master/NES/)
- [nes_linear.html](NES/nes_linear.html) - Fitting the same regression to many datasets
- [nes_logistic.html](NES/nes_logistic.html) - Logistic regression, identifiability, and separation
- [Newcomb/](https://github.com/avehtari/ROS-Examples/tree/master/Newcomb/)
- [newcomb.html](Newcomb/newcomb.html) - Posterior predictive checking of Normal model for Newcomb's speed of light data
- [Parabola/](https://github.com/avehtari/ROS-Examples/tree/master/Parabola/)
- [parabola.html](Parabola/parabola.html) - Demonstration of using Stan for optimization
- [Peacekeeping/](https://github.com/avehtari/ROS-Examples/tree/master/Peacekeeping/)
- [peace.html](Peacekeeping/peace.html) - Outcomes after civil war in countries with and without United Nations peacekeeping
- [PearsonLee/](https://github.com/avehtari/ROS-Examples/tree/master/PearsonLee/)
- [heights.html](PearsonLee/heights.html) - The heredity of height. Published in 1903 by Karl Pearson and Alice Lee.
- [Pew/](https://github.com/avehtari/ROS-Examples/tree/master/Pew/)
- [pew.html](Pew/pew.html) - Miscellaneous analyses using raw Pew data
- [PoissonExample/](https://github.com/avehtari/ROS-Examples/tree/master/PoissonExample/)
- [poissonexample.html](PoissonExample/poissonexample.html) - Demonstrate Poisson regression with simulated data.
- [Pollution/](https://github.com/avehtari/ROS-Examples/tree/master/Pollution/)
- [pollution.html](Pollution/pollution.html) - Pollution data.
- [Poststrat/](https://github.com/avehtari/ROS-Examples/tree/master/Poststrat/)
- [poststrat.html](Poststrat/poststrat.html) - Poststratification after estimation
- [poststrat2.html](Poststrat/poststrat2.html) - Poststratification after estimation
- [ProbabilitySimulation/](https://github.com/avehtari/ROS-Examples/tree/master/ProbabilitySimulation/)
- [probsim.html](ProbabilitySimulation/probsim.html) - Simulation of probability models
- [Pyth/](https://github.com/avehtari/ROS-Examples/tree/master/Pyth/)
- [Redistricting/](https://github.com/avehtari/ROS-Examples/tree/master/Redistricting/)
- [Residuals/](https://github.com/avehtari/ROS-Examples/tree/master/Residuals/)
- [residuals.html](Residuals/residuals.html) - Plotting the data and fitted model
- [Restaurant/](https://github.com/avehtari/ROS-Examples/tree/master/Restaurant/)
- [restaurant.html](Restaurant/restaurant.html) - Demonstration of using Stan for optimization
- [RiskyBehavior/](https://github.com/avehtari/ROS-Examples/tree/master/RiskyBehavior/)
- [risky.html](RiskyBehavior/risky.html) Risky behavior data.
- [Roaches/](https://github.com/avehtari/ROS-Examples/tree/master/Roaches/)
- [roaches.html](Roaches/roaches.html) - Analyse the effect of integrated pest management on reducing cockroach levels in urban apartments
- [Robit/](https://github.com/avehtari/ROS-Examples/tree/master/Robit/)
- [robit.html](Robit/robit.html) - Comparison of robit and logit models for binary data
- [Rodents/](https://github.com/avehtari/ROS-Examples/tree/master/Rodents/)
- [Rsquared/](https://github.com/avehtari/ROS-Examples/tree/master/Rsquared/)
- [rsquared.html](Rsquared/rsquared.html) - Bayesian R^2
- [Sesame/](https://github.com/avehtari/ROS-Examples/tree/master/Sesame/)
- [sesame.html](Sesame/sesame.html) - Causal analysis of Sesame Street experiment
- [SexRatio/](https://github.com/avehtari/ROS-Examples/tree/master/SexRatio/)
- [sexratio.html](SexRatio/sexratio.html) - Example where an informative prior makes a difference
- [SimpleCausal/](https://github.com/avehtari/ROS-Examples/tree/master/SimpleCausal/)
- [causal.html](SimpleCausal/causal.html) - Simple graphs illustrating regression for causal inference
- [Simplest/](https://github.com/avehtari/ROS-Examples/tree/master/Simplest/)
- [simplest.html](Simplest/simplest.html) - Linear regression with a single predictor
- [simplest_lm.html](Simplest/simplest_lm.html) - Linear least squares regression with a single predictor
- [Stents/](https://github.com/avehtari/ROS-Examples/tree/master/Stents/)
- [stents.html](Stents/stents.html) - Stents - comparing distributions
- [Storable/](https://github.com/avehtari/ROS-Examples/tree/master/Storable/)
- [storable.html](Storable/storable.html) - Ordered categorical data analysis with a study from experimental economics, on the topic of ``storable votes.''
- [Student/](https://github.com/avehtari/ROS-Examples/tree/master/Student/)
- [student.html](Student/student.html) - Models for regression coefficients
- [Unemployment/](https://github.com/avehtari/ROS-Examples/tree/master/Unemployment/)
- [unemployment.html](Unemployment/unemployment.html) - Time series fit and posterior predictive model checking for unemployment series
-------------
## Download code and data
- [Git repo for the code and data](https://github.com/avehtari/ROS-Examples)
- [Download all code and data as a ZIP file](https://codeload.github.com/avehtari/ROS-Examples/zip/master)
## Tidyverse code
Bill Behrman has revised all the example code to use Tidyverse
- [Regression and Other Stories - Tidyverse Examples](https://github.com/behrman/ros)
- [Style guide used by Behrman](http://dcl-workflow.stanford.edu/style-guide.html)
## brms + tidyverse code
Solomon A. Kurz is revising all the example code to use brms and tidyverse
- [Working through Regression and other stories](https://github.com/ASKurz/Working-through-Regression-and-other-stories)
## Python code
Ravin Kumar, Tomás Capretto, and Osvaldo Martin are porting ROS
examples to Python using bambi (BAyesian Model-Building Interface)
which has similar formula syntax as rstanarm and brms.
- [Bambi resources](https://github.com/bambinos/Bambi_resources)
## Julia code
Rob J. Goedman is porting ROS examples to Julia.
- [RegressionAndOtherStories.jl](https://github.com/RegressionAndOtherStoriesJulia/RegressionAndOtherStories.jl)