From e8ee59c1dcc1438a2d1d4e7b9b199b89be714d13 Mon Sep 17 00:00:00 2001 From: sachaMorin Date: Mon, 25 Sep 2023 16:30:50 -0400 Subject: [PATCH] Include Section 5 code in paper_examples.py --- scripts/paper_examples.py | 64 +++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/scripts/paper_examples.py b/scripts/paper_examples.py index 0ca39a9..7104d38 100644 --- a/scripts/paper_examples.py +++ b/scripts/paper_examples.py @@ -1,7 +1,59 @@ -"""All examples from Section 6 of the paper.""" +"""All examples from Sections 5 and 6 of the paper.""" +# SECTION 5.2: ESTIMATORS +# Section 5 only illustrates the API +# Importing packages. Not in the paper +from stepmix.datasets import data_bakk_response +from stepmix.stepmix import StepMix + +# Generating dummy data. Not in the paper +Y, Z_o, _ = data_bakk_response( + n_samples=2000, + sep_level=0.9, + random_state=42, +) + +# Simple model with categorical MM only +model = StepMix(n_components=3, measurement="categorical") +model.fit(Y) + +# Model with categorical MM and outcome SM +model = StepMix( + n_components=3, + measurement="categorical", + structural="gaussian_unit", + n_steps=3, + assignment="soft", + correction="BCH", +) +model.fit(Y, Z_o) + +# Methods +model.predict(Y, Z_o) +model.predict_proba(Y, Z_o) +model.score(Y, Z_o) +model.aic(Y, Z_o) +model.bic(Y, Z_o) +model.get_mm_df() +model.get_sm_df() +model.get_cw_df() +model.sample(100) + +# SECTION 5.3: NONPARAMETRIC BOOTSTRAPPING +stats_dict = model.bootstrap_stats( + Y, + Z_o, + n_repetitions=10, + progress_bar=True, +) + +# SECTION 5.4: ADDITIONAL FEATURES +# Manually run 3-step with low-level method calls +model.em(Y) +soft_assignments = model.predict_proba(Y) +model.m_step_structural(soft_assignments, Z_o) -######### SUBSECTION 6.1: SINGLE OUTCOME SIMULATION ######### -print("SUBSECTION 6.1: SINGLE OUTCOME SIMULATION") +# SECTION 6.1: SINGLE OUTCOME SIMULATION +print("\n\n\nSUBSECTION 6.1: SINGLE OUTCOME SIMULATION") print("Printing verbose output and mean parameters of the distal outcome\n") from stepmix.datasets import data_bakk_response @@ -26,7 +78,7 @@ mus = model.get_sm_df() print(mus) -######### SUBSECTION 6.2: SINGLE COVARIATE SIMULATION ######### +# SECTION 6.2: SINGLE COVARIATE SIMULATION print("\n\n\nSUBSECTION 6.2: SINGLE COVARIATE SIMULATION") print("Printing beta parameters of the covariate model\n") @@ -60,7 +112,7 @@ betas = betas.sub(betas[1], axis=0) print(betas) -######### SUBSECTION 6.3: COMPLETE MODEL SIMULATION ######### +# SECTION 6.3: COMPLETE MODEL SIMULATION print("\n\n\nSUBSECTION 6.3: COMPLETE MODEL SIMULATION") print("Printing mean parameters of the distal outcome\n") @@ -99,7 +151,7 @@ mus = model.get_sm_df().loc["response"] print(mus) -######### SUBSECTION 6.4: APPLICATION EXAMPLE ######### +# SECTION 6.4: APPLICATION EXAMPLE print("\n\n\nSUBSECTION 6.4: APPLICATION EXAMPLE") print("Printing verbose output\n")