Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent R function "step" from outputing to the console?

Tags:

r

The step function always prints the result of each stepwise regression to the console, even if the executed statement is an assignment, not evaluation. How do I make it just silently select predictors, without printing anything?

like image 850
Fermat's Little Student Avatar asked Dec 18 '14 06:12

Fermat's Little Student


1 Answers

In the help file of function step() you can find that there is argument trace=. If you set this argument to 0 then only final predictors are printed or if you use step() in assignment then nothing is printed.

Modified example from help file:

summary(lm1 <- lm(Fertility ~ ., data = swiss))
slm1 <- step(lm1,trace=0)
summary(slm1)

Or

step(lm1, trace=0)

Call:
lm(formula = Fertility ~ Agriculture + Education + Catholic + 
    Infant.Mortality, data = swiss)

Coefficients:
     (Intercept)       Agriculture         Education          Catholic  
         62.1013           -0.1546           -0.9803            0.1247  
Infant.Mortality  
          1.0784 
like image 112
Didzis Elferts Avatar answered Nov 05 '22 09:11

Didzis Elferts