7.13 Table 7.17 comes from a General Social Survey. Subjects were asked whether meth- ods of birth control should be available to teenagers and how often they attend reli- gious services.
a. Fit the independence model. Describe the lack of fit.
R<-c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9)
T<-c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
count<-c(49,49,19,9,31,27,11,11,46,55,25,8,34,37,19,7,21,22,14,16,26,36,16,16,8,16,15,11,32,65,57,61,4,17,16,20)
data=data.frame(R,T,count)
model.ind<-glm(count~factor(R)+factor(T), family = poisson, data=data)
summary(model.ind)
##
## Call:
## glm(formula = count ~ factor(R) + factor(T), family = poisson,
## data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.7667 -0.9140 -0.1117 1.1532 3.6198
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.53086 0.10412 33.912 < 2e-16 ***
## factor(R)2 -0.45426 0.14296 -3.178 0.001485 **
## factor(R)3 0.06156 0.12409 0.496 0.619852
## factor(R)4 -0.26157 0.13508 -1.936 0.052812 .
## factor(R)5 -0.54582 0.14709 -3.711 0.000207 ***
## factor(R)6 -0.29299 0.13629 -2.150 0.031576 *
## factor(R)7 -0.92426 0.16714 -5.530 3.21e-08 ***
## factor(R)8 0.53436 0.11219 4.763 1.91e-06 ***
## factor(R)9 -0.79323 0.15963 -4.969 6.72e-07 ***
## factor(T)2 0.25529 0.08409 3.036 0.002397 **
## factor(T)3 -0.26796 0.09588 -2.795 0.005193 **
## factor(T)4 -0.45655 0.10136 -4.504 6.66e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 360.16 on 35 degrees of freedom
## Residual deviance: 112.54 on 24 degrees of freedom
## AIC: 312.35
##
## Number of Fisher Scoring iterations: 5
1-pchisq(112.54,24)
## [1] 2.025047e-13
The chi-square goodness of fit test yields a p-value of 2.025047e-13, which can be rounded to zero. Since 0<0.05, we would say that it is not a goodness of fit.
b. Using equally spaced scores, fit the linear-by-linear association model. Describe the association. Test goodness of fit. Test independence by using the ordinality, and interpret.
model.ass<-glm(count~factor(R)+factor(T)+R*T, family = poisson, data=data)
summary(model.ass)
##
## Call:
## glm(formula = count ~ factor(R) + factor(T) + R * T, family = poisson,
## data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.65027 -0.41789 0.06635 0.43607 1.69387
##
## Coefficients: (2 not defined because of singularities)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.87747 0.10196 38.028 < 2e-16 ***
## factor(R)2 -0.68153 0.14446 -4.718 2.39e-06 ***
## factor(R)3 -0.40555 0.13164 -3.081 0.00206 **
## factor(R)4 -0.98210 0.15198 -6.462 1.03e-10 ***
## factor(R)5 -1.53428 0.17693 -8.672 < 2e-16 ***
## factor(R)6 -1.56463 0.18847 -8.302 < 2e-16 ***
## factor(R)7 -2.49488 0.23513 -10.611 < 2e-16 ***
## factor(R)8 -1.35128 0.23276 -5.805 6.42e-09 ***
## factor(R)9 -3.00988 0.29309 -10.269 < 2e-16 ***
## factor(T)2 -0.27072 0.09866 -2.744 0.00607 **
## factor(T)3 -1.41907 0.15651 -9.067 < 2e-16 ***
## factor(T)4 -2.32803 0.23758 -9.799 < 2e-16 ***
## R NA NA NA NA
## T NA NA NA NA
## R:T 0.12148 0.01337 9.083 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 360.157 on 35 degrees of freedom
## Residual deviance: 19.901 on 23 degrees of freedom
## AIC: 221.71
##
## Number of Fisher Scoring iterations: 4
1-pchisq(19.9,23)
## [1] 0.6479365
P-value of chi-square goodness of fit is 0.64>0.05. Thus, it is a good fit for the model of assocaition.
Compared with independence model, the reductionn in deviance is 112-19.9=92.1 with df=24-23=1. Since the p-value is rounded to zero<0.05. We hace strong evidence of association.
The estimated local odds ratio is exp(0.12148)=1.13.
c. Fit the L × L model using column scores {1, 2, 4, 5}. Explain why a fitted local log odds ratio using columns 2 and 3 is double a fitted local log odds ratio using columns 1 and 2 or columns 3 and 4. What is the relation between the odds ratios?
Between column 2 and 3,local odds ratio is epx(0.0836(4-2))=1.1820 Between column 2 and 3, local odds ratio is exp(0.0836(2-1))=1.087