Skip to content

Instantly share code, notes, and snippets.

@dill
Last active November 5, 2019 16:15
Show Gist options
  • Save dill/292d55fcd01a36bcae3743ad1f16f421 to your computer and use it in GitHub Desktop.
Save dill/292d55fcd01a36bcae3743ad1f16f421 to your computer and use it in GitHub Desktop.
deep dive into a terrible graphic (laffer curve)
tax_rate tax_rev
0.07357329 -0.0567062
8.81285407 2.4505785
12.84385295 3.5807126
16.23680790 2.1860302
19.18260073 2.4643621
19.29050823 1.9514672
18.45218145 1.2480201
26.73285538 1.5886201
22.37159417 3.3657369
25.35785231 2.8740010
23.20419858 5.7879019
28.31835981 10.0210381
30.29993378 5.7198302
28.31631610 4.8265564
27.46000474 3.4932956
28.39888169 3.1676883
29.23925217 3.6168644
30.38903921 3.7964138
33.25063150 5.5009854
30.34612146 3.1687765
30.42623460 2.8969737
34.29700720 3.5799872
35.32498958 3.3917323
34.79607936 3.0661250
33.30172407 2.7568404
33.23959551 2.2382628
34.29087609 2.2232701
35.43003589 2.1847002
35.40428524 2.7835612
# context: https://twitter.com/realwokieleaks/status/1057798810804645893
# load data
dat <- read.csv("dat.csv")
# data slurped using the digitize R package
# "normal" fit
b <- gam(tax_rev~s(tax_rate), data=dat, method="REML")
# yes ignoring that the response is >0 for now...
# plot that, yeah that seems like it's okay?
par(mfrow=c(1,2))
plot(b, xlim=c(0, 50), ylim=c(0, 10), shift=coef(b)[1], shade=TRUE, main="not silly")
# which points shall we uber weight?
text(dat, labels=1:nrow(dat))
# UAE is 1
# Norway is 12
weights <- rep(1, nrow(dat))
weights[1] <- 1e5
weights[12] <- 1e5
# maxing out basis complexity, using weights
b_w <- gam(tax_rev~s(tax_rate, k=nrow(dat)-1), data=dat, method="REML", weights=weights)
plot(b_w, xlim=c(0, 50), ylim=c(0, 10), shift=coef(b)[1], n=200, shade=TRUE, main="silly")
points(dat)
@dill
Copy link
Author

dill commented Nov 1, 2018

Produces this graphic:
screen shot 2018-11-01 at 10 43 59

@ahurford
Copy link

ahurford commented Nov 5, 2019

Sadly, the link at the top of the code doesn't yield the original graphic since some tweets have been deleted. Is it possible to archive that figure with this too, i.e., this link https://twitter.com/rlmcelreath/status/1191649370569166848 or ideally something more permanent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment