r - Three-level multilevel model specification problem with R2WinBUGS -


i'm trying apply method used gelman & hill (2007: p348) on radon data set, own data. it's multilevel model problem whereby need specify 3 levels - repeated broadband speed measurements (level 1) nested within local authorities (level 2) (j), nested within regions (level 3) (k). dependent variable broadband speed (y) , independent variable population density (x).

although model apparently syntactically correct, winbugs keeps saying have undefined variable, i'm not sure code mis- specified. i'm not confident nesting correct, , specification of both inits , parameters in r code. know lot of people have moved onto using rstan, still feel need learn basic winbugs before move towards it.

any appreciated. here's reproducible example:

###winbugs model model {  #level 1 (i in 1:n){ y[i] ~ dnorm (y.hat[i], tau.y) y.hat[i] <- a[laid[i]] + b*x[i]}  b ~ dnorm (0, .0001) tau.y <- pow(sigma.y, -2) sigma.y ~ dunif (0, 100)  #level 2 (j in 1:j){ a[j] ~ dnorm (mu.a, tau.a)}  mu.a ~ dnorm (0, .0001) tau.a <- pow(sigma.a, -2) sigma.a ~ dunif (0, 100)  #level 3 (k in 1:k){ a[k] ~ dnorm (mu.b, tau.b)}  mu.b ~ dnorm (0, .0001) tau.b <- pow(sigma.b, -2) sigma.b ~ dunif (0, 100) } 

and here's r code , data:

