###############################################
# HOW TO USE THIS FILE 
# This is an HTML file to show you what R output looks like 
# Comments relate to interpretation of output 
# for comments on how torun code see the html R source code
red stuff is (R commands)
blue is output
# Black is comment
Links in this page
Simple means and proportions Table 2.3
Effect of design aspects on precision of estimates table 2.4
Chi square tests tables 2.6 onwards
Internet use by council area
Survey logistic regressions
Code to plot Figure 1
> names(shs)
  
 [1] "PSU"      "UNIQID"   "IND_WT"   "SHS_6CLA" "COUNCIL" 
 [6] "RC5"      "RC7E"     "RC7G"     "INTUSE"   "GROUPINC"
[11] "CLUST"    "STRATUM"  "AGE"      "SEX"      "EMP_STA" 
[16] "GROSSWT"  "GROC"
  
# the range of weights is pretty large and the ratio of the most 
# extreme weights is big
# the range of weights is 
# large and the ratio of  
# extremes of weights is big
 
>  hist(shs$IND_WT,col='red')
>  range(shs$IND_WT)
[1] 0.05373944 6.29964895
  
weights graph
>  max(shs$IND_WT)/min(shs$IND_WT)
[1] 117.2258
> library(survey)
> shs.des <- svydesign(id=~PSU, weights=~GROSSWT,strata=~STRATUM,data=shs)
> print(summary(shs.des))
Stratified 1 - level Cluster Sampling design
With (11937) clusters.
svydesign(id = ~PSU, weights = ~GROSSWT, strata = ~STRATUM, data = shs)
Probabilities:
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
0.001113 0.005406 0.007731 0.010660 0.011650 0.130500 
Stratum Sizes: 
             1   2   3  4  5  6   7   8  9 10  11  12  13
obs        202 130 192 22 95 78 137 246 54  8 142 194 144
design.PSU 202 130 192 22 95 78 137 246 54  8  13  18  13
actual.PSU 202 130 192 22 95 78 137 246 54  8  13  18  13


lines ommitted here
           269 270 271 272 273 274 275 276 277 278 279 280
obs         46  65  63  37  11  32  11  64 168 223 157  88
design.PSU  46  65  63  37  11  32  11   7  20  21  13   9
actual.PSU  46  65  63  37  11  32  11   7  20  21  13   9
           281
obs         34
design.PSU   4
actual.PSU   4
Data variables:
 [1] "PSU"      "UNIQID"   "IND_WT"   "SHS_6CLA" "COUNCIL" 
 [6] "RC5"      "RC7E"     "RC7G"     "INTUSE"   "GROUPINC"
[11] "CLUST"    "STRATUM"  "AGE"      "SEX"      "EMP_STA" 
[16] "GROSSWT"  "GROC"    
> # NOTE THAT SOME STRATA HAVE BEEN COMBINED TO PREVENT LONELY PSUS
#  back to top uparrow

> svymean(~INTUSE,shs.des,deff=T)
            mean        SE   DEff
INTUSE 0.3415642 0.0034046 1.4889
> svyby(~INTUSE,~SEX,shs.des,svymean,keep.var=T,deff=T)
          SEX statistic.INTUSE          SE     DEff
male     male        0.3851593 0.005124113 1.358964
female female        0.3070535 0.004329645 1.465283
There were 18 warnings (use warnings() to see them)
# The error messages are because splitting the data by sex has
# produced a few more lonely PSUS. See the html help for
# survey.lonely.psu by following links from html help menu to 
# >packages >survey 
# A better option is  to adjust estimates for this 
> options("survey.adjust.domain.lonely"=T)
> options("survey.lonely.psu"='adjust')
> svyby(~INTUSE,~SEX,shs.des,svymean,keep.var=T,deff=T)
          SEX statistic.INTUSE          SE     DEff
male     male        0.3851593 0.005124113 1.358964
female female        0.3070535 0.004329645 1.465283
There were 18 warnings (use warnings() to see them)

# this increases the design effect by only a tiny amount 
# so not worth fussing with here
> svymean(~RC5,subset(shs.des,INTUSE==1),deff=T)
                                     mean        SE   DEff
RC5Up to 1 hour a week          0.4082868 0.0060968 1.3722
RC5Over 1 hour, up to 5 hours   0.4066075 0.0060470 1.3517
RC5Over 5 hours up to 10 hours  0.1082947 0.0037595 1.3054
RC5Over 10 hours up to 20 hours 0.0507795 0.0027595 1.4090
RC5Over 20 hours                0.0260314 0.0019740 1.3707
There were 18 warnings (use warnings() to see them)
#  back to top uparrow

# testing efect of different designs
> shs.des <- svydesign(id=~UNIQID, weights=~GROSSWT,data=shs)
> svymean(~INTUSE,shs.des,deff=T)
            mean        SE  DEff
INTUSE 0.3415642 0.0032671 1.371
> shs.des <- svydesign(id=~PSU, weights=~GROSSWT,data=shs)
> svymean(~INTUSE,shs.des,deff=T)
            mean        SE   DEff
INTUSE 0.3415642 0.0037742 1.8297
> shs.des <- svydesign(id=~UNIQID, weights=~GROSSWT,strata=~STRATUM,data=shs)
> svymean(~INTUSE,shs.des,deff=T)
            mean        SE   DEff
INTUSE 0.3415642 0.0031608 1.2833
> shs.des <- svydesign(id=~PSU, weights=~GROSSWT,strata=~STRATUM,data=shs)
> svymean(~INTUSE,shs.des,deff=T)
            mean        SE   DEff
INTUSE 0.3415642 0.0034046 1.4889
# back to top uparrow
> svychisq(~INTUSE+SEX,shs.des)

        Pearson's X^2: Rao & Scott adjustment

data:  svychisq(~INTUSE + SEX, shs.des) 
F = 143.8122, ndf = 1, ddf = 11936, p-value <
2.2e-16

> chisq.test(table(shs$INTUSE,shs$SEX),correct=F)
> svytable(~INTUSE+SEX,shs.des)
      SEX
INTUSE male      female   
     0 1109378.6 1579433.7
     1  694956.4  699867.4
# table gives sum of weights by default
 
> svytable(~SEX+GROC,shs.des)
        GROC
SEX      0          1         
  male   1755180.10   49154.96
  female 2211799.09   67502.00
> svychisq(~GROC+SEX,shs.des)
        Pearson's X^2: Rao & Scott adjustment

data:  svychisq(~GROC + SEX, shs.des) 
F = 1.0726, ndf = 1, ddf = 11936, p-value = 0.3004
> chisq.test(table(shs$GROC,shs$SEX),correct=F)
        Pearson's Chi-squared test

data:  table(shs$GROC, shs$SEX) 
X-squared = 0.1983, df = 1, p-value = 0.6561

> svychisq(~RC5+EMP_STA,subset(shs.des,INTUSE==1))

        Pearson's X^2: Rao & Scott adjustment

data:  svychisq(~RC5 + EMP_STA, subset(shs.des, INTUSE == 1)) 
F = 7.191, ndf = 42.015, ddf = 205243.504, p-value <
2.2e-16

Warning messages: 
1: Stratum (47) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  
2: Stratum (58) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  
3: Stratum (77) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  
4: Stratum (92) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  
5: Stratum (97) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  
6: Stratum (260) has only one PSU at stage 1 in: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],
 # more lonely PSUs  
> chisq.test(table(shs$RC5,shs$EMP_STA),correct=T)
        Pearson's Chi-squared test

data:  table(shs$RC5, shs$EMP_STA) 
X-squared = 348.1233, df = 44, p-value < 2.2e-16

Warning message: 
Chi-squared approximation may be incorrect in: chisq.test(table(shs$RC5, shs$EMP_STA), correct = T)
# as is often the case, this message is not necessary, 
# rule of thumb used by program is too strict  
# back to top uparrow
> svyby(~INTUSE,~COUNCIL,shs.des,svymean,keep.var=T,deff=T)
                                COUNCIL statistic.INTUSE         SE     DEff
Aberdeen City             Aberdeen City        0.4259058 0.01549399 1.150013
Aberdeenshire             Aberdeenshire        0.3730824 0.01776256 1.530558
Angus                             Angus        0.3570794 0.02228616 1.383812
Argyll & Bute             Argyll & Bute        0.3244755 0.02701520 1.838561
Clackmannanshire       Clackmannanshire        0.3005110 0.03016245 2.281721
Dumfries & Galloway Dumfries & Galloway        0.2524177 0.01676567 1.162006
Dundee City                 Dundee City        0.3167761 0.01821253 1.215296
East Ayrshire             East Ayrshire        0.2995928 0.02261369 1.607520
East Dunbartonshire East Dunbartonshire        0.4710906 0.02366215 1.258309
East Lothian               East Lothian        0.3789814 0.02632696 1.641675
East Renfrewshire     East Renfrewshire        0.4395395 0.02396917 1.187309
Edinburgh, City of   Edinburgh, City of        0.4516778 0.01133339 1.165448
Eilean Siar                 Eilean Siar        0.2594083 0.02015594 1.371884
Falkirk                         Falkirk        0.3389266 0.01965099 1.294220
Fife                               Fife        0.3304139 0.01376578 1.524050
Glasgow City               Glasgow City        0.2788830 0.00895252 1.217506
Highland                       Highland        0.3830987 0.01690704 1.316076
Inverclyde                   Inverclyde        0.2964038 0.02291117 1.264850
Midlothian                   Midlothian        0.3433780 0.02326079 1.464382
Moray                             Moray        0.3067903 0.02525173 1.757371
North Ayrshire           North Ayrshire        0.2462255 0.02206251 1.921944
North Lanarkshire     North Lanarkshire        0.2802862 0.01491976 1.717864
Orkney Islands           Orkney Islands        0.3083178 0.03012039 2.724578
Perth & Kinross         Perth & Kinross        0.3762066 0.02259931 1.478352
Renfrewshire               Renfrewshire        0.3161091 0.01742582 1.270713
Scottish Borders       Scottish Borders        0.3575336 0.02692191 1.935275
Shetland Islands       Shetland Islands        0.4711420 0.02854234 2.054934
South Ayrshire           South Ayrshire        0.3294139 0.02528204 1.952842
South Lanarkshire     South Lanarkshire        0.3189291 0.01561810 1.726094
Stirling                       Stirling        0.4327323 0.02651420 1.647057
West Dunbartonshire West Dunbartonshire        0.2791583 0.02367021 1.398244
West Lothian               West Lothian        0.3524483 0.02099518 1.426553
# back to top uparrow
> summary(svyglm(INTUSE~GROUPINC,subset(shs.des,!is.na(GROUPINC)),family='binomial'))
Call:
svyglm.survey.design(formula = INTUSE ~ GROUPINC, design = subset(shs.des, 
    !is.na(GROUPINC)), family = "binomial")

Survey design:
subset.survey.design(shs.des, !is.na(GROUPINC))

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)       -1.11339    0.10629 -10.475  < 2e-16 ***
GROUPINCunder 10K -0.76785    0.11376  -6.750 1.51e-11 ***
GROUPINC10-20K     0.04745    0.10883   0.436    0.663    
GROUPINC20-30k     0.97683    0.11043   8.845  < 2e-16 ***
GROUPINC30-50k     1.89464    0.11504  16.470  < 2e-16 ***
GROUPINC50K+       2.44274    0.16282  15.003  < 2e-16 ***
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

(Dispersion parameter for binomial family taken to be 1)

Number of Fisher Scoring iterations: 5

> # add rurality
> summary(svyglm(INTUSE~GROUPINC+SHS_6CLA,subset(shs.des,!is.na(GROUPINC)),family='binomial'))

Call:
svyglm.survey.design(formula = INTUSE ~ GROUPINC + SHS_6CLA, 
    design = subset(shs.des, !is.na(GROUPINC)), family = "binomial")

