You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

mice插补后用multinom做多项回归的系数命名异常问题求助

Fixing Coefficient Labels for Multinomial Regression with MICE Imputation

I've run into this exact issue before! The problem stems from how nnet::multinom structures its coefficient output versus linear models like lm. For categorical response variables (like age in nhanes2), multinom produces coefficients for each non-reference category—but the mice::pool function doesn't automatically map these to meaningful labels, falling back to generic numbered identifiers instead.

Here are a few solid solutions to fix this:

Solution 1: Manually Correct Coefficient Names

You can extract the proper coefficient labels from one of the imputed models and overwrite the generic names in the pooled summary:

library(mice)
library(nnet)

# Run imputation (hide progress with printFlag=FALSE)
test <- mice(nhanes2, meth=c('sample','pmm','logreg','norm'), printFlag = FALSE)

# Fit multinomial regression across imputed datasets
m <- with(test, multinom(age ~ bmi, model = TRUE))

# Grab coefficient names from the first imputed model as a template
correct_coef_names <- rownames(coef(m$analyses[[1]]))

# Pool results and fix the row names
pooled_results <- pool(m)
pooled_summary <- summary(pooled_results)
rownames(pooled_summary) <- correct_coef_names

# View the cleaned output
pooled_summary

Solution 2: Use the broom Package for Tidy Model Output

The broom package simplifies working with model results across different model types. Combine it with dplyr to cleanly pool and summarize your multinomial models:

library(mice)
library(nnet)
library(broom)
library(dplyr)
library(purrr)

test <- mice(nhanes2, meth=c('sample','pmm','logreg','norm'), printFlag = FALSE)

# Extract tidy results from each imputed model
tidy_imputations <- map_dfr(m$analyses, ~tidy(.x, conf.int = TRUE))

# Pool results following MICE's variance pooling rules
pooled_tidy <- tidy_imputations %>%
  group_by(term, response) %>%
  summarise(
    estimate = mean(estimate),
    # Combine within-imputation and between-imputation variance
    std.error = sqrt(var(estimate) + mean(std.error^2)),
    statistic = mean(statistic),
    p.value = mean(p.value),
    conf.low = mean(conf.low),
    conf.high = mean(conf.high)
  )

# View the neatly labeled results
pooled_tidy

Alternative: Use Bayesian Multinomial Regression with brms

If you're open to Bayesian methods, the brms package handles imputed datasets (mira objects) seamlessly and automatically outputs properly labeled coefficients without extra work:

library(mice)
library(brms)

test <- mice(nhanes2, meth=c('sample','pmm','logreg','norm'), printFlag = FALSE)

# Fit Bayesian multinomial regression across imputations
brm_fit <- with(test, brm(age ~ bmi, family = categorical()))

# Pool and summarize the results
summary(pool(brm_fit))

内容的提问来源于stack exchange,提问作者Branners

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:18:05