print("Hello world! - python.jsrun.net .")
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
data = {
'Education': ['文盲', '小学', '初中', '高中中专', '大专大学'],
'Deaths': [43086, 21917, 10741, 4038, 1991],
'Population': [1461971, 1870095, 3113930, 2091845, 687195]
}
df = pd.DataFrame(data)
df['Survivals'] = df['Population'] - df['Deaths']
expanded_rows = []
for _, row in df.iterrows():
expanded_rows.append({
'Education': row['Education'],
'Died': 1,
'Count': row['Deaths']
})
expanded_rows.append({
'Education': row['Education'],
'Died': 0,
'Count': row['Survivals']
})
logit_df = pd.DataFrame(expanded_rows)
model = smf.glm(
formula='Died ~ C(Education)',
data=logit_df,
family=sm.families.Binomial(),
freq_weights=logit_df['Count']
).fit()
model_summary = model.summary2().as_text()
model_params = model.params
model_summary, model_params