Skip to content

Commit 0cf6e8c

Browse files
committed
Replaced MutableData with Data throughout
1 parent 7dd8a3f commit 0cf6e8c

22 files changed

+112
-112
lines changed

examples/statistical_rethinking_lectures/03-Geocentric_Models.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@
11401140
" with pm.Model() as model:\n",
11411141
"\n",
11421142
" # Mutable data for posterior predictive visualization\n",
1143-
" H_ = pm.MutableData(\"H\", H[:sample_size], dims=\"obs_id\")\n",
1143+
" H_ = pm.Data(\"H\", H[:sample_size], dims=\"obs_id\")\n",
11441144
"\n",
11451145
" # Priors\n",
11461146
" alpha = pm.Normal(\"alpha\", 0, 10) # Intercept\n",
@@ -1355,7 +1355,7 @@
13551355
"with pm.Model() as howell_model:\n",
13561356
"\n",
13571357
" # Mutable data for posterior predictive / visualization\n",
1358-
" H_ = pm.MutableData(\"H\", ADULT_HOWELL.height.values, dims=\"obs_ids\")\n",
1358+
" H_ = pm.Data(\"H\", ADULT_HOWELL.height.values, dims=\"obs_ids\")\n",
13591359
"\n",
13601360
" # priors\n",
13611361
" alpha = pm.Normal(\"alpha\", 0, 10) # Intercept\n",

