Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get values of Z - statistic from glm object?

Tags:

r

glm

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

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

How can I access the column Pr(>|z|) the same way I get estimates of coefficients with fit$coef?

like image 235
Jevgenijs Strigins Avatar asked Sep 09 '12 17:09

Jevgenijs Strigins


People also ask

What is the z value in GLM?

The z value is the Wald statistic that tests the hypothesis that the estimate is zero. The null hypothesis is that the estimate has a normal distribution with mean zero and standard deviation of 1. The quoted p-value, P(>|z|), gives the tail area in a two-tailed test.

How do you find the z value in logistic regression?

The z-value is the regression coefficient divided by standard error. If the z-value is too big in magnitude, it indicates that the corresponding true regression coefficient is not 0 and the corresponding X-variable matters.

How do you interpret GLM results in R?

The lower the value, the better the model is able to predict the value of the response variable. with p degrees of freedom. We can then find the p-value associated with this Chi-Square statistic. The lower the p-value, the better the model is able to fit the dataset compared to a model with just an intercept term.

How do you interpret z values in regression?

Z-scores can be positive or negative. The sign tells you whether the observation is above or below the mean. For example, a z-score of +2 indicates that the data point falls two standard deviations above the mean, while a -2 signifies it is two standard deviations below the mean. A z-score of zero equals the mean.


2 Answers

I believe that

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

will get you what you want. (summary.glm() returns an object that has a coef() method that returns the coefficient table.) (By the way, if accessor methods exist it's better to use them than to directly access the components of the fitted model -- e.g. coef(fit) is better than fit$coef.)

pull out p-values and r-squared from a linear regression gives a similar answer.

I would suggest methods(class="summary.glm") to find available accessor methods, but it's actually a little bit trickier than that because the default methods (in this case coef.default()) may also be relevant ...

PS if you want the Z values, coef(summary(fit))[,"z value"] should do it (your question is a little bit ambiguous: usually when people say "Z statistic" they mean the want the value of the test statistic, rather than the p value)

like image 103
Ben Bolker Avatar answered Nov 08 '22 07:11

Ben Bolker


You can access to the info 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

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

like image 22
Jilber Urbina Avatar answered Nov 08 '22 08:11

Jilber Urbina