HI, I am not sure about the ?update() method. You could try this:
set.seed(232) mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8) #with 8 columns dat1<-data.frame(mat1) names(dat1)[1]<-"Y" fit<-lm(Y~.,data=dat1) res<-coef(summary(fit)) res # Estimate Std. Error t value Pr(>|t|) #(Intercept) 143.763081344 21.9902865 6.53757200 0.02260698 #X2 -0.009030461 0.1103611 -0.08182650 0.94223654 #X3 -1.844809745 0.2655513 -6.94709326 0.02009766 #X4 1.436647351 0.2540660 5.65462216 0.02988003 #X5 -0.005406684 0.2906822 -0.01859998 0.98684896 #X6 -0.050101169 0.1486149 -0.33712071 0.76811703 #X7 0.563284987 0.1204945 4.67477901 0.04284010 #X8 -1.901918462 0.2697166 -7.05154460 0.01952387 Wtd<-row.names(res[res[,"Pr(>|t|)"]<0.05,]) Wtd1<-Wtd[!grepl("\\(.*\\)",Wtd)] fit1<-lm(as.formula(paste("Y~",paste(Wtd1,collapse="+"))),data=dat1) coef(summary(fit1)) # Estimate Std. Error t value Pr(>|t|) #(Intercept) 146.8921451 10.87053736 13.51287 3.975711e-05 #X3 -1.9002023 0.10667909 -17.81232 1.023637e-05 #X4 1.4421062 0.09790384 14.72982 2.606788e-05 #X7 0.5726324 0.05396720 10.61075 1.285606e-04 #X8 -1.9560052 0.14204298 -13.77052 3.625118e-05 A.K. ________________________________ From: farnoosh sheikhi <farnoosh...@yahoo.com> To: arun <smartpink...@yahoo.com> Sent: Wednesday, November 21, 2012 2:47 PM Subject: update fit (removing insignificant variables) Hi there, I have a question for removing insignificant predictors from fit. The output looks like below but with 170 predictors. Lab_1 0.037928 * Lab_2 0.030423 * Lab_4 0.616122 Lab_7 0.101278 Lab_8 2.44e-06 *** Lab_12 0.003181 ** Lab_14 0.096809 I need to update my model with significant ones. I know if I want to remove one, I use the following code, but I don't know how to do that for 70 insignificant predictors. fit2<-update(fit, .~. -Lab_7) Thanks a lot. Best,Farnoosh Sheikhi ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.