LoginSignup
1
0

More than 5 years have passed since last update.

{lmerTest} packages ステップワイズするとき 回帰モデル

Posted at

lmer関数を用いるような混合モデルをやるときにもステップワイズを勿論行います。
ただしlibrary(MASS)のstepAICが使えないためにlibrary(MuMIn)のdrege関数でモデル選択をすると総当たりなため非常に遅くて悩んでいましたが、もっと高速な関数があったので比較した結果をメモしておきます。

library(lme4)
library(MuMIn)
library(lmerTest)

# 大気汚染のデータで回帰モデル
data(airquality)

# 一旦欠損値を取り除く
air_data <- airquality[!is.na(airquality$Ozone) & !is.na(airquality$Solar.R),]

# 月によって風の強さが違うと仮定
model_result <- lmer(Ozone~Solar.R+(Wind|Month)+Temp+Day, data= air_data)

# おまじない
options(na.action = "na.fail")

# dregeとstepでの時間比較
step_dredge_time <- system.time(drege_model_select <- dredge(model_result,rank = "AIC", fixed = NULL, m.lim = NULL,trace = TRUE))
step_step_time <- system.time(step_model_select <- step(model_result))

私の手元環境ではdregeが1.08秒でlmerTestパッケージのstep関数ならば0.58秒で約半分ぐらい速度的に異なりました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0