/
Chi_DD.py
104 lines (46 loc) · 1.14 KB
/
Chi_DD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
# In[2]:
#create data
df = pd.DataFrame({'cases': [898, 1055, 613, 254, 467, 1054, 1663, 2909],
'hospitalizations': [90, 82, 56, 27, 56, 92, 161, 206],
'deaths': [4, 1, 2, 2, 2, 2, 7, 8]})
# In[3]:
#view data
df
# In[4]:
import statsmodels.api as sm
# In[5]:
#define response variable
y = df['deaths']
# In[7]:
#define predictor variables
x = df[['cases', 'hospitalizations']]
# In[8]:
#add constant to predictor variables
x = sm.add_constant(x)
# In[9]:
#fit linear regression model
model = sm.OLS(y, x).fit()
# In[10]:
#view model summary
print(model.summary())
# In[12]:
#import necessary libraries
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.formula.api import ols
# In[13]:
#fit simple linear regression model
model = ols('cases ~ deaths', data=df).fit()
# In[14]:
#view model summary
print(model.summary())
# In[16]:
#define figure size
fig = plt.figure(figsize=(12,8))
#produce regression plots
fig = sm.graphics.plot_regress_exog(model, 'deaths', fig=fig)
# In[ ]: