Sort xxtable () output by p-value from glm model summary

I model a lot of data for different companies, and for each company I need to quickly determine those parameters of the model that are most significant. What I would like to see is the xtable() output for a model that sorts all the coefficients in ascending order of p-value (i.e. the most important parameters).

 x <- data.frame(a=rnorm(100), b=runif(100), c=rnorm(100), e=rnorm(100)) fit <- glm(a ~ ., data=x) xtable(fit) 

I assume that I can accomplish something similar by messing up the structure of the fit object. But I am not familiar with the structure in order to be able to confidently change something.

Suggestions?

+4
source share
1 answer

Not necessarily the most elegant solution, but this should accomplish this task:

 data(birthwt, package="MASS") glm.res <- glm(low ~ ., data=birthwt[,-10]) idx <- order(coef(summary(glm.res))[,4]) # sort out the p-values out <- coef(summary(glm.res))[idx,] # reorder coef, SE, etc. by increasing p library(xtable) xtable(out) 

enter image description here

+6
source

Source: https://habr.com/ru/post/1395096/


All Articles