@@ -127,92 +127,98 @@ def R2D2M2CP(
127
127
--------
128
128
Here are arguments explained in a synthetic example
129
129
130
- >>> import pymc_experimental as pmx
131
- >>> import pymc as pm
132
- >>> import numpy as np
133
- >>> X = np.random.randn(10, 3)
134
- >>> b = np.random.randn(3)
135
- >>> y = X @ b + np.random.randn(10) * 0.04 + 5
136
- >>> with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
137
- ... eps, beta = pmx.distributions.R2D2M2CP(
138
- ... "beta",
139
- ... y.std(),
140
- ... X.std(0),
141
- ... dims="variables",
142
- ... # NOTE: global shrinkage
143
- ... r2=0.8,
144
- ... # NOTE: if you are unsure about r2
145
- ... r2_std=0.2,
146
- ... # NOTE: if you know where a variable should go
147
- ... # if you do not know, leave as 0.5
148
- ... positive_probs=[0.8, 0.5, 0.1],
149
- ... # NOTE: if you have different opinions about
150
- ... # where a variable should go.
151
- ... # NOTE: if you put 0.5 previously,
152
- ... # just put 0.1 there, but other
153
- ... # sigmas should work fine too
154
- ... positive_probs_std=[0.3, 0.1, 0.2],
155
- ... # NOTE: variable importances are relative to each other,
156
- ... # but larget numbers put "more" weight in the relation
157
- ... # use
158
- ... # * 1-10 for small confidence
159
- ... # * 10-30 for moderate confidence
160
- ... # * 30+ for high confidence
161
- ... # EXAMPLE:
162
- ... # "a" - is likely to be useful
163
- ... # "b" - no idea if it is useful
164
- ... # "c" - a must have in the relation
165
- ... variables_importance=[10, 1, 34],
166
- ... # NOTE: try both
167
- ... centered=True
168
- ... )
169
- ... intercept = y.mean()
170
- ... obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
130
+ .. code-block:: python
131
+
132
+ import pymc_experimental as pmx
133
+ import pymc as pm
134
+ import numpy as np
135
+ X = np.random.randn(10, 3)
136
+ b = np.random.randn(3)
137
+ y = X @ b + np.random.randn(10) * 0.04 + 5
138
+ with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
139
+ eps, beta = pmx.distributions.R2D2M2CP(
140
+ "beta",
141
+ y.std(),
142
+ X.std(0),
143
+ dims="variables",
144
+ # NOTE: global shrinkage
145
+ r2=0.8,
146
+ # NOTE: if you are unsure about r2
147
+ r2_std=0.2,
148
+ # NOTE: if you know where a variable should go
149
+ # if you do not know, leave as 0.5
150
+ positive_probs=[0.8, 0.5, 0.1],
151
+ # NOTE: if you have different opinions about
152
+ # where a variable should go.
153
+ # NOTE: if you put 0.5 previously,
154
+ # just put 0.1 there, but other
155
+ # sigmas should work fine too
156
+ positive_probs_std=[0.3, 0.1, 0.2],
157
+ # NOTE: variable importances are relative to each other,
158
+ # but larget numbers put "more" weight in the relation
159
+ # use
160
+ # * 1-10 for small confidence
161
+ # * 10-30 for moderate confidence
162
+ # * 30+ for high confidence
163
+ # EXAMPLE:
164
+ # "a" - is likely to be useful
165
+ # "b" - no idea if it is useful
166
+ # "c" - a must have in the relation
167
+ variables_importance=[10, 1, 34],
168
+ # NOTE: try both
169
+ centered=True
170
+ )
171
+ intercept = y.mean()
172
+ obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
171
173
172
174
There can be special cases by choosing specific set of arguments
173
175
174
176
Here the prior distribution of beta is ``Normal(0, y.std() * r2 ** .5)``
175
177
176
- >>> with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
177
- ... eps, beta = pmx.distributions.R2D2M2CP(
178
- ... "beta",
179
- ... y.std(),
180
- ... X.std(0),
181
- ... dims="variables",
182
- ... # NOTE: global shrinkage
183
- ... r2=0.8,
184
- ... # NOTE: if you are unsure about r2
185
- ... r2_std=0.2,
186
- ... # NOTE: if you know where a variable should go
187
- ... # if you do not know, leave as 0.5
188
- ... centered=False
189
- ... )
190
- ... intercept = y.mean()
191
- ... obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
178
+ .. code-block:: python
179
+
180
+ with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
181
+ eps, beta = pmx.distributions.R2D2M2CP(
182
+ "beta",
183
+ y.std(),
184
+ X.std(0),
185
+ dims="variables",
186
+ # NOTE: global shrinkage
187
+ r2=0.8,
188
+ # NOTE: if you are unsure about r2
189
+ r2_std=0.2,
190
+ # NOTE: if you know where a variable should go
191
+ # if you do not know, leave as 0.5
192
+ centered=False
193
+ )
194
+ intercept = y.mean()
195
+ obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
192
196
193
197
194
198
It is fine to leave some of the ``_std`` arguments unspecified.
195
199
You can also specify only ``positive_probs``, and all
196
200
the variables are assumed to explain same amount of variance (same importance)
197
201
198
- >>> with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
199
- ... eps, beta = pmx.distributions.R2D2M2CP(
200
- ... "beta",
201
- ... y.std(),
202
- ... X.std(0),
203
- ... dims="variables",
204
- ... # NOTE: global shrinkage
205
- ... r2=0.8,
206
- ... # NOTE: if you are unsure about r2
207
- ... r2_std=0.2,
208
- ... # NOTE: if you know where a variable should go
209
- ... # if you do not know, leave as 0.5
210
- ... positive_probs=[0.8, 0.5, 0.1],
211
- ... # NOTE: try both
212
- ... centered=True
213
- ... )
214
- ... intercept = y.mean()
215
- ... obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
202
+ .. code-block:: python
203
+
204
+ with pm.Model(coords=dict(variables=["a", "b", "c"])) as model:
205
+ eps, beta = pmx.distributions.R2D2M2CP(
206
+ "beta",
207
+ y.std(),
208
+ X.std(0),
209
+ dims="variables",
210
+ # NOTE: global shrinkage
211
+ r2=0.8,
212
+ # NOTE: if you are unsure about r2
213
+ r2_std=0.2,
214
+ # NOTE: if you know where a variable should go
215
+ # if you do not know, leave as 0.5
216
+ positive_probs=[0.8, 0.5, 0.1],
217
+ # NOTE: try both
218
+ centered=True
219
+ )
220
+ intercept = y.mean()
221
+ obs = pm.Normal("obs", intercept + X @ beta, eps, observed=y)
216
222
"""
217
223
if not isinstance (dims , (list , tuple )):
218
224
dims = (dims ,)
0 commit comments