CDOoDocuments.StdDocumentDescDocuments.DocumentDescContainers.ViewDescViews.ViewDescStores.StoreDesc+Documents.ModelDescContainers.ModelDescModels.ModelDescStores.ElemDescy qTextViews.StdViewDescTextViews.ViewDescTextModels.StdModelDescTextModels.ModelDesc%TextModels.AttributesDesc'* *vk # # chapter 9 - example 8 waterpolo # Poisson loglinear for Water polo data # model 3 - game random effects (correlation) model{ for (i in 1:n){ g[i,1] <- G1[i] g[i,2] <- G2[i] g[i,1]~dpois( lambda[i,1] ) g[i,2]~dpois( lambda[i,2] ) log( lambda[i,1] ) <- mu + att[ team1[i] ] + def[ team2[i] ] + b[i] log( lambda[i,2] ) <- mu + att[ team2[i] ] + def[ team1[i] ] + b[i] res2[i,1] <- pow( g[i,1] - lambda[i,1], 2) res2[i,2] <- pow( g[i,2] - lambda[i,2], 2) b[i] ~ dnorm( 0, tau) } mu~dnorm( 0, 0.001) att[1] <- -sum(att[2:teams]) def[1] <- -sum(def[2:teams]) for (k in 2:teams){ att[k]~dnorm( 0, 0.001) def[k]~dnorm( 0, 0.001) } tau~dgamma( 0.001, 0.001) ss.res <- sum(res2[1:n,1:2]) ss.y <- pow( sd(g[1:n,1:2]), 2)*(2*n-1) R2pois <- 1 - ss.res/ss.y for(i in 1:n){ game[i]~dnorm(0,1) phase[i]~dnorm(0,1) } es <- exp( 1/tau ) omega <- 1/( (es-1)*sqrt(es) ) for (i in 1:n){ m[i,1] <- exp( mu + att[ team1[i] ] + def[ team2[i] ] ) m[i,2] <- exp( mu + att[ team2[i] ] + def[ team1[i] ] ) DI[i,1] <- 1 + m[i,1]* (es-1)*sqrt(es) DI[i,2] <- 1 + m[i,2]* (es-1)*sqrt(es) cor[i] <- 1/sqrt( (1+omega/m[i,1])*(1+omega/m[i,2]) ) } m.mean <- mean( m[1:n,1:2] ) di.stats[1] <- ranked( DI[1:n,1:2], 1 ) di.stats[2] <- ranked( DI[1:n,1:2], 30 ) di.stats[3] <- mean( DI[1:n,1:2] ) di.stats[5] <- 0.5*( ranked( DI[1:n,1:2], 60 )+ranked( DI[1:n,1:2], 61 ) ) di.stats[6] <- 1 + m.mean* (es-1)*sqrt(es) di.stats[7] <- ranked( DI[1:n,1:2], 90 ) di.stats[8] <- ranked( DI[1:n,1:2], 120 ) cor.stats[1] <- ranked( cor[1:n], 1 ) cor.stats[2] <- ranked( cor[1:n], 15 ) cor.stats[3] <- mean( cor[1:n] ) cor.stats[5] <- 0.5*( ranked( cor[1:n], 30 )+ranked( cor[1:n], 31 ) ) cor.stats[6] <- 1/sqrt( (1+omega/m.mean)*(1+omega/m.mean) ) cor.stats[7] <- ranked( cor[1:n], 45 ) cor.stats[8] <- ranked( cor[1:n], n ) } INITS list(mu=0.0, att=c(NA, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), def=c(NA, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) , tau=1) DATA list( n=60, teams=16, G1 = c(6, 9, 9, 8, 6, 10, 7, 7, 6, 8, 3, 1, 10, 9, 8, 4, 13, 5, 14, 5, 5, 7, 5, 4, 6, 13, 13, 7, 8, 4, 4, 3, 5, 12, 8, 5, 7, 6, 7, 8, 10, 10, 2, 5, 16, 5, 3, 8, 6, 5, 12, 9, 2, 9, 12, 3, 9, 5, 6, 4), G2 = c(7, 8, 10, 2, 1, 4, 3, 1, 3, 6, 3, 12, 11, 7, 5, 6, 5, 4, 6, 11, 6, 14, 6, 6, 6, 6, 3, 4, 9, 10, 3, 12, 5, 9, 7, 10, 10, 5, 8, 7, 6, 3, 4, 11, 6, 6, 2, 9, 7, 9, 11, 7, 4, 8, 6, 8, 10, 8, 7, 2), team1 = c(14, 6, 15, 4, 9, 12, 8, 5, 15, 4, 16, 10, 7, 13, 14, 6, 16, 7, 13, 14, 10, 6, 15, 4, 6, 2, 9, 13, 14, 15, 16, 12, 2, 3, 16, 12, 14, 15, 9, 13, 6, 2, 14, 15, 16, 12, 9, 13, 14, 11, 7, 8, 9, 16, 14, 1, 4, 7, 9, 5), team2 = c(16, 7, 13, 10, 2, 3, 11, 1, 3, 1, 9, 5, 8, 12, 2, 11, 2, 11, 3, 9, 1, 8, 12, 5, 3, 10, 11, 1, 8, 5, 7, 4, 6, 10, 8, 5, 11, 1, 7, 4, 10, 3, 7, 4, 11, 1, 8, 5, 1, 12, 4, 15, 5, 13, 11, 12, 15, 8, 13, 16), game = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60), phase = c(1, 2, 3, 4, 1, 3, 2, 4, 3, 4, 1, 4, 2, 3, 1, 2, 1, 2, 3, 1, 4, 2, 3, 4, 7, 7, 5, 6, 5, 6, 5, 6, 7, 7, 5, 6, 5, 6, 5, 6, 7, 7, 5, 6, 5, 6, 5, 6, 14, 14, 11, 11, 8, 8, 16, 15, 13, 12, 10, 9) ) WATER POLO WORL CUP 2000 DATA - CAPTION team1/team2 [1,] "AUS" [2,] "BRA" [3,] "CAN" [4,] "CRO" [5,] "ESP" [6,] "GER" [7,] "GRE" [8,] "HUN" [9,] "ITA" [10,] "JPN" [11,] "KAZ" [12,] "NED" [13,] "RUS" [14,] "SVK" [15,] "USA" [16,] "YUG" phase [1,] "Group A" [2,] "Group B" [3,] "Group C" [4,] "Group D" [5,] "Group E (Places 13-16)" [6,] "Group F" [7,] "Group G" [8,] "SF (1-4)" [9,] "FINAL" [10,] "POS3-4" [11,] "SF (5-8)" [12,] "POS5-6" [13,] "POS7-8" [14,] "SF (9-12)" [15,] "POS9-10" [16,] "POS11-12" TextControllers.StdCtrlDescTextControllers.ControllerDescContainers.ControllerDescControllers.ControllerDesc TextRulers.StdRulerDescTextRulers.RulerDescTextRulers.StdStyleDescTextRulers.StyleDescZTextRulers.AttributesDesc$ Zo * ,[ @Documents.ControllerDesc Ws,! [h$