Skip to content

Instantly share code, notes, and snippets.

@selftext
Created October 28, 2012 14:07
Show Gist options
  • Save selftext/3968692 to your computer and use it in GitHub Desktop.
Save selftext/3968692 to your computer and use it in GitHub Desktop.
G-test for goodness of fit in R
> x <- c(22.69,23.84,24.77,25.84,26.79,27.74,28.67,30.41)
> y <- c(5,4,17,21,15,20,15,14)
> ny <- c(9,10,11,18,7,4,3,0)
> ymat <- cbind(y,ny)
> m1 <- glm(ymat ~ x, family=binomial)
> summary(m1)
Call:
glm(formula = ymat ~ x, family = binomial)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.04867 -0.48888 0.06475 0.79123 1.40490
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -11.51402 2.54890 -4.517 6.26e-06 ***
x 0.46468 0.09855 4.715 2.41e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 34.0340 on 7 degrees of freedom
Residual deviance: 5.9696 on 6 degrees of freedom
AIC: 33.151
Number of Fisher Scoring iterations: 4
> deviance(m1)
[1] 5.969609
> 1-pchisq(5.9696,6)
[1] 0.4266041
> qchisq(.95,6)
[1] 12.59159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment