# HTML version or R output exemplar 1 # To view comments on what these commands are # doing go to the commented coded file to R code red stuff (R commands)R output is in blue ######### ANY TEXT AFTER THE # CHARACTER (here shown black) # ARE TREATED AS COMMENTS BY R Links in this page Mean income with different design assumptions Raking to match Scottish totals Jacknife estimation for mean Subgroup lone parents Percentiles back to top > frs.des <- svydesign(id=~PSU, weights=~GROSS2,data=frs) > summary(frs.des) 1 - level Cluster Sampling design With (320) clusters. svydesign(id = ~PSU, weights = ~GROSS2, data = frs) Probabilities: Min. 1st Qu. Median Mean 3rd Qu. 0.0001369 0.0019080 0.0022420 0.0022720 0.0026040 Max. 0.0049750 Data variables: [1] "SERNUM" "CTBAND" "ADULTH" "DEPCHLDH" "GROSS2" [6] "HHINC" "PSU" "TENURE" > svymean(~HHINC,design=frs.des,deff=T) mean SE DEff HHINC 483.091 10.639 2.9066 > frs.des <- svydesign(id=~SERNUM, weights=~GROSS2,data=frs) > svymean(~HHINC,design=frs.des,deff=T) mean SE DEff HHINC 483.0913 7.8775 1.5934 back to top > tab.ctband <- xtabs(GROSS2~CTBAND,data=frs) > tab.ctband[1:9]<-c( 24.83 ,24.62, 15.45 ,11.91 ,11.96 ,5.95 ,3.94 ,0.45 ,0.89)*sum(frs$GROSS2)/100 > unclass(tab.ctband) CTBAND 1 2 3 4 5 6 7 8 515672 547548 351599 291425 266257 147851 87767 9190 9 19670 attr(,"call") xtabs(formula = GROSS2 ~ CTBAND, data = frs) > > tab.tenure <- xtabs(GROSS2~TENURE,data=frs) > tab.tenure[1:4]<-c( 62.63 , 21.59, 5.58 , 10.20)*sum(frs$GROSS2)/100 > unclass(tab.ctband) CTBAND 1 2 3 4 5 6 7 8 515672 547548 351599 291425 266257 147851 87767 9190 9 19670 attr(,"call") xtabs(formula = GROSS2 ~ CTBAND, data = frs) > frs.des <- svydesign(id=~PSU, weights=~GROSS2,data=frs) > frs.des <- as.svrepdesign(frs.des) > frs.des<-rake(frs.des,list(~CTBAND,~TENURE),list(tab.ctband,tab.tenure)) > svymean(~HHINC,design=frs.des,deff=T) mean SE DEff HHINC 479.58 7.46 1.4352 > back to top > svymean(~HHINC,design=frs.des,deff=T) mean SE DEff HHINC 479.58 7.46 1.4352 back to top my.svrepquantile(~HHINC,design=frs.des,quantile=c(0.05,0.1,.25,.5,.75,.9,.95)) quantiles Quantile se l.limit u.limit [1,] 0.05 100.0000 3.073927 92.0000 106.9191 [2,] 0.10 129.0000 3.500000 121.0000 135.0000 [3,] 0.25 200.0000 4.000000 192.7797 208.0000 [4,] 0.50 350.0000 7.000000 338.0000 365.0000 [5,] 0.75 618.0000 11.791250 596.0000 636.0000 [6,] 0.90 981.2433 23.531862 930.0000 1019.7699 [7,] 0.95 1275.0000 32.899771 1204.0000 1337.8400 back to top > xtabs(~ADULTH+DEPCHLDH,data=frs) DEPCHLDH ADULTH 0 1 2 3 4 5 6 7 1 1524 172 118 33 8 1 1 1 2 1472 348 419 131 15 8 4 1 3 235 78 23 5 2 2 0 0 4 62 13 5 3 1 1 0 0 5 6 2 0 0 0 0 0 0 6 1 0 0 0 0 0 0 0 > frs$LONEP<-0 > frs$LONEP[frs$ADULTH==1 & frs$DEPCHLDH>0]<-1 > xtabs(~LONEP+DEPCHLDH,data=frs) DEPCHLDH LONEP 0 1 2 3 4 5 6 7 0 3300 441 447 139 18 11 4 1 1 0 172 118 33 8 1 1 1 > sum(frs$LONEP) [1] 334 > frs.des <- svydesign(id=~PSU, weights=~GROSS2,data=frs) > frs.des.lonep<-subset.survey.design(frs.des,LONEP==1) > svymean(~HHINC,frs.des.lonep,deff=T) mean SE DEff HHINC 276.5555 8.4954 1.0101 > frs.des <- svydesign(id=~PSU, weights=~GROSS2,data=frs) > frs.des <- as.svrepdesign(frs.des) > frs.des<-rake(frs.des,list(~CTBAND,~TENURE),list(tab.ctband,tab.tenure)) > frs.des.lonep<-subset.survey.design(frs.des,LONEP==1) > svymean(~HHINC,frs.des.lonep,deff=T) mean SE DEff HHINC 274.4804 8.1958 0.9732 >