2016-11-03 11 views
0

おかげregarding the failure of stepwise variable selection in lmステップパッケージのしきい値を設定する方法は?その記事で説明したように、この記事へ

私は例のデータを持っているが、以下のように見える、私は必要なもの

set.seed(1)   # for reproducible example 
x <- sample(1:500,500) # need this so predictors are not perfectly correlated. 
x <- matrix(x,nc=5) # 100 rows, 5 cols 
y <- 1+ 3*x[,1]+2*x[,2]+4*x[,5]+rnorm(100) # y depends on variables 1, 2, 5 only 

# you start here... 
df <- data.frame(y,as.matrix(x)) 
full.model <- lm(y ~ ., df)     # include all predictors 
step(full.model,direction="backward") 

は、これらのうちわずか5最高の変数と、その後6つの最良の変数を選択することです20、誰もこのcontarainsを作る方法を知っていますか?

答えて

0

MuMIn::dredge()には、用語数の制限に関するオプションがあります。
[注記]:必要な組み合わせの数は、予測変数の数とともに指数関数的に増加します。

set.seed(1)   # for reproducible example 
x <- sample(100*20) 
x <- matrix(x, nc = 20)  # 20 predictor 
y <- 1 + 2*x[,1] + 3*x[,2] + 4*x[,3] + 5*x[,7] + 6*x[,8] + 7*x[,9] + rnorm(100) # y depends on variables 1,2,3,7,8,9 only 

df <- data.frame(y, as.matrix(x)) 
full.model <- lm(y ~ ., df)     # include all predictors 

library(MuMIn) 

# options(na.action = "na.fail")  # trace = 2: a progress bar is displayed 
dredge(full.model, m.lim = c(5, 5), trace = 2)   # result: x2, x3, x7, x8, x9 
関連する問題