In [1]:
%pylab inline
import pandas as pd
In [23]:
ungrouped_data = pd.read_csv("../data/Beetles.dat", sep="\t")
ungrouped_data
Out[23]:
In [34]:
grouped_data = pd.read_csv("../data/Beetles2.dat", sep= "\t")
grouped_data['alive'] = grouped_data['n'] - grouped_data['dead']
grouped_data
Out[34]:
In [25]:
import statsmodels.api as sm
#spector_data.exog = sm.add_constant(spector_data.exog)
logit_mod = sm.Logit(ungrouped_data['y'], sm.add_constant(ungrouped_data['x']))
logit_res = logit_mod.fit()
In [26]:
print(logit_res.summary())
In [27]:
glm_model = sm.GLM(grouped_data['dead']/grouped_data['n'], sm.add_constant(grouped_data['logdose']), family=sm.families.Binomial(link=sm.families.links.logit),
weights = grouped_data['n'])
glm_fit = glm_model.fit()
print(glm_fit.summary())
The above is an abuse of statsmodels. I don't even know why it works.
In [35]:
glm_model = sm.GLM(grouped_data[['dead', 'alive']] , sm.add_constant(grouped_data['logdose']), family=sm.families.Binomial(link=sm.families.links.logit),
)
glm_fit = glm_model.fit()
print(glm_fit.summary())
In [16]:
glm_model = sm.GLM(grouped_data['y'], sm.add_constant(grouped_data['x']), family=sm.families.Binomial(link=sm.families.links.logit))
glm_fit = glm_model.fit()
print(glm_fit.summary())
In [ ]: