Skip to content

Commit

Permalink
Include Section 5 code in paper_examples.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaMorin committed Sep 25, 2023
1 parent ccb0dfc commit e8ee59c
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions scripts/paper_examples.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit e8ee59c

Please sign in to comment.