协变量筛选#
mas.model.scm#
- class mas.model.scm#
spec()#
- spec(direction='both', p_forward=0.05, p_backward=0.01, global_init=0.001, maxiter=None, accept_rule=None) MarkedScmSpecDefFunctionType #
标记一个函数作为 scm 配置函数
参数:
direction (
"forward"
|"backward"
|"both"
, optional): 搜索方向。默认值为"both"
。p_forward (
float
, optional): 前向搜索过程中假设检验的显著性水平。即若 p 值小于此值,则纳入此协变量关系。默认值为0.05
。p_backward (
float
, optional): 逆向搜索过程中假设检验的显著性水平。即若 p 值大于此值,则剔除此协变量关系。默认值为0.01
。global_init (
float
, optional): 所有因纳入协变量关系而新增的固定效应参数(theta)初值。默认值为1e-3
。maxiter (
int
, optional): 最大搜索次数。默认值为None
。accept_rule (
AcceptRuleCallable
, optional): 用户自定义的接受规则。例如设置自定义接受规则为:仅当纳入协变量后清除率的个体间变异参数方差估计值
omega["eta_cl", "eta_cl"]
减小 30% 或以上时才接受新的协变量模型。def custom_rule(context: AcceptRuleContext) -> bool: if context.direction == "forward": if context.test_params.omega["eta_cl", "eta_cl"] / context.base_params.omega["eta_cl", "eta_cl"] < 0.7: return True return False
示例:
@scm.spec(direction="forward", maxiter=20)
def my_scm_spec(m: Warfarin):
...
test()#
- test(covariates, on, states, init=None, bounds=None, init_state=None) None #
指定需要被测试的协变量-参数关系。
参数:
covariates (
AnyCategoricalColVar | list[AnyCategoricalColVar] | StrCategoricalColVarCollection | NumericCategoricalColVarCollection | AnyContinuousColVar | list[AnyContinuousColVar] | NumericContinuousColVarCollection | str | list[str]
):需要被测试的协变量。一般接受自 column() 或 multicolumn() 定义的变量。on (
Theta | list[Theta] | str | list[str]
):需要被引入协变量的固定效应参数。states (
AnyCategoricalValidStates | AnyContinuousValidStates
):需要被测试的协变量-参数关系状态。对应的协变量效应参数化形式请参考 协变量效应参数化公式。对于分类型协变量,支持的状态为
"exclude"
、"linear"
与"*"
。对于连续型协变量,支持的状态为
"exclude"
、"linear"
、"piecewise"
、"exp"
、"power"
与"*"
。
init (
ValueType | list[ValueType | PiecewiseValueType | None]
, optional):因纳入协变量关系而新增的协变量效应参数初值。若为None
,将自动计算初值。默认值为None
。bounds (
BoundsType | list[BoundsType | PiecewiseBoundsType | None]
, optional):协变量效应参数估计的上下边界值。若为None
,将自动计算边界值。默认值为None
。init_state (
CategoricalValidStateType
, optional):在搜索开始时即被引入至模型的协变量关系及其状态。默认值为None
。
协变量效应参数化公式#
总则
以乘法的形式结合各协变量效应与原模型固定效应参数,公式如下:
假设原模型中共有 k 个固定效应参数与 i 个个体。其中,\(p_{ki}\) 为第 i 个个体的第 k 个固定效应参数的估计值;\(\theta_{k}\) 为此固定效应参数的群体典型值;\(\eta_{ki}\) 为此固定效应参数的个体间变异;\({z}_i\) 为第 i 个个体的协变量值向量;\(g_{k}\) 为有关于 \({z}_i\) 的函数,用于描述协变量与固定效应参数间的关系,具体由纳入协变量的个数 r 以及不同的协变量-参数关系状态(\(c_{ir}\))决定。
各状态的参数化公式
"exclude"
:不引入任何协变量。"linear"
:以线性关系引入协变量,公式如下:
若为连续型协变量:
若为分类协变量(以二分类变量为例):
"piecewise"
:以分段线性关系引入协变量,公式如下:
"exp"
:以指数形式引入协变量,公式如下:
"power"
:以幂的形式引入协变量,公式如下:
上述公式中,\(\theta_{r}\) 为协变量效应参数,表明了协变量值的变动对固定效应参数的影响大小。
参考文献
Jonsson, E. N., & Karlsson, M. O. (1998). Automated covariate model building within NONMEM. Pharmaceutical research, 15(9), 1463–1468.
示例:
例如,假设在模型固定效应参数清除率(self.theta_cl
)上以线性关系引入了协变量体重(self.wt
)与年龄(self.age
),模型将变为如下形式:
class WarfarinPk(EvOneCmtLinear):
"""
theta_cl ~ WT @ linear
theta_cl ~ AGE @ linear
"""
def __init__(self):
super().__init__()
self.theta_cl = theta(0.15, bounds=(0.01, 10.0), fixed=False)
self.theta_v = theta(8.0, bounds=(0.01, 20.0), fixed=False)
self.theta_ka = theta(0.5, bounds=(0.01, 5.0), fixed=False)
self.theta_alag = theta(0.8, bounds=(0.01, 24.0), fixed=False)
self.WT__theta_cl_1 = theta(-0.003125, bounds=(-0.03125, 0.03333), fixed=False)
self.AGE__theta_cl_1 = theta(-0.002985, bounds=(-0.02985, 0.1176), fixed=False)
self.eta_cl = omega(0.05, fixed=False)
self.eta_v = omega(0.08, fixed=False)
self.eta_ka = omega(0.05, fixed=False)
self.eta_alag = omega(0.15, fixed=False)
self.eps_prop = sigma(0.01, fixed=False)
self.eps_add = sigma(0.55, fixed=False)
self.WT = column('WT', dtype='numeric', is_categorical=False)
self.AGE = column('AGE', dtype='numeric', is_categorical=False)
def pred(self):
AGE__theta_cl = 1 + self.AGE__theta_cl_1 * (self.AGE - 29.5)
theta_cl__with_cov = self.theta_cl * AGE__theta_cl
WT__theta_cl = 1 + self.WT__theta_cl_1 * (self.WT - 70.0)
theta_cl__with_cov = theta_cl__with_cov * WT__theta_cl
cl = theta_cl__with_cov * exp(self.eta_cl)
v = self.theta_v * exp(self.eta_v)
ka = self.theta_ka * exp(self.eta_ka)
alag = self.theta_alag * exp(self.eta_alag)
pred_res = self.pred_physio(cl=cl, v=v, ka=ka, alag1=alag, s2=v)
ipred = pred_res.F
y = ipred * (1 + self.eps_prop) + self.eps_add
return y
from mas.model import *
from mas.datasets import warfarin_pk
class WarfarinPk(EvOneCmtLinear):
def __init__(self) -> None:
self.theta_cl = theta(0.15, bounds=(0.01, 10))
self.theta_v = theta(8, bounds=(0.01, 20))
self.theta_ka = theta(0.5, bounds=(0.01, 5))
self.theta_alag = theta(0.8, bounds=(0.01, 24))
self.eta_cl = omega(0.05)
self.eta_v = omega(0.08)
self.eta_ka = omega(0.05)
self.eta_alag = omega(0.15)
self.eps_prop = sigma(0.01)
self.eps_add = sigma(0.55)
def pred(self):
cl = self.theta_cl * exp(self.eta_cl) # 指数型个体间变异
v = self.theta_v * exp(self.eta_v)
ka = self.theta_ka * exp(self.eta_ka)
alag = self.theta_alag * exp(self.eta_alag)
pred_res = self.pred_physio(cl=cl, v=v, ka=ka, alag1=alag, s2=v) # 使用生理药动学参数预测
ipred = pred_res.F # 取出血药浓度预测值
y = ipred * (1 + self.eps_prop) + self.eps_add # 比例型与加和型个体内变异
return y
model = PopModel(WarfarinPk, warfarin_pk)
fit_res = model.fit()
🔧 CXX compiler C:\ProgramData\mingw64\bin\g++.EXE
📦 Compiling build target...
🔗 Linking dynamic library...
✅ Compilation Finished
✈️ First Order Conditional Estimation
Using BFGS...
* maxiter = 9999
* xtol = 1e-06
* ftol = 1e-06
* lower_bounds =
* upper_bounds =
* log_level = 0
* print = 1
* print_type = 0
* verbose = 1
* p_small = 0.1
* rel_step_size = 0.001
#0 ofv: 364.3540523
x: 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01 1.0000e-01
Gradients: 101.0869092 7.448347598 -104.527048 30.99690495 -37.06225844 16.55080045 -45.97759626 -13.85882588 32.8152305 114.4144297
Funcalls: 8
#1 ofv: 299.5539461
x: -1.6505e-01 8.0470e-02 3.7407e-01 1.8725e-02 1.9718e-01 5.6603e-02 2.2056e-01 1.3634e-01 1.3957e-02 -2.0000e-01
Gradients: -114.075615 -2.647636428 -72.14488225 10.92768269 -34.00781518 15.79326196 -36.54203627 -12.03106061 38.90196043 85.34205841
Funcalls: 17
#2 ofv: 265.0144085
x: 8.0508e-02 8.6169e-02 5.2938e-01 -4.7986e-03 2.7039e-01 2.2606e-02 2.9922e-01 1.6224e-01 -6.9785e-02 -3.8371e-01
Gradients: 78.37210597 -0.6928517193 -50.12021333 2.10182098 -18.87280515 14.57028216 -33.88907152 -11.71094215 26.26219179 57.21172002
Funcalls: 26
#3 ofv: 237.8232702
x: -4.4996e-02 9.3925e-02 8.7340e-01 -3.3590e-02 4.1236e-01 -6.7988e-02 5.0958e-01 2.3385e-01 -2.5205e-01 -7.8184e-01
Gradients: -3.826486956 1.905187077 -7.466653587 0.2917805314 5.194169916 6.60842656 -32.57337745 -2.361307685 -61.54034687 -11.12924107
Funcalls: 35
#4 ofv: 226.8520803
x: -8.7464e-02 8.5075e-02 1.1354e+00 -5.3358e-02 4.6160e-01 -1.6997e-01 8.6937e-01 2.9401e-01 7.6682e-02 -9.4398e-01
Gradients: -24.14642615 -5.217842577 4.313521252 -4.005676921 10.95704242 -1.461475585 -15.67787208 0.2075106133 44.02165162 9.839742375
Funcalls: 44
#5 ofv: 221.942983
x: -7.4977e-02 1.4710e-01 1.1112e+00 2.6679e-02 2.0417e-01 -2.1551e-01 1.4630e+00 3.1768e-01 3.0043e-03 -9.5099e-01
Gradients: -30.25032098 24.85634258 -2.024998879 -0.99371552 -21.57279826 -8.145394937 2.301319134 1.443848747 16.1747936 6.124771214
Funcalls: 53
#6 ofv: 221.0960183
x: -7.2891e-02 8.3836e-02 1.0966e+00 4.6522e-02 2.1288e-01 -1.9917e-01 1.5544e+00 3.1610e-01 -1.5021e-02 -9.3995e-01
Gradients: -27.83990018 -4.529436581 -2.559537464 0.126858985 -20.11512122 -4.806058932 4.321817677 1.625650173 11.7040482 5.676701932
Funcalls: 62
#7 ofv: 220.3849934
x: -7.2355e-02 1.0763e-01 1.0591e+00 8.2535e-02 3.2093e-01 -1.5401e-01 1.6748e+00 3.0074e-01 -3.7553e-02 -9.0280e-01
Gradients: -22.46721754 5.433079645 -3.068826953 1.168386588 -5.025697311 -0.3119883882 6.626919793 1.895498718 7.840708364 7.433178434
Funcalls: 71
#8 ofv: 220.311444
x: -7.1093e-02 1.0466e-01 9.9391e-01 1.3292e-01 3.4360e-01 -1.9409e-01 1.6673e+00 1.3333e-01 -1.6102e-02 -9.8698e-01
Gradients: -20.75982993 3.674940328 -5.103562138 3.001265871 -1.605112507 -4.594728915 6.049522188 -0.3691282421 7.25252454 0.6433957114
Funcalls: 80
#9 ofv: 220.0818023
x: -7.0826e-02 1.0673e-01 1.0282e+00 1.2825e-01 3.3255e-01 -1.5467e-01 1.6507e+00 4.5455e-02 -1.5810e-02 -9.8821e-01
Gradients: -21.02685542 4.09997036 -4.109724891 0.7656126979 -3.142475217 -0.4776948134 5.848696138 -2.102507125 7.728632073 0.4892926281
Funcalls: 89
#10 ofv: 219.5604367
x: -6.4508e-02 1.0342e-01 1.1140e+00 1.6954e-01 3.3088e-01 -1.8315e-01 1.6015e+00 -3.5791e-02 -3.5774e-02 -9.2937e-01
Gradients: -17.18882128 3.24855108 -3.16732962 3.086188537 -3.469447015 -3.445086304 4.912860532 -2.742531412 5.719071453 3.506260734
Funcalls: 98
#11 ofv: 218.3357278
x: -4.3254e-02 9.8811e-02 1.1537e+00 1.2984e-01 3.2023e-01 -1.5320e-01 1.4055e+00 1.1531e-01 -4.2353e-02 -9.2249e-01
Gradients: -3.031874246 1.551717717 -1.947360391 2.472724664 -4.526287755 -0.3662460919 0.6879234211 -0.2720726122 4.139760256 3.552658992
Funcalls: 108
#12 ofv: 218.3302056
x: -4.2963e-02 9.7610e-02 1.1528e+00 1.1036e-01 3.2317e-01 -1.6124e-01 1.4020e+00 1.1630e-01 -4.5333e-02 -9.1787e-01
Gradients: -2.710567243 1.287507039 -1.842042667 0.757525545 -4.16596355 -1.210544586 0.7189839845 -0.5752693784 3.464364952 3.749225104
Funcalls: 118
#13 ofv: 218.1737151
x: -4.0106e-02 9.5279e-02 1.1725e+00 9.8696e-02 3.3913e-01 -1.5153e-01 1.3654e+00 1.4177e-01 -4.7600e-02 -9.3140e-01
Gradients: -0.4902703175 0.3499584172 -1.248274333 0.3714240132 -2.137729515 -0.2500963047 -0.402476548 -0.2581159222 1.556192212 2.106209599
Funcalls: 129
#14 ofv: 218.094335
x: -3.9124e-02 9.3641e-02 1.2037e+00 9.1424e-02 3.5662e-01 -1.4586e-01 1.3752e+00 1.6346e-01 -4.8658e-02 -9.4827e-01
Gradients: 0.489332692 -0.2978531032 -0.7147783118 0.1439240397 0.04381634586 0.3283400491 -0.3067598739 0.03209075019 -0.3498870844 0.383681962
Funcalls: 138
#15 ofv: 218.0465777
x: -3.9802e-02 9.3712e-02 1.2673e+00 9.2500e-02 3.6203e-01 -1.4977e-01 1.3922e+00 1.6071e-01 -4.5431e-02 -9.5937e-01
Gradients: 0.3898578372 -0.1893067153 0.1472262577 -0.132802633 0.7412611562 -0.005292759423 -0.3205846167 0.07131200793 -0.1530610007 -0.3225232322
Funcalls: 147
#16 ofv: 218.0402149
x: -4.0068e-02 9.4113e-02 1.2621e+00 9.5160e-02 3.5770e-01 -1.4946e-01 1.4013e+00 1.5612e-01 -4.5825e-02 -9.5688e-01
Gradients: 0.1751094888 -0.04672872979 -0.04608552924 -0.05553771551 0.2142667902 0.0360657554 0.06309788614 0.006985671555 -0.1632259517 -0.1029274517
Funcalls: 156
#17 ofv: 218.0343663
x: -4.0530e-02 9.4373e-02 1.2665e+00 9.8265e-02 3.5379e-01 -1.5026e-01 1.3977e+00 1.5135e-01 -4.5480e-02 -9.5422e-01
Gradients: -0.1473105318 0.06456721724 0.0291372563 0.05668317801 -0.2660676866 -0.03483982993 -0.1063940752 -0.005836340476 0.2435005596 0.1776746278
Funcalls: 165
#18 ofv: 218.0025783
x: -3.9148e-02 9.5296e-02 1.3023e+00 1.1950e-01 3.5338e-01 -1.5000e-01 1.4106e+00 1.2959e-01 -4.6051e-02 -9.5291e-01
Gradients: -0.5929457672 0.01262665073 -0.09482056253 -0.5521284 -0.325407984 0.03378203648 -0.05927945813 0.003662935651 0.1203704746 0.1078263218
Funcalls: 198
#19 ofv: 217.9974735
x: -3.8214e-02 9.5439e-02 1.3199e+00 1.3189e-01 3.5583e-01 -1.5042e-01 1.4182e+00 1.1707e-01 -4.6246e-02 -9.5329e-01
Gradients: -0.01031537538 0.0108785517 -0.0008314488834 0.02676910028 -0.02958518665 0.007431465123 -0.0005238512365 -0.007457125023 0.003303126306 0.002376624231
Funcalls: 213
#20 ofv: 217.9974593
x: -3.8206e-02 9.5404e-02 1.3195e+00 1.3128e-01 3.5607e-01 -1.5048e-01 1.4181e+00 1.1805e-01 -4.6250e-02 -9.5334e-01
Gradients: -0.002445679659 0.0004589659319 -0.0001156027054 6.782998476e-05 -0.0003977363115 0.0007578415519 -0.0001345254365 0.0005515728998 -0.001311506352 -0.0002194009471
Funcalls: 228
converged = True
n_iter = 21
x_opt = -3.8206e-02 9.5404e-02 1.3195e+00 1.3128e-01 3.5607e-01 -1.5048e-01 1.4181e+00 1.1805e-01 -4.6250e-02 -9.5334e-01
f_opt = 217.9974593
fun_calls = 241
Computing Covariance...
Covariance computation succeed
@scm.spec
def warfarin_scm_rules(m: WarfarinPk):
scm.test("WT", on=m.theta_cl, states="*")
scm.test("WT", on=m.theta_v, states="*")
scm_res = fit_res.scm(warfarin_scm_rules)
scm_res
Starting forward search...
Iteration#1, Testing Branch 1 / 2...
theta_cl ~ WT @ linear
theta_v ~ WT @ exclude
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 213.308
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 11
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.133
theta_v 7.977
theta_ka 1.355
theta_alag 0.825
WT__theta_ 0.009
cl_1
Omega(SD)
eta_cl 0.268 0.011
eta_v 0.220 3.975
eta_ka 0.836 50.395
eta_alag 0.394 59.285
Sigma(SD)
eps_prop 0.086 14.934
eps_add 0.260 15.617
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
16 0:00:00.1 0:00:00.84
────────────────────────────────────────────────────────────────────────────────
[Accept] Base OFV: 217.99745934332697, Test OFV: 213.30795749862867, Expected: 214.15600052263284, P Value: 0.03034744437114134 < 0.05 (forward), p-value criteria satisfied
Iteration#1, Testing Branch 2 / 2...
theta_cl ~ WT @ exclude
theta_v ~ WT @ linear
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 191.380
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 11
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.132
theta_v 8.076
theta_ka 1.337
theta_alag 0.823
WT__theta_ 0.013
v_1
Omega(SD)
eta_cl 0.288 0.000
eta_v 0.133 11.532
eta_ka 0.839 50.848
eta_alag 0.394 59.031
Sigma(SD)
eps_prop 0.087 13.911
eps_add 0.257 14.602
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
19 0:00:00.1 0:00:00.91
────────────────────────────────────────────────────────────────────────────────
[Accept] Base OFV: 217.99745934332697, Test OFV: 191.3798614598505, Expected: 214.15600052263284, P Value: 2.4797476594340395e-07 < 0.05 (forward), p-value criteria satisfied
────────────────────────────────────────────────────────────────────────────────
Selected Model Base OFV Test OFV dDF Criteria
────────────────────────────────────────────────────────────────────────────────
theta_cl ~ 217.997 213.308 1 [Accept] 0.0
WT @ linear 303474443711
4134 < 0.05
(forward)
✅ theta_v ~ WT 217.997 191.380 1 [Accept] 2.4
@ linear 797476594340
395e-07 <
0.05
(forward)
────────────────────────────────────────────────────────────────────────────────
Iteration#2, Testing Branch 1 / 2...
theta_cl ~ WT @ linear
theta_v ~ WT @ linear
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 186.560
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 12
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.133
theta_v 8.075
theta_ka 1.338
theta_alag 0.824
WT__theta_ 0.009
cl_1
WT__theta_ 0.013
v_1
Omega(SD)
eta_cl 0.266 0.000
eta_v 0.133 11.589
eta_ka 0.840 50.819
eta_alag 0.394 59.072
Sigma(SD)
eps_prop 0.087 13.877
eps_add 0.257 14.569
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
18 0:00:00.1 0:00:00.81
────────────────────────────────────────────────────────────────────────────────
[Accept] Base OFV: 191.3798614598505, Test OFV: 186.56009477309667, Expected: 187.53840263915637, P Value: 0.02813515336426431 < 0.05 (forward), p-value criteria satisfied
Iteration#2, Testing Branch 2 / 2...
theta_cl ~ WT @ exclude
theta_v ~ WT @ piecewise
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 191.011
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 12
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.132
theta_v 8.248
theta_ka 1.329
theta_alag 0.823
WT__theta_ 0.014
v_1
WT__theta_ 0.010
v_2
Omega(SD)
eta_cl 0.288 0.000
eta_v 0.131 11.811
eta_ka 0.834 50.864
eta_alag 0.394 59.011
Sigma(SD)
eps_prop 0.087 13.873
eps_add 0.257 14.565
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
17 0:00:00.1 0:00:01.5
────────────────────────────────────────────────────────────────────────────────
[Reject] Base OFV: 191.3798614598505, Test OFV: 191.0105998543206, Expected: 187.53840263915637, P Value: 0.5434070317112094 > 0.05 (forward), p-value criteria failed
────────────────────────────────────────────────────────────────────────────────
Selected Model Base OFV Test OFV dDF Criteria
────────────────────────────────────────────────────────────────────────────────
✅ theta_cl ~ 191.380 186.560 1 [Accept] 0.0
WT @ linear 281351533642
6431 < 0.05
(forward)
theta_v ~ WT 191.380 191.011 1 [Reject] 0.5
@ piecewise 434070317112
094 > 0.05
(forward)
────────────────────────────────────────────────────────────────────────────────
Iteration#3, Testing Branch 1 / 2...
theta_cl ~ WT @ piecewise
theta_v ~ WT @ linear
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 186.033
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 13
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.139
theta_v 8.076
theta_ka 1.337
theta_alag 0.823
WT__theta_ 0.012
cl_1
WT__theta_ 0.003
cl_2
WT__theta_ 0.013
v_1
Omega(SD)
eta_cl 0.264 0.000
eta_v 0.132 11.599
eta_ka 0.840 50.803
eta_alag 0.394 59.083
Sigma(SD)
eps_prop 0.087 13.875
eps_add 0.257 14.566
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
18 0:00:00.1 0:00:00.96
────────────────────────────────────────────────────────────────────────────────
[Reject] Base OFV: 186.56009477309667, Test OFV: 186.032994850381, Expected: 182.71863595240254, P Value: 0.4678286705081436 > 0.05 (forward), p-value criteria failed
Iteration#3, Testing Branch 2 / 2...
theta_cl ~ WT @ linear
theta_v ~ WT @ piecewise
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 186.202
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 13
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.133
theta_v 8.244
theta_ka 1.331
theta_alag 0.824
WT__theta_ 0.009
cl_1
WT__theta_ 0.014
v_1
WT__theta_ 0.010
v_2
Omega(SD)
eta_cl 0.266 0.000
eta_v 0.131 11.858
eta_ka 0.835 50.834
eta_alag 0.393 59.052
Sigma(SD)
eps_prop 0.087 13.842
eps_add 0.258 14.534
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
18 0:00:00.1 0:00:01.12
────────────────────────────────────────────────────────────────────────────────
[Reject] Base OFV: 186.56009477309667, Test OFV: 186.20224381538958, Expected: 182.71863595240254, P Value: 0.5497021877232625 > 0.05 (forward), p-value criteria failed
────────────────────────────────────────────────────────────────────────────────
Selected Model Base OFV Test OFV dDF Criteria
────────────────────────────────────────────────────────────────────────────────
theta_cl ~ 186.560 186.033 1 [Reject] 0.4
WT @ 678286705081
piecewise 436 > 0.05
(forward)
theta_v ~ WT 186.560 186.202 1 [Reject] 0.5
@ piecewise 497021877232
625 > 0.05
(forward)
────────────────────────────────────────────────────────────────────────────────
All candidates are rejected, stopping forward...
Forward search done. Starting backward search...
Iteration#4, Testing Branch 1 / 2...
theta_cl ~ WT @ exclude
theta_v ~ WT @ linear
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 191.380
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 11
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.132
theta_v 8.076
theta_ka 1.337
theta_alag 0.823
WT__theta_ 0.013
v_1
Omega(SD)
eta_cl 0.288 0.000
eta_v 0.133 11.532
eta_ka 0.839 50.848
eta_alag 0.394 59.031
Sigma(SD)
eps_prop 0.087 13.911
eps_add 0.257 14.602
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
19 0:00:00.1 0:00:00.81
────────────────────────────────────────────────────────────────────────────────
[Accept] Base OFV: 186.56009477309667, Test OFV: 191.3798614598505, Expected: 193.19499137411788, P Value: 0.02813515336426431 > 0.01 (backward), p-value criteria satisfied
Iteration#4, Testing Branch 2 / 2...
theta_cl ~ WT @ linear
theta_v ~ WT @ exclude
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 213.308
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 11
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.133
theta_v 7.977
theta_ka 1.355
theta_alag 0.825
WT__theta_ 0.009
cl_1
Omega(SD)
eta_cl 0.268 0.011
eta_v 0.220 3.975
eta_ka 0.836 50.395
eta_alag 0.394 59.285
Sigma(SD)
eps_prop 0.086 14.934
eps_add 0.260 15.617
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
16 0:00:00.1 0:00:00.72
────────────────────────────────────────────────────────────────────────────────
[Reject] Base OFV: 186.56009477309667, Test OFV: 213.30795749862867, Expected: 193.19499137411788, P Value: 2.3180797870114844e-07 < 0.01 (backward), p-value criteria failed
────────────────────────────────────────────────────────────────────────────────
Selected Model Base OFV Test OFV dDF Criteria
────────────────────────────────────────────────────────────────────────────────
✅ theta_cl ~ 186.560 191.380 -1 [Accept] 0.0
WT @ exclude 281351533642
6431 > 0.01
(backward)
theta_v ~ WT 186.560 213.308 -1 [Reject] 2.3
@ exclude 180797870114
844e-07 <
0.01
(backward)
────────────────────────────────────────────────────────────────────────────────
Iteration#5, Testing Branch 2 / 2...
theta_cl ~ WT @ exclude
theta_v ~ WT @ exclude
Fitting...
➡️ Since build cache already exists, skip compile
Done
Estimation Summary
────────────────────────────────────────────────────────────────────────────────
Estimation Covariance OFV Cond.
Number
────────────────────────────────────────────────────────────────────────────────
✅ Converged 217.997
────────────────────────────────────────────────────────────────────────────────
Number of Ob 250
servations:
Number of 10
Parameters:
Parameter Estimation
────────────────────────────────────────────────────────────────────────────────
Parameter Estimate RSE(%) Shrinkage(%)
────────────────────────────────────────────────────────────────────────────────
Theta
theta_cl 0.132
theta_v 7.978
theta_ka 1.354
theta_alag 0.824
Omega(SD)
eta_cl 0.289 0.000
eta_v 0.220 3.994
eta_ka 0.835 50.450
eta_alag 0.394 59.243
Sigma(SD)
eps_prop 0.086 14.953
eps_add 0.259 15.636
────────────────────────────────────────────────────────────────────────────────
Information
────────────────────────────────────────────────────────────────────────────────
Number of Time
Iterations
Compilation Estimation Covariance
────────────────────────────────────────────────────────────────────────────────
19 0:00:00.1 0:00:00.94
────────────────────────────────────────────────────────────────────────────────
[Reject] Base OFV: 191.3798614598505, Test OFV: 217.99745984151804, Expected: 198.0147580608717, P Value: 2.4797470199455773e-07 < 0.01 (backward), p-value criteria failed
────────────────────────────────────────────────────────────────────────────────
Selected Model Base OFV Test OFV dDF Criteria
────────────────────────────────────────────────────────────────────────────────
theta_v ~ WT 191.380 217.997 -1 [Reject] 2.4
@ exclude 797470199455
773e-07 <
0.01
(backward)
────────────────────────────────────────────────────────────────────────────────
All candidates are rejected, stopping backward...
Final Model:
class WarfarinPk__4_1(EvOneCmtLinear):
"""
theta_v ~ WT @ linear
"""
def __init__(self):
super().__init__()
self.theta_cl = theta(0.13214967026116575, bounds=(0.01, 10.0), fixed=False)
self.theta_v = theta(7.9779670063667325, bounds=(0.01, 20.0), fixed=False)
self.theta_ka = theta(1.354048807806639, bounds=(0.01, 5.0), fixed=False)
self.theta_alag = theta(0.8242517398514302, bounds=(0.01, 24.0), fixed=False)
self.WT__theta_v_1 = theta(-3.125e-05, bounds=(-0.03125, 0.03333333333333333), fixed=False)
self.eta_cl = omega(0.0834433566753548, fixed=False)
self.eta_v = omega(0.04847597272618166, fixed=False)
self.eta_ka = omega(0.6979357303081926, fixed=False)
self.eta_alag = omega(0.15551458646151314, fixed=False)
self.eps_prop = sigma(0.007463952003385256, fixed=False)
self.eps_add = sigma(0.06690288843036893, fixed=False)
self.WT = column('WT', dtype='numeric', is_categorical=False)
def pred(self):
WT__theta_cl = 1
WT__theta_v = 1 + self.WT__theta_v_1 * (self.WT - 70.0)
theta_cl__with_cov = self.theta_cl * WT__theta_cl
theta_v__with_cov = self.theta_v * WT__theta_v
cl = theta_cl__with_cov * exp(self.eta_cl)
v = theta_v__with_cov * exp(self.eta_v)
ka = self.theta_ka * exp(self.eta_ka)
alag = self.theta_alag * exp(self.eta_alag)
pred_res = self.pred_physio(cl=cl, v=v, ka=ka, alag1=alag, s2=v)
ipred = pred_res.F
y = ipred * (1 + self.eps_prop) + self.eps_add
return y
Computing Covariance...
Covariance computation succeed
Summary
Step | Test | OFV | DDF | P Value | Accepted | Selected | Model |
---|---|---|---|---|---|---|---|
1 | theta_cl ~ WT @ linear | 213.308(+4.690) | 1 | 0.030 < 0.05 (forward) | Yes | WarfarinPk__1_1 | |
theta_v ~ WT @ linear | 191.380(+26.618) | 1 | 0.000 < 0.05 (forward) | Yes | ✅ | WarfarinPk__1_2 | |
2 | theta_cl ~ WT @ linear | 186.560(+4.820) | 1 | 0.028 < 0.05 (forward) | Yes | ✅ | WarfarinPk__2_1 |
theta_v ~ WT @ piecewise | 191.011(+0.369) | 1 | 0.543 > 0.05 (forward) | No | WarfarinPk__2_2 | ||
3 | theta_cl ~ WT @ piecewise | 186.033(+0.527) | 1 | 0.468 > 0.05 (forward) | No | WarfarinPk__3_1 | |
theta_v ~ WT @ piecewise | 186.202(+0.358) | 1 | 0.550 > 0.05 (forward) | No | WarfarinPk__3_2 | ||
4 | theta_cl ~ WT @ exclude | 191.380(-4.820) | -1 | 0.028 > 0.01 (backward) | Yes | ✅ | WarfarinPk__4_1 |
theta_v ~ WT @ exclude | 213.308(-26.748) | -1 | 0.000 < 0.01 (backward) | No | WarfarinPk__4_2 | ||
5 | theta_v ~ WT @ exclude | 217.997(-26.618) | -1 | 0.000 < 0.01 (backward) | No | WarfarinPk__5_2 |
ScmResult#
- class ScmResult#
SCM 搜索结果,包含最终模型、运行日志以及各个步骤中的模型结果。
final_model#
- property final_model#
SCM 法搜索得到的最终模型。
类型:
ScmFinalModel
scm_res.final_model
class WarfarinPk__4_1(EvOneCmtLinear):
"""
theta_v ~ WT @ linear
"""
def __init__(self):
super().__init__()
self.theta_cl = theta(0.13225628140336454, bounds=(0.01, 10.0), fixed=False)
self.theta_v = theta(8.076371754991348, bounds=(0.01, 20.0), fixed=False)
self.theta_ka = theta(1.3368408859910255, bounds=(0.01, 5.0), fixed=False)
self.theta_alag = theta(0.8227523051009413, bounds=(0.01, 24.0), fixed=False)
self.WT__theta_v_1 = theta(0.013039911125114306, bounds=(-0.03125, 0.03333333333333333), fixed=False)
self.eta_cl = omega(0.08289638409433286, fixed=False)
self.eta_v = omega(0.01766768192187216, fixed=False)
self.eta_ka = omega(0.7037029773125222, fixed=False)
self.eta_alag = omega(0.15549785963005286, fixed=False)
self.eps_prop = sigma(0.007529493956931285, fixed=False)
self.eps_add = sigma(0.06592263102065547, fixed=False)
self.WT = column('WT', dtype='numeric', is_categorical=False)
def pred(self):
WT__theta_cl = 1
WT__theta_v = 1 + self.WT__theta_v_1 * (self.WT - 70.0)
theta_cl__with_cov = self.theta_cl * WT__theta_cl
theta_v__with_cov = self.theta_v * WT__theta_v
cl = theta_cl__with_cov * exp(self.eta_cl)
v = theta_v__with_cov * exp(self.eta_v)
ka = self.theta_ka * exp(self.eta_ka)
alag = self.theta_alag * exp(self.eta_alag)
pred_res = self.pred_physio(cl=cl, v=v, ka=ka, alag1=alag, s2=v)
ipred = pred_res.F
y = ipred * (1 + self.eps_prop) + self.eps_add
return y
steps#
- property steps#
各搜索步骤的模型测试结果。
类型:
list[ScmStepwiseResult]
as_dataframe()#
- as_dataframe()#
将搜索步骤与结果转为 dataframe 类型
类型:
DataFrame
scm_res.as_dataframe()
step | parameter | covariate | state | base_ofv | test_ofv | ofv_change | delta_df | p_value | alpha | direction | accepted | selected | model |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
i64 | str | str | str | f64 | f64 | f64 | i64 | f64 | f64 | str | bool | bool | str |
0 | "theta_cl" | "WT" | "linear" | 217.997459 | 213.307957 | 4.689502 | 1 | 0.030347 | 0.05 | "forward" | true | false | "WarfarinPk__1_1" |
0 | "theta_v" | "WT" | "linear" | 217.997459 | 191.379861 | 26.617598 | 1 | 2.4797e-7 | 0.05 | "forward" | true | true | "WarfarinPk__1_2" |
1 | "theta_cl" | "WT" | "linear" | 191.379861 | 186.560095 | 4.819767 | 1 | 0.028135 | 0.05 | "forward" | true | true | "WarfarinPk__2_1" |
1 | "theta_v" | "WT" | "piecewise" | 191.379861 | 191.0106 | 0.369262 | 1 | 0.543407 | 0.05 | "forward" | false | false | "WarfarinPk__2_2" |
2 | "theta_cl" | "WT" | "piecewise" | 186.560095 | 186.032995 | 0.5271 | 1 | 0.467829 | 0.05 | "forward" | false | false | "WarfarinPk__3_1" |
2 | "theta_v" | "WT" | "piecewise" | 186.560095 | 186.202244 | 0.357851 | 1 | 0.549702 | 0.05 | "forward" | false | false | "WarfarinPk__3_2" |
3 | "theta_cl" | "WT" | "exclude" | 186.560095 | 191.379861 | -4.819767 | -1 | 0.028135 | 0.01 | "backward" | true | true | "WarfarinPk__4_1" |
3 | "theta_v" | "WT" | "exclude" | 186.560095 | 213.307957 | -26.747863 | -1 | 2.3181e-7 | 0.01 | "backward" | false | false | "WarfarinPk__4_2" |
4 | "theta_v" | "WT" | "exclude" | 191.379861 | 217.99746 | -26.617598 | -1 | 2.4797e-7 | 0.01 | "backward" | false | false | "WarfarinPk__5_2" |