Tuesday 15 March 2011

finding certain variable name from glm model summary in R -



finding certain variable name from glm model summary in R -

i have glm model , want select name of variable coefficient has highest p-value. know how find highest p-value, , know how number of variable (in order in appears in model), don't know how variable name. reason want create loop on each iteration removes variable to the lowest degree important coefficient , reruns model. manually, have way many variables.

the next sample code of help. code outputs column name corresponding maximum p value (also, ignores intercept)

mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv") mydata$rank <- factor(mydata$rank) mylogit <- glm(admit ~ gre + gpa + rank, info = mydata, family = "binomial") coefficients <- coef(summary(mylogit)) maxpcolumn <- rownames(coefficients)[2:nrow(coefficients)][which.max(coefficients[2:nrow(coefficients),4])] maxpcolumn

r glm

No comments:

Post a Comment