data from CDP


In [75]:
import pandas as pd
from scipy.stats import ttest_ind

In [24]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
import prettyplotlib as ppl

In [25]:
import brewer2mpl
set2 = brewer2mpl.get_map('Set2', 'qualitative', 8).mpl_colors
set2[0]


Out[25]:
(0.4, 0.7607843137254902, 0.6470588235294118)

In [26]:
sample = pd.DataFrame.from_csv('sample_company_goals.csv')

In [49]:
have_goals = sample.loc[sample['has goal']==1]
hg_ave_1 = have_goals['% change emissions'].mean()
hg_std_1 = have_goals['% change emissions'].std()
hg_ave_2 = have_goals['% change intensity'].mean()
hg_std_2 = have_goals['% change intensity'].std()
# mean = 0
# variance = 1
# mean2 = 2.5

In [50]:
no_goals = sample.loc[sample['has goal']==0]
ng_ave_1 = no_goals['% change emissions'].mean()
ng_std_1 = no_goals['% change emissions'].std()
ng_ave_2 = no_goals['% change intensity'].mean()
ng_std_2 = no_goals['% change intensity'].std()

In [74]:
[[hg_ave_1, hg_std_1], [hg_ave_2, hg_std_2],
[ng_ave_1, ng_std_1], [ng_ave_2, ng_std_2]]


Out[74]:
[[-0.049000000000000009, 0.3502840117517339],
 [-0.14599999999999999, 0.34179916130187721],
 [0.096250000000000016, 0.44753092470959877],
 [-0.011249999999999996, 0.33972415280636142]]

In [76]:
ttest_ind(have_goals['% change emissions'],no_goals['% change emissions'])


Out[76]:
(-0.77369590048001746, 0.45039170294514297)

In [77]:
ttest_ind(have_goals['% change intensity'],no_goals['% change intensity'])


Out[77]:
(-0.83333487958988717, 0.41692308306003345)

In [78]:
pe_x = np.linspace(-1.5,1.5,100)
hg_pe = mlab.normpdf(pe_x,hg_ave_1,hg_std_1)
ng_pe = mlab.normpdf(pe_x,ng_ave_1,ng_std_1)

In [114]:
hist(no_goals['% change emissions'].values)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-114-50f00b402bf5> in <module>()
----> 1 hist(no_goals['% change emissions'].values)

TypeError: 'tuple' object is not callable

In [117]:
ppl.plot(pe_x,ng_pe, linewidth = 3.0, color=set2[1])
ppl.fill_between(pe_x,0,hg_pe,where=pe_x>-0.052, color=set2[0])
ppl.fill_between(pe_x,0,ng_pe,where=pe_x>0.096, color=set2[1])
ppl.plot(pe_x,hg_pe, linewidth = 3.0, color=set2[0])


Out[117]:
[<matplotlib.lines.Line2D at 0x7f14c06c08d0>]

In [68]:
pi_x = np.linspace(-1.5,1.5,100)
hg_pi = mlab.normpdf(pi_x,hg_ave_2,hg_std_2)
ng_pi = mlab.normpdf(pi_x,ng_ave_2,ng_std_2)

In [98]:
ppl.plot(pi_x,hg_pi, linewidth = 3.0)
ppl.plot(pi_x,ng_pi, linewidth = 3.0)
ppl.fill_between(pi_x,0,ng_pi,where=pi_x>-0.0112, color=set2[1])
ppl.fill_between(pi_x,0,hg_pi,where=pi_x>-0.146, color=set2[0])


Out[98]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f14c12bd890>

In [ ]: