library(ggplot2)
lines <-
"deposit sold returned
2.0 500.0 72.0
5.0 500.0 103.0
10.0 500.0 170.0
20.0 500.0 296.0
25.0 500.0 406.0
30.0 500.0 449.0"
con <- textConnection(lines)
bottles <- read.csv(con, sep="")
fit <- glm(formula = cbind(returned, sold - returned) ~ deposit, family = binomial,
data = bottles)
summary(fit)
##
## Call:
## glm(formula = cbind(returned, sold - returned) ~ deposit, family = binomial,
## data = bottles)
##
## Deviance Residuals:
## 1 2 3 4 5 6
## 0.1754 0.4330 0.5784 -2.9193 1.2710 1.2209
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.076565 0.084839 -24.48 <2e-16 ***
## deposit 0.135851 0.004772 28.47 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1108.171 on 5 degrees of freedom
## Residual deviance: 12.181 on 4 degrees of freedom
## AIC: 53.419
##
## Number of Fisher Scoring iterations: 3
exp(confint(fit))
## Waiting for profiling to be done...
## 2.5 % 97.5 %
## (Intercept) 0.1059309 0.1477395
## deposit 1.1349710 1.1564067
logit <- function(x){log(x/(1-x))}
qplot(deposit, returned/sold, data=bottles)

qplot(deposit, logit(returned/sold), data=bottles)

bottles$linear.predictors <- fit$linear.predictors
qplot(deposit, linear.predictors, data=bottles)

ggplot(bottles, aes(deposit)) +
geom_point(aes(y=returned/sold)) +
geom_line(aes(y=plogis(linear.predictors), colour="Prediction"))
