Simple analysis of incentives data. See Chapter 19 in Regression and Other Stories.


Load packages

library("rprojroot")
root<-has_dirname("ROS-Examples")$make_fix_file()
library("rstanarm")
library("ggplot2")
library("bayesplot")
theme_set(bayesplot::theme_default(base_family = "sans"))

Load data

incentives <- read.csv(root("Incentives/data","incentives.csv"))
head(incentives)
  rr_diff     value prepay gift burden
1       3  1.241506      1    0      0
2       6  2.466235      1    1      0
3       9 14.713524      0    0      1
4       4 24.628795      0    0      1
5       6 43.117169      0    0      1
6      13 17.313976      0    0      1

Normal linear regression

fit <- stan_glm(rr_diff ~ value + prepay + gift + burden, data=incentives, refresh=0)
print(fit, digits=2)
stan_glm
 family:       gaussian [identity]
 formula:      rr_diff ~ value + prepay + gift + burden
 observations: 62
 predictors:   5
------
            Median MAD_SD
(Intercept)  1.60   1.75 
value        0.12   0.05 
prepay       3.92   2.10 
gift        -5.25   2.29 
burden       2.91   1.56 

Auxiliary parameter(s):
      Median MAD_SD
sigma 5.99   0.59  

------
* For help interpreting the printed output see ?print.stanreg
* For info on the priors used see ?prior_summary.stanreg
LS0tCnRpdGxlOiAiUmVncmVzc2lvbiBhbmQgT3RoZXIgU3RvcmllczogSW5jZW50aXZlcyIKYXV0aG9yOiAiQW5kcmV3IEdlbG1hbiwgSmVubmlmZXIgSGlsbCwgQWtpIFZlaHRhcmkiCmRhdGU6ICJgciBmb3JtYXQoU3lzLkRhdGUoKSlgIgpvdXRwdXQ6CiAgaHRtbF9kb2N1bWVudDoKICAgIHRoZW1lOiByZWFkYWJsZQogICAgdG9jOiB0cnVlCiAgICB0b2NfZGVwdGg6IDIKICAgIHRvY19mbG9hdDogdHJ1ZQogICAgY29kZV9kb3dubG9hZDogdHJ1ZQotLS0KU2ltcGxlIGFuYWx5c2lzIG9mIGluY2VudGl2ZXMgZGF0YS4gU2VlIENoYXB0ZXIgMTkgaW4gUmVncmVzc2lvbgphbmQgT3RoZXIgU3Rvcmllcy4KCi0tLS0tLS0tLS0tLS0KCgpgYGB7ciBzZXR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