Survey design:
subset.survey.design(shs.des, !is.na(GROUPINC))

Coefficients:
                         Estimate Std. Error t value Pr(>|t|)    
(Intercept)              -1.04553    0.10782  -9.697  < 2e-16 ***
GROUPINCunder 10K        -0.76579    0.11476  -6.673 2.55e-11 ***
GROUPINC10-20K            0.05813    0.10987   0.529  0.59671    
GROUPINC20-30k            0.99344    0.11160   8.901  < 2e-16 ***
GROUPINC30-50k            1.91223    0.11620  16.457  < 2e-16 ***
GROUPINC50K+              2.44744    0.16402  14.922  < 2e-16 ***
SHS_6CLAoth urban        -0.18763    0.04109  -4.566 4.99e-06 ***
SHS_6CLAaccessible towns -0.06250    0.05738  -1.089  0.27606    
SHS_6CLAremote towns     -0.09267    0.10321  -0.898  0.36928    
SHS_6CLAaccessible rural -0.14266    0.05253  -2.716  0.00661 ** 
SHS_6CLAremote rural      0.02935    0.06747   0.435  0.66354    
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

(Dispersion parameter for binomial family taken to be 0.9972467)

Number of Fisher Scoring iterations: 5
#  back to top uparrow
#
> fit<-svyglm(INTUSE~GROUPINC,design=shs.des)
# now some more complicated code to fit the curves for age and sex # # shown on the first page of this exemplar
# using the splines library in R
> library(splines)
# replace one missing value in age
> shs$AGE[is.na(shs$AGE)]<-40
> splinexs<-bs(shs$AGE,knots=c(25,45,65),degree=3)
> SP1<-splinexs[,1]
> SP2<-splinexs[,2]
> SP3<-splinexs[,3]
> SP4<-splinexs[,4]
> SP5<-splinexs[,5]
> SP6<-splinexs[,6]
# add extra vars to survey design
> shs.des<-update(shs.des,SP1=SP1,SP2=SP2,SP3=SP3,SP4=SP4,SP5=SP5,SP6=SP6,AGE=AGE)
> fit<-svyglm(INTUSE~SP1+SP2+SP3+SP5+SP6
+       +(as.integer(SEX)-1)+ (as.integer(SEX)-1)*SP1+
+      (as.integer(SEX)-1)*SP2+(as.integer(SEX)-1)*SP3+
+         (as.integer(SEX)-1)*SP4+(as.integer(SEX)-1)*SP5+ 
+            (as.integer(SEX)-1)*SP6                                            
+             , design=shs.des, family='binomial')
> plot(c(15,83),c(0,65),type='n',xlab='age',ylab='% internet users',)
> ilogit<-function(x){1/(1+exp(-x))}
> Mfit<- ilogit(predict(fit))[shs$SEX=='male'][match(c(16:80),shs$AGE[shs$SEX=='male'])]*100
> Wfit<- ilogit(predict(fit))[shs$SEX=='female'][match(c(16:80),shs$AGE[shs$SEX=='female'])]*100
> agemeans<-svyby(~INTUSE,~SEX+AGE,shs.des,svymean)
> usebyageM<-agemeans[1:65,3]*100
> usebyageW<-agemeans[1:65+65,3]*100
> plot(c(15,83),c(0,65),type='n',xlab='age',ylab='% internet users',)
> points(c(16:79,82),usebyageM)
> points(c(16:79,82),usebyageW,col=2,pch=16)
> lines(c(16:79,82),Mfit,lwd=2)
> lines(c(16:79,82),Wfit,lwd=2,col=2)
##########################################################
> # now look at additional effect of other variables
> #
> summary(update(fit,~.+SHS_6CLA))
Call:
svyglm.survey.design(formula = INTUSE ~ SP1 + SP2 + SP3 + SP5 + 
    SP6 + as.integer(SEX) + SP4 + SHS_6CLA + SP1:as.integer(SEX) + 
    SP2:as.integer(SEX) + SP3:as.integer(SEX) + as.integer(SEX):SP4 + 
    SP5:as.integer(SEX) + SP6:as.integer(SEX) - 1, design = shs.des, 
    family = "binomial")

