Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Last active August 29, 2015 14:02
Show Gist options
  • Save mbusigin/093abd156fe4a6224b27 to your computer and use it in GitHub Desktop.
Save mbusigin/093abd156fe4a6224b27 to your computer and use it in GitHub Desktop.
Scatter of 12m average miles driven %-y/y vs population & labour force
getSymbols(c("M12MTVUSM227NFWA", "CNP16OV", "CLF16OV"), src="FRED")
a = na.omit(merge(Delt(M12MTVUSM227NFWA, k=12), Delt(CNP16OV, k=12), Delt(CLF16OV, k=12)))
plot(as.vector(a[,2]), as.vector(a[,1]), type="p", xlim=c(-.01, .04), ylim=c(-0.04, .08), pch=14, cex=.5, col="red", xlab="x", ylab="M12MTVUSM227NFWA %-y/y")
m2 = lm(a[,1] ~ a[,2])
abline(m2, col="red")
points(as.vector(a[,3]), as.vector(a[,1]), pch=16, col="dodgerblue3", cex=.5)
m3 = lm(a[,1] ~ a[,3])
abline(m3, col="dodgerblue3")
legend("topleft", c("x = CNP16OV %-y/y (r=0.326)", "x = CLF16OV %-y/y (r=0.55)"), col=c("red", "dodgerblue3"), pch=c(14, 16), cex=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment