0
多虧了這個帖子regarding the failure of stepwise variable selection in lm如何設置Step包的門檻?
我有實例中的數據看起來就像是在該職位描述如下
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,有沒有人知道如何使這種聯繫?