examples/statistical_rethinking_lectures/03-Geocentric_Models.myst.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ for sample_size in sample_sizes:
416416
with pm.Model() as model:
417417
418418
# Mutable data for posterior predictive visualization
419-
H_ = pm.MutableData("H", H[:sample_size], dims="obs_id")
419+
H_ = pm.Data("H", H[:sample_size], dims="obs_id")
420420
421421
# Priors
422422
alpha = pm.Normal("alpha", 0, 10) # Intercept
@@ -507,7 +507,7 @@ for ii, (sample_size, model, inference) in enumerate(
507507
with pm.Model() as howell_model:
508508
509509
# Mutable data for posterior predictive / visualization
510-
H_ = pm.MutableData("H", ADULT_HOWELL.height.values, dims="obs_ids")
510+
H_ = pm.Data("H", ADULT_HOWELL.height.values, dims="obs_ids")
511511
512512
# priors
513513
alpha = pm.Normal("alpha", 0, 10) # Intercept

examples/statistical_rethinking_lectures/04-Categories_&_Curves.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@
12191219
"\n",
12201220
" with pm.Model(coords={\"SEX\": SEX}) as model:\n",
12211221
" # Data\n",
1222-
" S = pm.MutableData(\"S\", SEX_ID)\n",
1222+
" S = pm.Data(\"S\", SEX_ID)\n",
12231223
"\n",
12241224
" # Priors\n",
12251225
" sigma = pm.Uniform(\"sigma\", 0, 10)\n",
@@ -1943,9 +1943,9 @@
19431943
"\n",
19441944
" with pm.Model(coords={\"SEX\": SEX}) as model:\n",
19451945
" # Data\n",
1946-
" S = pm.MutableData(\"S\", SEX_ID, dims=\"obs_ids\")\n",
1947-
" H = pm.MutableData(\"H\", data[\"height\"].values, dims=\"obs_ids\")\n",
1948-
" Hbar = pm.MutableData(\"Hbar\", data[\"height\"].mean())\n",
1946+
" S = pm.Data(\"S\", SEX_ID, dims=\"obs_ids\")\n",
1947+
" H = pm.Data(\"H\", data[\"height\"].values, dims=\"obs_ids\")\n",
1948+
" Hbar = pm.Data(\"Hbar\", data[\"height\"].mean())\n",
19491949
"\n",
19501950
" # Priors\n",
19511951
" sigma = pm.Uniform(\"sigma\", 0, 10)\n",
@@ -2918,7 +2918,7 @@
29182918
"def fit_nth_order_polynomial(data, n=3):\n",
29192919
" with pm.Model() as model:\n",
29202920
" # Data\n",
2921-
" H_std = pm.MutableData(\"H\", utils.standardize(data.height.values), dims=\"obs_ids\")\n",
2921+
" H_std = pm.Data(\"H\", utils.standardize(data.height.values), dims=\"obs_ids\")\n",
29222922
"\n",
29232923
" # Priors\n",
29242924
" sigma = pm.Uniform(\"sigma\", 0, 10)\n",
@@ -4453,9 +4453,9 @@
44534453
"with pm.Model(coords={\"SEX\": SEX}) as flb_model:\n",
44544454
"\n",
44554455
" # Data\n",
4456-
" S = pm.MutableData(\"S\", SEX_ID)\n",
4457-
" H = pm.MutableData(\"H\", ADULT_HOWELL.height.values)\n",
4458-
" Hbar = pm.MutableData(\"Hbar\", ADULT_HOWELL.height.mean())\n",
4456+
" S = pm.Data(\"S\", SEX_ID)\n",
4457+
" H = pm.Data(\"H\", ADULT_HOWELL.height.values)\n",
4458+
" Hbar = pm.Data(\"Hbar\", ADULT_HOWELL.height.mean())\n",
44594459
"\n",
44604460
" # Height Model\n",
44614461
" ## Height priors\n",

examples/statistical_rethinking_lectures/04-Categories_&_Curves.myst.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def fit_total_effect_model(data):
375375
376376
with pm.Model(coords={"SEX": SEX}) as model:
377377
# Data
378-
S = pm.MutableData("S", SEX_ID)
378+
S = pm.Data("S", SEX_ID)
379379
380380
# Priors
381381
sigma = pm.Uniform("sigma", 0, 10)
@@ -633,9 +633,9 @@ def fit_direct_effect_weight_model(data):
633633
634634
with pm.Model(coords={"SEX": SEX}) as model:
635635
# Data
636-
S = pm.MutableData("S", SEX_ID, dims="obs_ids")
637-
H = pm.MutableData("H", data["height"].values, dims="obs_ids")
638-
Hbar = pm.MutableData("Hbar", data["height"].mean())
636+
S = pm.Data("S", SEX_ID, dims="obs_ids")
637+
H = pm.Data("H", data["height"].values, dims="obs_ids")
638+
Hbar = pm.Data("Hbar", data["height"].mean())
639639
640640
# Priors
641641
sigma = pm.Uniform("sigma", 0, 10)
@@ -848,7 +848,7 @@ for n_samples in [0, 2, 4, 8, 16, 32, 64]:
848848
def fit_nth_order_polynomial(data, n=3):
849849
with pm.Model() as model:
850850
# Data
851-
H_std = pm.MutableData("H", utils.standardize(data.height.values), dims="obs_ids")
851+
H_std = pm.Data("H", utils.standardize(data.height.values), dims="obs_ids")
852852
853853
# Priors
854854
sigma = pm.Uniform("sigma", 0, 10)
@@ -1115,9 +1115,9 @@ SEX_ID, SEX = pd.factorize(["M" if s else "F" for s in ADULT_HOWELL["male"].valu
11151115
with pm.Model(coords={"SEX": SEX}) as flb_model:
11161116
11171117
# Data
1118-
S = pm.MutableData("S", SEX_ID)
1119-
H = pm.MutableData("H", ADULT_HOWELL.height.values)
1120-
Hbar = pm.MutableData("Hbar", ADULT_HOWELL.height.mean())
1118+
S = pm.Data("S", SEX_ID)
1119+
H = pm.Data("H", ADULT_HOWELL.height.values)
1120+
Hbar = pm.Data("Hbar", ADULT_HOWELL.height.mean())
11211121
11221122
# Height Model
11231123
## Height priors

examples/statistical_rethinking_lectures/05-Elemental_Confounds.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@
14161416
" with pm.Model() as divorce_model:\n",
14171417
"\n",
14181418
" # Observed Data\n",
1419-
" age = pm.MutableData(\"age\", data[\"MedianAgeMarriage\"].values, dims=\"obs_ids\")\n",
1420-
" marriage_rate = pm.MutableData(\"marriage_rate\", data[\"Marriage\"].values, dims=\"obs_ids\")\n",
1419+
" age = pm.Data(\"age\", data[\"MedianAgeMarriage\"].values, dims=\"obs_ids\")\n",
1420+
" marriage_rate = pm.Data(\"marriage_rate\", data[\"Marriage\"].values, dims=\"obs_ids\")\n",
14211421
" divorce_rate = data[\"Divorce\"].values\n",
14221422
"\n",
14231423
" sigma = pm.Exponential(\"sigma\", 1)\n",
@@ -2539,7 +2539,7 @@
25392539
" with pm.Model() as divorce_model:\n",
25402540
"\n",
25412541
" # Observed Data\n",
2542-
" age = pm.MutableData(\"age\", data[\"MedianAgeMarriage\"].values, dims=\"obs_ids\")\n",
2542+
" age = pm.Data(\"age\", data[\"MedianAgeMarriage\"].values, dims=\"obs_ids\")\n",
25432543
"\n",
25442544
" alpha = pm.Normal(\"alpha\", 0, 0.2)\n",
25452545
" beta_age = pm.Normal(\"beta_age\", 0, 1)\n",

examples/statistical_rethinking_lectures/05-Elemental_Confounds.myst.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ def fit_marriage_divorce_model(data):
553553
with pm.Model() as divorce_model:
554554
555555
# Observed Data
556-
age = pm.MutableData("age", data["MedianAgeMarriage"].values, dims="obs_ids")
557-
marriage_rate = pm.MutableData("marriage_rate", data["Marriage"].values, dims="obs_ids")
556+
age = pm.Data("age", data["MedianAgeMarriage"].values, dims="obs_ids")
557+
marriage_rate = pm.Data("marriage_rate", data["Marriage"].values, dims="obs_ids")
558558
divorce_rate = data["Divorce"].values
559559
560560
sigma = pm.Exponential("sigma", 1)
@@ -878,7 +878,7 @@ def fit_age_divorce_model(data):
878878
with pm.Model() as divorce_model:
879879
880880
# Observed Data
881-
age = pm.MutableData("age", data["MedianAgeMarriage"].values, dims="obs_ids")
881+
age = pm.Data("age", data["MedianAgeMarriage"].values, dims="obs_ids")
882882
883883
alpha = pm.Normal("alpha", 0, 0.2)
884884
beta_age = pm.Normal("beta_age", 0, 1)

examples/statistical_rethinking_lectures/07-Fitting_Over_&_Under.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,8 @@
956956
" H0 = plants.H0.values\n",
957957
" H1 = plants.H1.values\n",
958958
"\n",
959-
" T = pm.MutableData(\"T\", treatment.astype(float))\n",
960-
" F = pm.MutableData(\"F\", fungus.astype(float))\n",
959+
" T = pm.Data(\"T\", treatment.astype(float))\n",
960+
" F = pm.Data(\"F\", fungus.astype(float))\n",
961961
"\n",
962962
" # proportional amount of growth\n",
963963
" g = alpha + beta_T * T + beta_F * F\n",
@@ -1173,8 +1173,8 @@
11731173
" H0 = plants.H0.values\n",
11741174
" H1 = plants.H1.values\n",
11751175
"\n",
1176-
" T = pm.MutableData(\"T\", treatment.astype(float))\n",
1177-
" F = pm.MutableData(\"F\", fungus.astype(float))\n",
1176+
" T = pm.Data(\"T\", treatment.astype(float))\n",
1177+
" F = pm.Data(\"F\", fungus.astype(float))\n",
11781178
"\n",
11791179
" # proportional amount of growth\n",
11801180
" g = alpha + beta_T * T\n",

examples/statistical_rethinking_lectures/07-Fitting_Over_&_Under.myst.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ with pm.Model() as biased_model:
400400
H0 = plants.H0.values
401401
H1 = plants.H1.values
402402
403-
T = pm.MutableData("T", treatment.astype(float))
404-
F = pm.MutableData("F", fungus.astype(float))
403+
T = pm.Data("T", treatment.astype(float))
404+
F = pm.Data("F", fungus.astype(float))
405405
406406
# proportional amount of growth
407407
g = alpha + beta_T * T + beta_F * F
@@ -439,8 +439,8 @@ with pm.Model() as unbiased_model:
439439
H0 = plants.H0.values
440440
H1 = plants.H1.values
441441
442-
T = pm.MutableData("T", treatment.astype(float))
443-
F = pm.MutableData("F", fungus.astype(float))
442+
T = pm.Data("T", treatment.astype(float))
443+
F = pm.Data("F", fungus.astype(float))
444444
445445
# proportional amount of growth
446446
g = alpha + beta_T * T

examples/statistical_rethinking_lectures/09-Modeling_Events.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@
17091709
" with pm.Model(coords={\"gender\": gender}) as total_effect_model:\n",
17101710
"\n",
17111711
" # Mutable data for running any gender-based counterfactuals\n",
1712-
" gender_coded = pm.MutableData(\"gender\", gender_coded, dims=\"obs_ids\")\n",
1712+
" gender_coded = pm.Data(\"gender\", gender_coded, dims=\"obs_ids\")\n",
17131713
"\n",
17141714
" alpha = pm.Normal(\"alpha\", 0, 1, dims=\"gender\")\n",
17151715
"\n",
@@ -2373,9 +2373,9 @@
23732373
" with pm.Model(coords={\"gender\": gender, \"department\": department}) as direct_effect_model:\n",
23742374
"\n",
23752375
" # Mutable data for running any gender-based or department-based counterfactuals\n",
2376-
" gender_coded = pm.MutableData(\"gender\", gender_coded, dims=\"obs_ids\")\n",
2377-
" department_coded = pm.MutableData(\"department\", department_coded, dims=\"obs_ids\")\n",
2378-
" n_applications = pm.MutableData(\"n_applications\", n_applications, dims=\"obs_ids\")\n",
2376+
" gender_coded = pm.Data(\"gender\", gender_coded, dims=\"obs_ids\")\n",
2377+
" department_coded = pm.Data(\"department\", department_coded, dims=\"obs_ids\")\n",
2378+
" n_applications = pm.Data(\"n_applications\", n_applications, dims=\"obs_ids\")\n",
23792379
"\n",
23802380
" alpha = pm.Normal(\"alpha\", 0, 1, dims=[\"department\", \"gender\"])\n",
23812381
"\n",

examples/statistical_rethinking_lectures/09-Modeling_Events.myst.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def fit_total_effect_model_admissions(data):
664664
with pm.Model(coords={"gender": gender}) as total_effect_model:
665665
666666
# Mutable data for running any gender-based counterfactuals
667-
gender_coded = pm.MutableData("gender", gender_coded, dims="obs_ids")
667+
gender_coded = pm.Data("gender", gender_coded, dims="obs_ids")
668668
669669
alpha = pm.Normal("alpha", 0, 1, dims="gender")
670670
@@ -782,9 +782,9 @@ def fit_direct_effect_model_admissions(data):
782782
with pm.Model(coords={"gender": gender, "department": department}) as direct_effect_model:
783783
784784
# Mutable data for running any gender-based or department-based counterfactuals
785-
gender_coded = pm.MutableData("gender", gender_coded, dims="obs_ids")
786-
department_coded = pm.MutableData("department", department_coded, dims="obs_ids")
787-
n_applications = pm.MutableData("n_applications", n_applications, dims="obs_ids")
785+
gender_coded = pm.Data("gender", gender_coded, dims="obs_ids")
786+
department_coded = pm.Data("department", department_coded, dims="obs_ids")
787+
n_applications = pm.Data("n_applications", n_applications, dims="obs_ids")
788788
789789
alpha = pm.Normal("alpha", 0, 1, dims=["department", "gender"])
790790

examples/statistical_rethinking_lectures/10-Counts_&_Hidden_Confounds.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,8 +3117,8 @@
31173117
"with pm.Model(coords={\"contact\": CONTACT}) as interaction_model:\n",
31183118
"\n",
31193119
" # Set up mutable data for predictions\n",
3120-
" std_log_population = pm.MutableData(\"population\", STD_LOG_POPULATION, dims=\"obs_id\")\n",
3121-
" contact_level = pm.MutableData(\"contact_level\", CONTACT_LEVEL, dims=\"obs_id\")\n",
3120+
" std_log_population = pm.Data(\"population\", STD_LOG_POPULATION, dims=\"obs_id\")\n",
3121+
" contact_level = pm.Data(\"contact_level\", CONTACT_LEVEL, dims=\"obs_id\")\n",
31223122
"\n",
31233123
" # Priors\n",
31243124
" alpha = pm.Normal(\"alpha\", 3, 0.5, dims=\"contact\") # intercept\n",
@@ -3967,8 +3967,8 @@
39673967
"with pm.Model(coords={\"contact\": CONTACT}) as innovation_loss_model:\n",
39683968
"\n",
39693969
" # Note: raw population here, not log/standardized\n",
3970-
" population = pm.MutableData(\"population\", POPULATION, dims=\"obs_id\")\n",
3971-
" contact_level = pm.MutableData(\"contact_level\", CONTACT_LEVEL, dims=\"obs_id\")\n",
3970+
" population = pm.Data(\"population\", POPULATION, dims=\"obs_id\")\n",
3971+
" contact_level = pm.Data(\"contact_level\", CONTACT_LEVEL, dims=\"obs_id\")\n",
39723972
"\n",
39733973
" # Priors -- we use Exponential for all.\n",
39743974
" # Note that in the lecture: McElreath uses a Normal for alpha\n",
@@ -4792,8 +4792,8 @@
47924792
"# Unstratified model\n",
47934793
"with pm.Model() as unstratified_model:\n",
47944794
"\n",
4795-
" # MutableData for PPDs\n",
4796-
" x = pm.MutableData(\"X\", X)\n",
4795+
" # Data for PPDs\n",
4796+
" x = pm.Data(\"X\", X)\n",
47974797
"\n",
47984798
" # Global params\n",
47994799
" alpha = pm.Normal(\"alpha\", 0, 1)\n",
@@ -4980,8 +4980,8 @@
49804980
"with pm.Model() as partially_stratified_model:\n",
49814981
"\n",
49824982
" # Mutable data for PPDs\n",
4983-
" x = pm.MutableData(\"X\", X)\n",
4984-
" z = pm.MutableData(\"Z\", Z)\n",
4983+
" x = pm.Data(\"X\", X)\n",
4984+
" z = pm.Data(\"Z\", Z)\n",
49854985
"\n",
49864986
" alpha = pm.Normal(\"alpha\", 0, 1)\n",
49874987
" beta = pm.Normal(\"beta\", 0, 1, shape=2)\n",
@@ -5415,8 +5415,8 @@
54155415
"# Fully statified Model\n",
54165416
"with pm.Model() as fully_stratified_model:\n",
54175417
"\n",
5418-
" x = pm.MutableData(\"X\", X)\n",
5419-
" z = pm.MutableData(\"Z\", Z)\n",
5418+
" x = pm.Data(\"X\", X)\n",
5419+
" z = pm.Data(\"Z\", Z)\n",
54205420
"\n",
54215421
" # Stratify intercept by Z as well\n",
54225422
" alpha = pm.Normal(\"alpha\", 0, 1, shape=2)\n",

examples/statistical_rethinking_lectures/10-Counts_&_Hidden_Confounds.myst.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ OBS_ID = np.arange(N_CULTURES).astype(int)
716716
with pm.Model(coords={"contact": CONTACT}) as interaction_model:
717717
718718
# Set up mutable data for predictions
719-
std_log_population = pm.MutableData("population", STD_LOG_POPULATION, dims="obs_id")
720-
contact_level = pm.MutableData("contact_level", CONTACT_LEVEL, dims="obs_id")
719+
std_log_population = pm.Data("population", STD_LOG_POPULATION, dims="obs_id")
720+
contact_level = pm.Data("contact_level", CONTACT_LEVEL, dims="obs_id")
721721
722722
# Priors
723723
alpha = pm.Normal("alpha", 3, 0.5, dims="contact") # intercept
@@ -981,8 +981,8 @@ ETA = 4
981981
with pm.Model(coords={"contact": CONTACT}) as innovation_loss_model:
982982
983983
# Note: raw population here, not log/standardized
984-
population = pm.MutableData("population", POPULATION, dims="obs_id")
985-
contact_level = pm.MutableData("contact_level", CONTACT_LEVEL, dims="obs_id")
984+
population = pm.Data("population", POPULATION, dims="obs_id")
985+
contact_level = pm.Data("contact_level", CONTACT_LEVEL, dims="obs_id")
986986
987987
# Priors -- we use Exponential for all.
988988
# Note that in the lecture: McElreath uses a Normal for alpha
@@ -1150,8 +1150,8 @@ plt.title("Probabilities");
11501150
# Unstratified model
11511151
with pm.Model() as unstratified_model:
11521152
1153-
# MutableData for PPDs
1154-
x = pm.MutableData("X", X)
1153+
# Data for PPDs
1154+
x = pm.Data("X", X)
11551155
11561156
# Global params
11571157
alpha = pm.Normal("alpha", 0, 1)
@@ -1173,8 +1173,8 @@ pm.model_to_graphviz(unstratified_model)
11731173
with pm.Model() as partially_stratified_model:
11741174
11751175
# Mutable data for PPDs
1176-
x = pm.MutableData("X", X)
1177-
z = pm.MutableData("Z", Z)
1176+
x = pm.Data("X", X)
1177+
z = pm.Data("Z", Z)
11781178
11791179
alpha = pm.Normal("alpha", 0, 1)
11801180
beta = pm.Normal("beta", 0, 1, shape=2)
@@ -1278,8 +1278,8 @@ Include a separate intercept for each group
12781278
# Fully statified Model
12791279
with pm.Model() as fully_stratified_model:
12801280
1281-
x = pm.MutableData("X", X)
1282-
z = pm.MutableData("Z", Z)
1281+
x = pm.Data("X", X)
1282+
z = pm.Data("Z", Z)
12831283
12841284
# Stratify intercept by Z as well
12851285
alpha = pm.Normal("alpha", 0, 1, shape=2)

0 commit comments

Comments
 (0)