-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
42 lines (32 loc) · 1.42 KB
/
Copy pathbasic_usage.py
File metadata and controls
42 lines (32 loc) · 1.42 KB
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
"""
Basic usage example for the imputemulti package.
Demonstrates EM and DA imputation on the tract2221 dataset.
"""
from imputemulti import load_tract2221, multinomial_impute
def main():
# 1. Load the dataset
print("Loading tract2221 dataset...")
df_full = load_tract2221()
# (Full state space is very large)
# Following the R manual, we will use a subset of columns for this example.
cols = ['age', 'gender', 'marital_status', 'edu_attain', 'emp_status']
df = df_full[cols].copy()
print(f"Using subset of columns: {cols}")
print(f"Dataset shape: {df.shape}")
print(f"Missing values per column:\n{df.isna().sum()}")
# 2. EM Imputation
print("\nRunning EM imputation...")
em_res = multinomial_impute(df, method="EM", conj_prior="none")
print(f"EM converged in {em_res.mle_iter} iterations.")
print(f"EM Log-Likelihood: {em_res.mle_log_lik:.4f}")
imputed_em = em_res.data[1]
print(f"Missing values after EM: {imputed_em.isna().sum().sum()}")
# 3. DA Imputation
print("\nRunning DA imputation...")
da_res = multinomial_impute(df, method="DA", conj_prior="none", burnin=100, post_draws=500)
print(f"DA Log-Likelihood: {da_res.mle_log_lik:.4f}")
imputed_da = da_res.data[1]
print(f"Missing values after DA: {imputed_da.isna().sum().sum()}")
print("\nBasic usage example completed successfully.")
if __name__ == "__main__":
main()