statsmodels.imputation.mice.MICE¶
-
class statsmodels.imputation.mice.MICE(model_formula, model_class, data, n_skip=
3, init_kwds=None, fit_kwds=None)[source]¶ 使用链式方程进行多重插补。
此类可用于使用“链式方程的多重插补”(MICE)方法将大多数 statsmodels 模型拟合到包含缺失值的数据集。
- Parameters:¶
- model_formula
str 拟合到填补数据集的模型公式。此公式用于“分析模型”。
- model_class
statsmodelsmodel 拟合到填补数据集的模型。 这个模型类用于‘分析模型’。
- data
MICEDatainstance 包含要进行缺失值插补的数据集的MICEData对象
- n_skip
int 在连续的用于分析的插补数据集之间跳过的插补数据集的数量。
- init_kwdsdict-like
传递给分析模型初始化方法的关键字参数字典。
- fit_kwdsdict-like
传递给分析模型 fit 方法的关键字参数字典。
- model_formula
示例
运行所有MICE步骤并获取结果:
>>> imp = mice.MICEData(data) >>> fml = 'y ~ x1 + x2 + x3 + x4' >>> mice = mice.MICE(fml, sm.OLS, imp) >>> results = mice.fit(10, 10) >>> print(results.summary())Results: MICE ================================================================= Method: MICE Sample size: 1000 Model: OLS Scale 1.00 Dependent variable: y Num. imputations 10 ----------------------------------------------------------------- Coef. Std.Err. t P>|t| [0.025 0.975] FMI ----------------------------------------------------------------- Intercept -0.0234 0.0318 -0.7345 0.4626 -0.0858 0.0390 0.0128 x1 1.0305 0.0578 17.8342 0.0000 0.9172 1.1437 0.0309 x2 -0.0134 0.0162 -0.8282 0.4076 -0.0451 0.0183 0.0236 x3 -1.0260 0.0328 -31.2706 0.0000 -1.0903 -0.9617 0.0169 x4 -0.0253 0.0336 -0.7520 0.4521 -0.0911 0.0406 0.0269 =================================================================获取一系列未合并以获得摘要的拟合分析模型:
>>> imp = mice.MICEData(data) >>> fml = 'y ~ x1 + x2 + x3 + x4' >>> mice = mice.MICE(fml, sm.OLS, imp) >>> results = [] >>> for k in range(10): >>> x = mice.next_sample() >>> results.append(x)方法
combine()池化多重插补结果。
fit([n_burnin, n_imputations])使用MICE拟合模型。
执行一次完整的MICE迭代。
Last update:
Oct 16, 2024