多重代入法で欠損値を補完した後に Cox 回帰の Wald 検定を統合する方法
多重代入法
多重代入法とは、欠損値を、取得されている変数から推測して、いくつかの値で補完して、いくつかのデータセットを作成し、解析したのち、結果を統合する方法
詳しくは、こちらも参照のこと
Cox 回帰の Wald 検定の統合
Cox 回帰の 3 値以上カテゴリを有するカテゴリカルデータのパラメータの検定には、Wald 検定という、カイ二乗値を用いた検定が使われる
この検定の統合方法を紹介する
サンプルスクリプト
以下のスクリプトの流れを紹介すると、以下のようになる
実際のスクリプトは以下のとおり
読み込んだデータセット名、cph 関数内の変数名、説明変数の数の分だけ anova.values という結果格納オブジェクトを増やして、スクリプトも加筆すると、同じように計算できる
# load sample data データ読み込み load("C:/Users/touke/OneDrive/R_Datasets/lung_rev.RData") df <- lung_rev summary(df) # imputation 多重代入 library(mice) df_imputed <- mice(df, seed=0) df_imputed # Initialize a list to store the results 結果格納オブジェクトの初期化 anova.values1 <- list() anova.values2 <- list() # Cox model using cph in rms; rms パッケージの cph 関数を使った Cox 回帰を実施 # Loop through numbers 1 to 5; 代入データセット 1 から 5 をループ処理 library(rms) for (i in 1:5) { # Complete the data with imputation number i df_imp <- complete(df_imputed, i) # Fit the Cox proportional hazards model cph_imp <- with(df_imp, cph(Surv(time, status01) ~ ph.ecog012 + meal.cal)) # Perform ANOVA and store the result in the list anova_result1 <- anova(cph_imp)[1] anova_result2 <- anova(cph_imp)[2] anova.values1[[i]] <- anova_result1 anova.values2[[i]] <- anova_result2 } # Combine the ANOVA results into a single vector; Wald 検定の結果を結合 anova_values1 <- unlist(anova.values1) anova_values2 <- unlist(anova.values2) # Display the combined ANOVA results; Wald 検定の結果を表示 anova_values1 anova_values2 # Pool chi-squares カイ二乗値の統合 library(miceadds) micombine.chisquare(anova_values1, df=2) micombine.chisquare(anova_values2, df=1)
結合したカイ二乗値は、以下のとおりになる
統合した結果は、以下のとおり
説明変数 1 番目の ph.ecog012 は、統計学的に有意である
2 番目の meal.cal は統計学的有意ではなかった
まとめ
R において、mice で多重代入したのち、Cox 回帰の Wald 検定を統合したいときのスクリプトを紹介した
rms パッケージの cph 関数と、miceadds パッケージの micobine.chisquare 関数を使うと実行できる
途中、for loop を使って、多重代入セットを効率よく処理する必要がある
何らか参考になれば幸い
参考サイト
https://bookdown.org/mwheymans/bookmi/pooling-methods-for-categorical-variables.html