sahara
sahara

Reputation: 143

function for removing nonsignificant variables at one step in R

I am trying to automate logistic regression in R. Basically, my source code will generate a new equation everyday as the input data is updated, (Variables, data format etc are same) and print out te significant variables with corresponding coefficients. When I use step function, sometimes the resulting coefficients are not significant. Therefore, I want to update my set of coefficients and get rid of all the ones that are not significant enough. Is there a function or automated way of doing it? If not, the only way I can think of is writing a script on another language that takes the coefficients and corresponding P value and checking significance, and rerunning R accordingly. But even for that, do you know how can I get only P values and coefficients of variables. I can either print whole summary of regression result with "summary" function. I can't reach only P values.

Thank you very much

Upvotes: 1

Views: 5347

Answers (1)

Eric Fail
Eric Fail

Reputation: 7928

It's a bit hard for me without sample code and data, but you can subset based on variable values like this,

newdata <- data[ which(data$p.value < 0.5), ]

You can inspect your R object using str, see ?str to figure out how to select whatever you want to use in your subset $p.value or $residuals.

If this doesn't answer your question try submitting some sample code and data.

Best, Eric

Upvotes: 1

Related Questions