R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SMPracticals)
Loading required package: ellipse
> data(toxo)
> toxo.glm <- glm(cbind(r,m-r) ~ poly(rain,3), data = toxo, family = binomial)
> summary(toxo.glm)

Call:
glm(formula = cbind(r, m - r) ~ poly(rain, 3), family = binomial, 
    data = toxo)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.7620  -1.2166  -0.5079   0.3538   2.6204  

Coefficients:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)     0.02427    0.07693   0.315 0.752401    
poly(rain, 3)1 -0.08606    0.45870  -0.188 0.851172    
poly(rain, 3)2 -0.19269    0.46739  -0.412 0.680141    
poly(rain, 3)3  1.37875    0.41150   3.351 0.000806 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 74.212  on 33  degrees of freedom
Residual deviance: 62.635  on 30  degrees of freedom
AIC: 161.33

Number of Fisher Scoring iterations: 3

> toxo.quasi <- glm(cbind(r,m-r) ~ poly(rain,3), data = toxo, family = quasibinomial)
> summary(toxo.quasi)

Call:
glm(formula = cbind(r, m - r) ~ poly(rain, 3), family = quasibinomial, 
    data = toxo)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.7620  -1.2166  -0.5079   0.3538   2.6204  

Coefficients:
               Estimate Std. Error t value Pr(>|t|)  
(Intercept)     0.02427    0.10716   0.226   0.8224  
poly(rain, 3)1 -0.08606    0.63897  -0.135   0.8938  
poly(rain, 3)2 -0.19269    0.65108  -0.296   0.7693  
poly(rain, 3)3  1.37875    0.57321   2.405   0.0225 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for quasibinomial family taken to be 1.940446)

    Null deviance: 74.212  on 33  degrees of freedom
Residual deviance: 62.635  on 30  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 3

> anova(toxo.glm)
Analysis of Deviance Table

Model: binomial, link: logit

Response: cbind(r, m - r)

Terms added sequentially (first to last)

              Df Deviance Resid. Df Resid. Dev
NULL                             33     74.212
poly(rain, 3)  3   11.577        30     62.635
> toxo.glm2 <- glm(cbind(r,m-r) ~ rain +I(rain^2)+I(rain^3), data = toxo, family = binomial)
> anova(toxo.glm2)
Analysis of Deviance Table

Model: binomial, link: logit

Response: cbind(r, m - r)

Terms added sequentially (first to last)

          Df Deviance Resid. Df Resid. Dev
NULL                         33     74.212
rain       1   0.1244        32     74.087
I(rain^2)  1   0.0000        31     74.087
I(rain^3)  1  11.4529        30     62.635
> toxo.quasi2 <- glm(cbind(r,m-r) ~ rain + I(rain^2)+I(rain^3), data = toxo, family = quasibinomial)
> anova(toxo.quasi2)
Analysis of Deviance Table

Model: quasibinomial, link: logit

Response: cbind(r, m - r)

Terms added sequentially (first to last)

          Df Deviance Resid. Df Resid. Dev
NULL                         33     74.212
rain       1   0.1244        32     74.087
I(rain^2)  1   0.0000        31     74.087
I(rain^3)  1  11.4529        30     62.635
> summary(toxo.quasi2)

Call:
glm(formula = cbind(r, m - r) ~ rain + I(rain^2) + I(rain^3), 
    family = quasibinomial, data = toxo)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.7620  -1.2166  -0.5079   0.3538   2.6204  

Coefficients:
              Estimate Std. Error t value Pr(>|t|)  
(Intercept) -2.902e+02  1.215e+02  -2.388   0.0234 *
rain         4.500e-01  1.876e-01   2.398   0.0229 *
I(rain^2)   -2.311e-04  9.616e-05  -2.404   0.0226 *
I(rain^3)    3.932e-08  1.635e-08   2.405   0.0225 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for quasibinomial family taken to be 1.940446)

    Null deviance: 74.212  on 33  degrees of freedom
Residual deviance: 62.635  on 30  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 3

> summary(toxo.quasi)

Call:
glm(formula = cbind(r, m - r) ~ poly(rain, 3), family = quasibinomial, 
    data = toxo)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.7620  -1.2166  -0.5079   0.3538   2.6204  

Coefficients:
               Estimate Std. Error t value Pr(>|t|)  
(Intercept)     0.02427    0.10716   0.226   0.8224  
poly(rain, 3)1 -0.08606    0.63897  -0.135   0.8938  
poly(rain, 3)2 -0.19269    0.65108  -0.296   0.7693  
poly(rain, 3)3  1.37875    0.57321   2.405   0.0225 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for quasibinomial family taken to be 1.940446)

    Null deviance: 74.212  on 33  degrees of freedom
Residual deviance: 62.635  on 30  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 3

> (74.212-62.635)/3
[1] 3.859
> .Last.value/(62.635/30)
[1] 1.848328
> 62.635/30
[1] 2.087833
> 3.859/1.9404
[1] 1.988765
> pf(.Last.value,df1=3,df2=30)
[1] 0.8631229
> 1-.Last.value
[1] 0.1368771
> 1-pchisq(3.859,30)
[1] 1
> 1-pchisq(3.859,3)
[1] 0.2770976
> with(toxo, plot(rain, r/m), xlab="rainfall", ylab = "proportion positive", xlim = c(1600, 2400), ylim = c(0,1))
> points(rain,toxo.glm$fitted.values, pch="+", col="red")
Error in points(rain, toxo.glm$fitted.values, pch = "+", col = "red") : 
  object 'rain' not found
> with(toxo, points(rain,toxo.glm$fitted.values, pch="+", col="red"))
> ?curve
> 1-pchisq(74.212-62.635,3)
[1] 0.008982002