Survey design:
update.survey.design(shs.des, SP1 = SP1, SP2 = SP2, SP3 = SP3, 
    SP4 = SP4, SP5 = SP5, SP6 = SP6, AGE = AGE)

Coefficients:
                         Estimate Std. Error t value
SP1                        0.9419     0.5929   1.589
SP2                        0.9405     0.4319   2.178
SP3                        0.7825     0.5191   1.507
SP5                       -0.3547     0.6350  -0.559
SP6                       -1.7107     0.6819  -2.509
as.integer(SEX)            0.4134     0.2383   1.735
SP4                       -0.5724     0.4965  -1.153
SHS_6CLAlarge urban       -0.3281     0.3794  -0.865
SHS_6CLAoth urban         -0.4373     0.3798  -1.152
SHS_6CLAaccessible towns  -0.2152     0.3824  -0.563
SHS_6CLAremote towns      -0.2587     0.3975  -0.651
SHS_6CLAaccessible rural  -0.1756     0.3826  -0.459
SHS_6CLAremote rural      -0.1175     0.3845  -0.306
SP1:as.integer(SEX)       -0.6059     0.3666  -1.653
SP2:as.integer(SEX)       -0.8730     0.2685  -3.251
SP3:as.integer(SEX)       -0.6574     0.3251  -2.022
as.integer(SEX):SP4       -0.8790     0.3167  -2.776
SP5:as.integer(SEX)       -1.9190     0.4153  -4.621
SP6:as.integer(SEX)       -1.9499     0.4731  -4.122
                         Pr(>|t|)    
SP1                       0.11212    
SP2                       0.02945 *  
SP3                       0.13171    
SP5                       0.57647    
SP6                       0.01212 *  
as.integer(SEX)           0.08284 .  
SP4                       0.24894    
SHS_6CLAlarge urban       0.38712    
SHS_6CLAoth urban         0.24948    
SHS_6CLAaccessible towns  0.57362    
SHS_6CLAremote towns      0.51509    
SHS_6CLAaccessible rural  0.64630    
SHS_6CLAremote rural      0.75991    
SP1:as.integer(SEX)       0.09839 .  
SP2:as.integer(SEX)       0.00115 ** 
SP3:as.integer(SEX)       0.04321 *  
as.integer(SEX):SP4       0.00551 ** 
SP5:as.integer(SEX)      3.84e-06 ***
SP6:as.integer(SEX)      3.77e-05 ***
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

(Dispersion parameter for binomial family taken to be 0.9942185)

Number of Fisher Scoring iterations: 7

> summary(update(fit,~.+EMP_STA))
Call:
svyglm.survey.design(formula = INTUSE ~ SP1 + SP2 + SP3 + SP5 + 
    SP6 + as.integer(SEX) + SP4 + EMP_STA + SP1:as.integer(SEX) + 
    SP2:as.integer(SEX) + SP3:as.integer(SEX) + as.integer(SEX):SP4 + 
    SP5:as.integer(SEX) + SP6:as.integer(SEX) - 1, design = shs.des, 
    family = "binomial")

Survey design:
update.survey.design(shs.des, SP1 = SP1, SP2 = SP2, SP3 = SP3, 
    SP4 = SP4, SP5 = SP5, SP6 = SP6, AGE = AGE)

Coefficients:
                                              Estimate
SP1                                            1.37213
SP2                                            1.53434
SP3                                            1.19930
SP5                                            0.70377
SP6                                           -0.76217
as.integer(SEX)                                0.45314
SP4                                            0.49352
EMP_STASelf employed                          -0.75431
EMP_STAEmployed full time                     -0.91465
EMP_STAEmployed part time                     -1.33168
EMP_STALooking after the home or family       -1.98307
EMP_STAPermanently retired from work          -1.32620
EMP_STAUnemployed and seeking work            -2.12990
EMP_STAAt school                               0.02851
EMP_STAIn further/higher education             0.06199
EMP_STAGov't work or training scheme          -1.73090
EMP_STAPermanently sick or disabled           -2.60353
EMP_STAUnable to work because  short-term ill -2.08311
EMP_STAOther                                  -1.31233
SP1:as.integer(SEX)                           -0.64187
SP2:as.integer(SEX)                           -0.60068
SP3:as.integer(SEX)                           -0.52699
as.integer(SEX):SP4                           -0.79712
SP5:as.integer(SEX)                           -2.07307
SP6:as.integer(SEX)                           -1.90606
                                              Std. Error
