# SECTION 4.1 library(BiasedUrn) # Table 2.8 data: income<-c("<15000","15000-25000","25000-40000",">40000") jobsat<-c("VD","LD","MS","VS") data<-c(1,2,1,0,3,3,6,1,10,10,14,9,6,7,12,11) (table.2.8<-cbind(expand.grid(income=income,jobsat=jobsat),count=data) ) (temp<-tapply(table.2.8$count,table.2.8[,1:2], sum) ) # A function written by Laura Thompson to compute GAMMA Gamma2.f<-function(x, pr=0.95) { # x is a matrix of counts. You can use output of crosstabs or xtabs in R. # A matrix of counts can be formed from a data frame by using design.table. # Confidence interval calculation and output from Greg Rodd # Check for using S-PLUS and output is from crosstabs (needs >= S-PLUS 6.0) n <- nrow(x) m <- ncol(x) pi.c<-pi.d<-matrix(0,nr=n,nc=m) row.x<-row(x) col.x<-col(x) for(i in 1:(n)) for(j in 1:(m)) { pi.c[i, j]<-sum(x[row.xi & col.x>j]) pi.d[i, j]<-sum(x[row.xj]) + sum(x[row.x>i & col.x