I have a matrix and a vector
set.seed(1) # I added this to have a reproducible values
X <- matrix(rexp(200, rate=.1), ncol=20)
Y <- matrix(rexp(10, rate=.1), ncol=1)
Then I randomly select 5 of the columns of X As @Laterow suggested # select 5 random columns from X temp <- sample(ncol(X), 5) X1 <- X[,temp]
Then I merge the X1 with my Y
mydata <- data.frame(cbind(Y,X1))
Then I build a regression
fit = lm(Y~.,data=mydata)
Then i obtain the sd
se <- sqrt(diag(vcov(fit)))
Now what I want to do is to change the column with the largest se with all other columns of my original X and keep the one with lowest se
for example if you run above, in the se, I have the X3 with biggest value
X3
7.348126e-18
so I change the column 3 of X1 with all other columns except itself from the X
Now I want to automatically change column 3 with all other columns except itself from the X
if you do
> temp
#[1] 18 4 9 8 10
it the X1 column 3 changed by all columns of X except 9