SP1                                              0.66236
SP2                                              0.47252
SP3                                              0.57164
SP5                                              0.69562
SP6                                              0.70271
as.integer(SEX)                                  0.26240
SP4                                              0.54218
EMP_STASelf employed                             0.43656
EMP_STAEmployed full time                        0.43188
EMP_STAEmployed part time                        0.43478
EMP_STALooking after the home or family          0.43602
EMP_STAPermanently retired from work             0.44424
EMP_STAUnemployed and seeking work               0.43651
EMP_STAAt school                                 0.43051
EMP_STAIn further/higher education               0.43056
EMP_STAGov't work or training scheme             0.62487
EMP_STAPermanently sick or disabled              0.44005
EMP_STAUnable to work because  short-term ill    0.46833
EMP_STAOther                                     0.47788
SP1:as.integer(SEX)                              0.40280
SP2:as.integer(SEX)                              0.28808
SP3:as.integer(SEX)                              0.35180
as.integer(SEX):SP4                              0.33772
SP5:as.integer(SEX)                              0.43702
SP6:as.integer(SEX)                              0.47133
                                              t value
SP1                                             2.072
SP2                                             3.247
SP3                                             2.098
SP5                                             1.012
SP6                                            -1.085
as.integer(SEX)                                 1.727
SP4                                             0.910
EMP_STASelf employed                           -1.728
EMP_STAEmployed full time                      -2.118
EMP_STAEmployed part time                      -3.063
EMP_STALooking after the home or family        -4.548
EMP_STAPermanently retired from work           -2.985
EMP_STAUnemployed and seeking work             -4.879
EMP_STAAt school                                0.066
EMP_STAIn further/higher education              0.144
EMP_STAGov't work or training scheme           -2.770
EMP_STAPermanently sick or disabled            -5.916
EMP_STAUnable to work because  short-term ill  -4.448
EMP_STAOther                                   -2.746
SP1:as.integer(SEX)                            -1.594
SP2:as.integer(SEX)                            -2.085
SP3:as.integer(SEX)                            -1.498
as.integer(SEX):SP4                            -2.360
SP5:as.integer(SEX)                            -4.744
SP6:as.integer(SEX)                            -4.044
                                              Pr(>|t|)    
SP1                                            0.03831 *  
SP2                                            0.00117 ** 
SP3                                            0.03591 *  
SP5                                            0.31168    
SP6                                            0.27810    
as.integer(SEX)                                0.08420 .  
SP4                                            0.36270    
EMP_STASelf employed                           0.08403 .  
EMP_STAEmployed full time                      0.03420 *  
EMP_STAEmployed part time                      0.00219 ** 
EMP_STALooking after the home or family       5.44e-06 ***
EMP_STAPermanently retired from work           0.00283 ** 
EMP_STAUnemployed and seeking work            1.07e-06 ***
EMP_STAAt school                               0.94720    
EMP_STAIn further/higher education             0.88552    
EMP_STAGov't work or training scheme           0.00561 ** 
EMP_STAPermanently sick or disabled           3.33e-09 ***
EMP_STAUnable to work because  short-term ill 8.70e-06 ***
EMP_STAOther                                   0.00603 ** 
SP1:as.integer(SEX)                            0.11106    
SP2:as.integer(SEX)                            0.03707 *  
SP3:as.integer(SEX)                            0.13415    
as.integer(SEX):SP4                            0.01827 *  
SP5:as.integer(SEX)                           2.11e-06 ***
SP6:as.integer(SEX)                           5.27e-05 ***
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

