jags - Cannot insert node into ...[]. Dimension mismatch -
i'm trying replicate simulations piece of jags code mark ballot, jags sending me error message..
if understood correctly, should have problem indexing house effects each party somewhere, i'm unable find because node seems indexed. have idea error like?
model <- jags.model(textconnection(model), data = data, n.chains=4, n.adapt=10000 compiling model graph resolving undeclared variables allocating nodes deleting model error in jags.model(textconnection(model2), data = data, n.chains = 4, : runtime error: cannot insert node houseeffect[1...4,2]. dimension mismatch
for replication
model <- ' model { for(poll in 1:numpolls) { adjusted_poll[poll, 1:parties] <- walk[pollday[poll], 1:parties] + houseeffect[house[poll], 1:parties] primaryvotes[poll, 1:parties] ~ dmulti(adjusted_poll[poll, 1:parties], n[poll]) } tightness <- 50000 discontinuity_tightness <- 50 for(day in 2:(discontinuity-1)) { multinomial[day, 1:parties] <- walk[day-1, 1:parties] * tightness walk[day, 1:parties] ~ ddirch(multinomial[day, 1:parties]) } multinomial[discontinuity, 1:parties] <- walk[discontinuity-1, 1:parties] * discontinuity_tightness walk[discontinuity, 1:parties] ~ ddirch(multinomial[discontinuity, 1:parties]) for(day in discontinuity+1:period) { multinomial[day, 1:parties] <- walk[day-1, 1:parties] * tightness walk[day, 1:parties] ~ ddirch(multinomial[day, 1:parties]) } (party in 1:2) { alpha[party] ~ dunif(250, 600) } (party in 3:parties) { alpha[party] ~ dunif(10, 250) } walk[1, 1:parties] ~ ddirch(alpha[]) for(day in 1:period) { coalitiontpp[day] <- sum(walk[day, 1:parties] * preference_flows[1:parties]) } (party in 2:parties) { houseeffect[1, party] <- -sum( houseeffect[2:housecount, party] ) } for(house in 1:housecount) { houseeffect[house, 1] <- -sum( houseeffect[house, 2:parties] ) } # note, not apply double constraint houseeffect[1, 1] monitorhouseeffectonesumparties <- sum(houseeffect[1, 1:parties]) monitorhouseeffectonesumhouses <- sum(houseeffect[1:housecount, 1]) (party in 2:parties) { for(house in 2:housecount) { houseeffect[house, party] ~ dnorm(0, pow(0.1, -2)) } } } ' preference_flows <- c(1.0, 0.0, 0.1697, 0.533) period = 26 housecount = 5 numpolls = 35 parties = 4 discontinuity = 20 pollday = c(1, 1, 2, 2, 6, 8, 8, 9, 9, 10, 10, 10, 10, 12, 12, 13, 14, 14, 16, 16, 17, 18, 19, 19, 20, 21, 22, 22, 24, 24, 24, 24, 24, 26, 26) house = c(1, 2, 3, 4, 3, 3, 5, 1, 2, 1, 3, 4, 5, 3, 4, 2, 3, 4, 3, 4, 5, 3, 2, 4, 3, 5, 3, 4, 1, 2, 3, 4, 5, 3, 4) n = c(1400, 1400, 1000, 1155, 1000, 1000, 3690, 1400, 1400, 1400, 1000, 1177, 3499, 1000, 1180, 1400, 1000, 1161, 1000, 1148, 2419, 1000, 1386, 1148, 1000, 2532, 1000, 1172, 1682, 1402, 1000, 1160, 3183, 1000, 1169) preference_flows = c(1.0000, 0.0000, 0.1697, 0.5330) primaryvotes = read.csv(text = c( 'coalition, labor, greens, other 532,574,154,140 560,518,168,154 350,410,115,125 439,450,139,127 385,385,95,135 375,395,120,110 1465,1483,417,325 504,602,154,140 532,560,154,154 504,602,154,140 355,415,120,110 412,483,141,141 1345,1450,392,312 375,405,100,120 448,448,142,142 588,504,168,140 390,380,115,115 441,453,139,128 380,400,110,110 471,425,126,126 957,979,278,205 405,360,125,110 546,532,182,126 471,413,126,138 385,380,120,115 1008,995,301,228 400,375,115,110 457,410,141,164 690,656,185,151 603,491,182,126 415,355,125,105 464,429,139,128 1307,1218,385,273 410,370,130,90 479,433,152,105'), sep=",") data = list(period = period, housecount = housecount, numpolls = numpolls, parties = parties, primaryvotes = primaryvotes, pollday = pollday, house = house, discontinuity = discontinuity, # manage rounding issues df$sample ... n = rowsums(primaryvotes), preference_flows = preference_flows ) print(data)
the problem passing house model parameter, , using house variable in loop. jags 4.0.1 confused. if re-code replace "house" in loop (say) "h" should work ... example follows ...
for (h in 2:housecount) { (p in 2:parties) { # vague priors ... houseeffect[h, p] ~ dnorm(0, pow(0.1, -2)) } } (p in 2:parties) { houseeffect[1, p] <- -sum( houseeffect[2:housecount, p] ) } for(h in 1:housecount) { houseeffect[h, 1] <- -sum( houseeffect[h, 2:parties] ) }
Comments
Post a Comment