require(r2winbugs)  n<- 344   j <- 86  k <- 13  laid <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,           6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,           11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,           16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,           21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,           26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,           31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,           36,36,36,36,37,37,37,37,38,38,38,38,39,39,39,39,40,40,40,40,           41,41,41,41,42,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,           46,46,46,46,47,47,47,47,48,48,48,48,49,49,49,49,50,50,50,50,           51,51,51,51,52,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,           56,56,56,56,57,57,57,57,58,58,58,58,59,59,59,59,60,60,60,60,           61,61,61,61,62,62,62,62,63,63,63,63,64,64,64,64,65,65,65,65,           66,66,66,66,67,67,67,67,68,68,68,68,69,69,69,69,70,70,70,70,           71,71,71,71,72,72,72,72,73,73,73,73,74,74,74,74,75,75,75,75,           76,76,76,76,77,77,77,77,78,78,78,78,79,79,79,79,80,80,80,80,           81,81,81,81,82,82,82,82,83,83,83,83,84,84,84,84,85,85,85,85,           86,86,86,86)  rnid <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,           2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,           3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,           4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,           4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,           5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,           6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,           7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,           8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,           9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,           10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,           11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,           11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,           12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,           13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,           13,13,13,13)       x <- c(7.59,7.6,7.6,7.6,7.53,7.53,7.54,7.54,8.38,8.39,         8.4,8.41,7.37,7.37,7.38,7.38,7.2,7.2,7.2,7.21,         7.79,7.8,7.81,7.82,7.72,7.72,7.72,7.73,7.66,7.67,         7.67,7.67,7.67,7.68,7.68,7.69,7.43,7.43,7.44,7.44,         7.43,7.43,7.43,7.43,8.33,8.34,8.35,8.35,7.16,7.16,         7.16,7.17,7.49,7.49,7.49,7.49,7.62,7.62,7.62,7.62,         6.56,6.57,6.57,6.58,6.28,6.28,6.28,6.28,6.8,6.8,         6.81,6.81,7.31,7.32,7.33,7.33,7.25,7.25,7.25,7.25,         7.81,7.82,7.83,7.85,7.8,7.8,7.81,7.81,7.74,7.74,         7.74,7.74,7.6,7.6,7.61,7.61,8.3,8.31,8.31,8.32,         8.08,8.09,8.12,8.14,8.07,8.07,8.07,8.08,8.19,8.2,         8.21,8.22,7.06,7.06,7.07,7.07,7.86,7.87,7.87,7.88,         8.19,8.19,8.2,8.2,7.26,7.27,7.27,7.27,6.33,6.34,         6.34,6.35,6.94,6.95,6.95,6.96,7.22,7.23,7.23,7.24,         6.87,6.87,6.88,6.89,6.89,6.89,6.9,6.9,7.85,7.85,         7.85,7.86,6.31,6.31,6.31,6.31,6.84,6.84,6.85,6.85,         6.28,6.28,6.28,6.28,5.44,5.44,5.44,5.45,4.14,4.14,         4.14,4.14,5.76,5.77,5.77,5.77,7.37,7.37,7.37,7.38,         7.02,7.03,7.04,7.04,5.88,5.89,5.89,5.89,6.98,6.98,         6.98,6.98,8.31,8.31,8.31,8.3,8.19,8.19,8.19,8.19,         4.94,4.94,4.94,4.94,6.72,6.72,6.72,6.72,5.29,5.29,         5.3,5.3,6.59,6.6,6.61,6.62,8.07,8.07,8.08,8.08,         8.41,8.42,8.42,8.44,4.56,4.54,4.56,4.57,8.31,8.33,         8.33,8.35,4.43,4.44,4.45,4.45,6.35,6.36,6.36,6.37,         4.56,4.57,4.57,4.57,7.89,7.89,7.89,7.9,6.21,6.23,         6.24,6.25,8.27,8.28,8.29,8.3,6.3,6.3,6.31,6.32,         6.27,6.28,6.29,6.3,5.01,5.02,5.03,5.03,4.9,4.94,         4.94,4.94,8.08,8.08,8.09,8.09,7.64,7.65,7.65,7.66,         8.29,8.3,8.31,8.33,7.73,7.74,7.74,7.75,6.81,6.83,         6.84,6.84,4.98,4.99,4.99,5,6.29,6.3,6.31,6.32,         8.45,8.46,8.47,8.49,5.8,5.81,5.83,5.84,5.88,5.9,         5.91,5.93,8.34,8.34,8.34,8.36,6.88,6.88,6.89,6.91,         7.22,7.23,7.24,7.26,8.56,8.57,8.58,8.6,6.95,6.96,         6.97,6.98,5.39,5.39,5.4,5.4,8.25,8.27,8.28,8.29,         8.37,8.38,8.39,8.4)  y <- c(2.1,2.77,2.95,3.3,1.96,2.57,2.82,3.12,2.1,2.56,            2.88,3.18,1.95,2.72,2.96,3.31,1.93,2.39,2.83,3.2,            2.21,2.83,3.03,3.35,2.17,2.82,3.1,3.44,2.04,2.54,            2.83,3.15,2.14,2.68,3.07,3.36,2.15,2.63,3.03,3.36,            2.05,2.49,2.91,3.28,2.25,2.67,2.96,3.33,2.08,2.56,            2.99,3.31,2.17,2.61,2.83,3.29,2.12,2.54,2.8,3.15,            1.93,2.53,2.71,3.03,1.97,2.53,2.72,3.07,1.97,2.42,            2.63,2.98,1.97,2.53,2.73,3.04,2.17,2.57,2.97,3.23,            2.17,2.69,2.93,3.23,2.09,2.71,2.92,3.25,2.1,2.58,            3.03,3.4,1.93,2.39,2.89,3.22,2.19,2.71,3.03,3.36,            2.12,2.5,2.9,3.23,2.14,2.6,3.03,3.36,2.16,2.61,            2.91,3.2,2.12,2.83,3.09,3.41,2.1,2.6,2.96,3.27,            2.21,2.95,3.1,3.47,2.12,2.59,2.95,3.25,1.92,2.5,            2.64,2.97,1.95,2.45,2.79,3.12,2.07,2.54,2.91,3.23,            1.92,2.42,2.66,2.99,2.07,2.93,3.14,3.48,2.2,2.92,            3.15,3.44,2.15,2.87,3.1,3.42,2.12,2.74,3.14,3.46,            2.05,2.57,3.03,3.38,1.84,2.24,2.47,2.75,1.84,2.12,            2.35,2.67,1.9,2.5,2.76,3.05,2,2.42,2.87,3.24,            2.01,2.51,2.91,3.26,1.9,2.37,2.62,2.92,1.99,2.53,            2.69,3.06,2.25,2.8,2.9,3.26,1.99,2.22,2.34,2.65,            2.07,2.35,2.45,2.65,2.21,3.11,3.21,3.55,1.89,2.56,            2.74,3.1,1.96,2.4,2.76,3.1,2.13,2.67,3.11,3.4,            2.17,2.65,3.07,3.39,1.76,2.08,2.1,3.01,2.21,2.71,            3.15,3.45,1.61,1.86,2.21,2.54,2.12,2.65,3.03,3.34,            1.76,2.1,2.3,2.63,2.03,2.48,2.88,3.26,1.97,2.53,            2.78,3.07,2.29,2.77,3.2,3.52,1.95,2.38,2.58,2.88,            2.08,2.59,3.03,3.37,1.87,2.33,2.59,2.91,1.5,1.53,            1.48,1.59,2.16,2.67,3.11,3.46,2.15,2.45,2.69,3.05,            2.2,2.63,3.06,3.4,2.08,2.53,2.99,3.38,2.03,2.65,            3.04,3.32,1.92,2.47,2.66,2.94,1.97,2.56,3.01,3.31,            2.09,2.72,3.19,3.48,1.96,2.65,2.97,3.26,2.01,2.62,            2.97,3.25,2.23,2.87,3.11,3.4,2.08,2.77,3.06,3.35,            2.1,2.87,3.12,3.46,2.17,2.69,3.02,3.3,1.81,2.42,            2.94,3.36,1.93,2.48,2.77,3.04,2.19,2.76,3.09,3.42,            1.86,2.67,2.98,3.26)  speed.data <- list ("n", "j", "k", "y", "laid", "rnid", "x") speed.inits <- function (){ list (a=rnorm(j), b=rnorm(1), mu.a=rnorm(1), mu.b=rnorm(1),     sigma.y=runif(1), sigma.a=runif(1), sigma.b=runif(1))} speed.parameters <- c ("a", "b", "mu.a", "mu.b", "sigma.y", "sigma.a", "sigma.b")  speed.1 <- bugs (speed.data, speed.inits, speed.parameters,              "speed.1.txt", n.chains=3, n.iter=10, debug=true) 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -