从应用于估算数据集的广义加性模型 (GAM) 中提取有效自由度 (EDF)

问题描述 投票:0回答:1

如何从合并的广义加性模型中提取合并的估计自由度 (edf)?

library(mice)  # For multiple imputation
library(mgcv)  # For GAM models
library(broom) # For tidying model outputs

# Create a Sample Dataset
set.seed(123)  # for reproducibility
n <- 100
df <- data.frame(
  outcome_score = rnorm(n, 100, 15),
  exposure = rnorm(n, 0.5, 0.1)
)
df$exposure[sample(1:n, 20)] <- NA
imp <- mice(df, m = 5, method = 'pmm', seed = 500)

# Fit GAMs on MICEed data
micegam <- with(imp,  gam(outcome_score ~ s(exposure, bs = "bs")))

我尝试了以下方法:

poolgam <- pool(micegam)
summary_poolgam <- summary(poolgam)
tidy_poolgam <- tidy(poolgam, conf.int = TRUE)
r gam r-mice mgcv
1个回答
0
投票

您可以以长格式绑定插补数据集并计算 EDF

by
每个插补。

> cpl <- complete(imp, action='long')
> Edf <- by(cpl, ~.imp, \(X) {
+   edf <- gam(outcome_score ~ s(exposure, bs = "bs"), data=X)$edf
+   c(edf['(Intercept)'], total=sum(edf))
+ }) |> do.call(what='rbind')
> Edf
  (Intercept)    total
1           1 2.500043
2           1 2.000000
3           1 2.856669
4           1 2.565222
5           1 2.000000

我猜,汇总的 EDF 应该是

colMeans
,因为汇总的估计值通常是每个插补估计值的平均值。

> colMeans(Edf)
(Intercept)       total 
   1.000000    2.384387 
© www.soinside.com 2019 - 2024. All rights reserved.