Skip to content

Instantly share code, notes, and snippets.

@mattjj
Created October 4, 2012 01:45
Show Gist options
  • Save mattjj/3831017 to your computer and use it in GitHub Desktop.
Save mattjj/3831017 to your computer and use it in GitHub Desktop.
ADP vs BLS
from __future__ import division
from matplotlib import pyplot as plt
import numpy as np
na = np.newaxis
# I got ADP historical data from the "Historical Data" link here:
# http://www.adpemploymentreport.com/
# I got BLS data here:
# http://data.bls.gov/timeseries/CES0000000001?output_view=net_1mth
# I munged the two into text files for the same dates by hand (copy/paste into vim)
# Both were in an Excel format. Both use seasonal adjustment (ARMIA, I think).
# The ADP data only reports the total numbers and the month-over-month
# percentage changes, so to compare to the BLS arithmetic increments I just take
# first differences of the ADP totals. The data goes from January 2002 to
# August 2012.
# load data
bls = np.loadtxt('data_bls.txt')
adp = np.diff(np.loadtxt('data_adp.txt'))
# regression and correlation
A,(residual,),_,_ = np.linalg.lstsq(np.vstack((adp,np.ones(adp.shape[0]))).T,bls[:,na])
slope,offset = A.flatten()
Rsq = 1. - residual / (bls**2-bls.mean()).sum()
corr = np.corrcoef(adp,bls)[0,1]
# joint Gaussian model
data = np.vstack((adp,bls)).T.copy()
mu = data.mean(0)
sigma = 1/data.shape[0]*(data - mu).T.dot(data-mu)
cond_var = sigma[1,1] - sigma[0,1]**2/sigma[0,0]
# plotting
plt.figure(figsize=(8,10))
plt.subplot(2,1,1)
t = np.arange(adp.min(),adp.max())
plt.plot(adp,bls,'bx')
plt.plot(t,slope*t+offset,'r-',label='regression (R^2=%0.2f,corr=%0.2f)' % (Rsq,corr))
plt.xlabel('ADP')
plt.ylabel('BLS')
plt.legend(loc='lower right')
plt.subplot(2,1,2)
plt.plot(adp,label='ADP')
plt.plot(bls,label='BLS')
plt.legend(loc='lower right')
plt.show()
108813
108711
108545
108484
108432
108414
108365
108306
108299
108254
108282
108188
108162
108136
108100
107958
107898
107870
107866
107907
108006
108145
108263
108328
108524
108571
108717
108908
109184
109417
109572
109793
109938
110069
110309
110491
110667
110844
111071
111236
111408
111585
111736
111915
112069
112248
112404
112648
112734
112933
113224
113402
113543
113650
113807
113909
114051
114066
114197
114412
114533
114666
114753
114904
114966
115011
115110
115125
115073
115043
115048
115149
115192
115233
115165
115115
114994
114865
114656
114480
114202
113877
113465
112857
112155
111404
110625
109840
109196
108746
108305
107952
107736
107550
107440
107290
107156
107127
107153
107202
107311
107392
107443
107507
107577
107594
107686
107770
107983
108187
108384
108583
108745
108792
108928
109053
109120
109225
109367
109593
109860
110042
110270
110474
110586
110717
110890
111046
111235
-129
-146
-24
-84
-9
47
-100
-11
-55
121
8
-163
95
-159
-213
-49
-9
0
25
-45
109
197
14
119
162
44
337
249
310
81
46
122
161
348
63
134
137
240
141
360
170
243
374
193
66
80
334
160
283
316
283
181
14
76
209
183
157
-9
204
171
236
93
190
72
139
75
-40
-18
73
79
112
89
41
-84
-95
-208
-190
-198
-210
-274
-432
-489
-803
-661
-818
-724
-799
-692
-361
-482
-339
-231
-199
-202
-42
-171
-40
-35
189
239
516
-167
-58
-51
-27
220
121
120
110
220
246
251
54
84
96
85
202
112
157
223
275
259
143
68
87
45
141
96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment