1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rで重回帰分析のステップワイズで特定の変数を残したい

Posted at

Rを使って重回帰分析したあと、ステップワイズ法で変数選択をしてモデルの最適化を図ることはよくある。
その時に、理論的にある変数は必ず残したい、ということがある。そんな時の方法。

r.lm1 <-lm(`sQ1-1`~f1+f2+f3+f4+f5+f6+f7+`fQ5-1`+`fQ5-2`,
                na.omit(dataset[c("sQ1-1","sQ1-2","f1","f2","f3","f4","f5","f6","f7","fQ5-2","fQ5-1")]),
                )
summary(r.lm1)
summary(step(r.lm1, scope=list(lower=`sQ1-1`~`fQ5-1`+`fQ5-2`, upper=r.lm1),trace=FALSE))

ポイントは、scope=list(lower=****,upper=****)というところ。ここのlowerの方に、残しておきたい変数だけのモデル式を設定しておくとよい。

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?