[R] extracting 'Z' value from a glm result
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Jan 29 10:25:45 CET 2006
Can I suggest rather using
> coef(summary(model))[, 3]
? It has the same effect for glm fits, but is more widely applicable.
Using the standard extractor functions can avoid some nasty surprises:
for example, summary.nls() has no documentation in 2.2.1 and uses
'parameters' rather than 'coefficients'.
On Sun, 29 Jan 2006, Chuck Cleland wrote:
> summary(model)$coefficients[,3]
>
> or
>
> summary(model)$coefficients[-1,3]
>
> For example:
>
> > counts <- c(18,17,15,20,10,20,25,13,12)
> > outcome <- gl(3,1,9)
> > treatment <- gl(3,3)
> > glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
> > summary(glm.D93)
>
> Call:
> glm(formula = counts ~ outcome + treatment, family = poisson())
>
> Deviance Residuals:
> 1 2 3 4 5 6 7
> -0.67125 0.96272 -0.16965 -0.21999 -0.95552 1.04939 0.84715
> 8 9
> -0.09167 -0.96656
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) 3.045e+00 1.709e-01 17.815 <2e-16 ***
> outcome2 -4.543e-01 2.022e-01 -2.247 0.0246 *
> outcome3 -2.930e-01 1.927e-01 -1.520 0.1285
> treatment2 8.717e-16 2.000e-01 4.36e-15 1.0000
> treatment3 4.557e-16 2.000e-01 2.28e-15 1.0000
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for poisson family taken to be 1)
>
> Null deviance: 10.5814 on 8 degrees of freedom
> Residual deviance: 5.1291 on 4 degrees of freedom
> AIC: 56.761
>
> Number of Fisher Scoring iterations: 4
>
> > summary(glm.D93)$coefficients[,3]
> (Intercept) outcome2 outcome3 treatment2 treatment3
> 1.781478e+01 -2.246889e+00 -1.520097e+00 4.358442e-15 2.278668e-15
> > summary(glm.D93)$coefficients[-1,3]
> outcome2 outcome3 treatment2 treatment3
> -2.246889e+00 -1.520097e+00 4.358442e-15 2.278668e-15
>
> Taka Matzmoto wrote:
>> Hello R users
>> I like to extract z values for x1 and x2. I know how to extract coefficents
>> using model$coef
>> but I don't know how to extract z values for each of independent variable. I
>> looked around
>> using names(model) but I couldn't find how to extract z values.
>>
>> Any help would be appreciated.
>>
>> Thanks
>>
>> TM
>>
>> #########################################################
>>> summary(model)
>>
>> Call:
>> glm(formula = y ~ x1+ x2, family = binomial)
>>
>> Deviance Residuals:
>> Min 1Q Median 3Q Max
>> -2.1397 -1.2357 0.6875 0.8517 1.5743
>>
>> Coefficients:
>> Estimate Std. Error z value Pr(>|z|)
>> (Intercept) -0.63930 1.13045 -0.566 0.572
>> x1 0.69956 0.09459 7.396 1.40e-13 ***
>> x2 1.51389 1.13212 1.337 0.181
>> ---
>> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>
>> (Dispersion parameter for binomial family taken to be 1)
>>
>> Null deviance: 1214.9 on 999 degrees of freedom
>> Residual deviance: 1149.8 on 997 degrees of freedom
>> AIC: 1155.8
>>
>> Number of Fisher Scoring iterations: 4
>> ############################################################
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>
> --
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 452-1424 (M, W, F)
> fax: (917) 438-0894
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list