(Dispersion parameter for binomial family taken to be 0.9990887)

Number of Fisher Scoring iterations: 7

> fit1<-svyglm(INTUSE~COUNCIL,design=shs.des)
> fit2<-svyglm(INTUSE~COUNCIL+SP1+SP2+SP3+(as.integer(SEX)-1)+(as.integer(SEX)-1)*SP1+(as.integer(SEX)-1)*SP2+(as.integer(SEX)-1)*SP3, design=shs.des, family='binomial')
> fit3<-svyglm(INTUSE~COUNCIL+SP1+SP2+SP3+(as.integer(SEX)-1)+(as.integer(SEX)-1)*SP1+(as.integer(SEX)-1)*SP2+(as.integer(SEX)-1)*SP3+GROUPINC, design=shs.des, family='binomial')

# this next bit compares ranking of adjusted and unadjusted
#  coefficients. It seems that this large variation between local 
# authorities is not explained by age sex or household income

> comp<-cbind(rank(-c(0,fit1$coefficients[2:32])), 
+ rank(-fit2$coefficients[1:32]+fit2$coefficients[1]), 
+ rank(-fit3$coefficients[1:32]+fit3$coefficients[1]))
> dimnames(comp)[[1]][1]<-'Aberdeen City'
> dimnames(comp)[[2]]<-c('Unadjusted','Age sex','Age sex wealth')
> print(comp)
 
                           Unadjusted Age sex
Aberdeen City                       6       6
COUNCILAberdeenshire               10      11
COUNCILAngus                       12      12
COUNCILArgyll & Bute               18      13
COUNCILClackmannanshire            24      26
COUNCILDumfries & Galloway         31      28
COUNCILDundee City                 20      21
COUNCILEast Ayrshire               25      24
COUNCILEast Dunbartonshire          2       1
COUNCILEast Lothian                 8       8
COUNCILEast Renfrewshire            4       4
COUNCILEdinburgh, City of           3       3
COUNCILEilean Siar                 30      29
COUNCILFalkirk                     15      14
COUNCILFife                        16      16
COUNCILGlasgow City                29      31
COUNCILHighland                     7      10
COUNCILInverclyde                  26      22
COUNCILMidlothian                  14      19
COUNCILMoray                       23      25
COUNCILNorth Ayrshire              32      32
COUNCILNorth Lanarkshire           27      30
COUNCILOrkney Islands              22      20
COUNCILPerth & Kinross              9       7
COUNCILRenfrewshire                21      18
COUNCILScottish Borders            11       9
COUNCILShetland Islands             1       2
COUNCILSouth Ayrshire              17      15
COUNCILSouth Lanarkshire           19      23
COUNCILStirling                     5       5
COUNCILWest Dunbartonshire         28      27
COUNCILWest Lothian                13      17
                           Age sex wealth
Aberdeen City                           5
COUNCILAberdeenshire                   13
COUNCILAngus                           10
COUNCILArgyll & Bute                   12
COUNCILClackmannanshire                30
COUNCILDumfries & Galloway             26
COUNCILDundee City                     17
COUNCILEast Ayrshire                   25
COUNCILEast Dunbartonshire              3
COUNCILEast Lothian                    11
COUNCILEast Renfrewshire                9
COUNCILEdinburgh, City of               2
COUNCILEilean Siar                     27
COUNCILFalkirk                         14
COUNCILFife                            16
COUNCILGlasgow City                    24
COUNCILHighland                         6
COUNCILInverclyde                      19
COUNCILMidlothian                      29
COUNCILMoray                           21
COUNCILNorth Ayrshire                  32
COUNCILNorth Lanarkshire               31
COUNCILOrkney Islands                  18
COUNCILPerth & Kinross                  7
COUNCILRenfrewshire                    23
COUNCILScottish Borders                 8
COUNCILShetland Islands                 1
COUNCILSouth Ayrshire                  15
COUNCILSouth Lanarkshire               28
COUNCILStirling                         4
COUNCILWest Dunbartonshire             22
COUNCILWest Lothian                    20
>