How to get z-statistic values ​​from glm object?

How can I get the values ​​of Z statistics as a vector from a glm object? For example, I have

 fit <- glm(y ~ 0 + x,binomial) 

How can I access the Pr(>|z|) column Pr(>|z|) in the same way as getting coefficient estimates using fit$coef ?

+7
source share
3 answers

I think that

 coef(summary(fit))[,"Pr(>|z|)"] 

will provide you with what you want. ( summary.glm() returns an object that has a coef() method that returns a table of coefficients.) (By the way, if access methods exist, it is better to use them than directly access the components of the finished model - for example, coef(fit) better than fit$coef .)

extracts p-values ​​and r-square from linear regression gives a similar answer.

I would suggest methods(class="summary.glm") find available access methods, but in fact it is a little more complicated, because the default methods (in this case coef.default() ) can also be relevant ...

PS , if you need Z values, coef(summary(fit))[,"z value"] should do this (your question is a bit ambiguous: usually, when people say "Z statistics", they mean that you need the test statistic value, not the p value)

+11
source

You can access the information you want by doing

 utils::data(anorexia, package="MASS") # Some data anorex.1 <- glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian, data = anorexia) # a glm model summary(anorex.1) summary(anorex.1)$coefficients[,3] # vector of t-values (Intercept) Prewt TreatCont TreatFT 3.716770 -3.508689 -2.163761 2.138933 summary(anorex.1)$coefficients[,4] # vector of p-values (Intercept) Prewt TreatCont TreatFT 0.0004101067 0.0008034250 0.0339993147 0.0360350847 summary(anorex.1)$coefficients[,3:4] # matrix t value Pr(>|t|) (Intercept) 3.716770 0.0004101067 Prewt -3.508689 0.0008034250 TreatCont -2.163761 0.0339993147 TreatFT 2.138933 0.0360350847 
Function

str will show you where each element is located inside the object, and [[ accessors (better than $ , as indicated by @DWin and @Ben Bolker) will extract information for you. Try str(summary(anorex.1)) to find out what this function does.

+1
source

I use the generic syntax: summary (my_model) [[1]] [[2]]. You can try using different combinations of numbers in "[[]]" to extract the necessary data. Of course, if I understood your question correctly :)

0
source

All Articles