[R] [multi-level model] set up categorical variable/indicator?

Huan-Kai Tseng
Sat, 14 Mar 2009 22:39:46 -0000

Hi everyone,

I'm working on a multi-level model based on one of the "radon"
example from
Gelman & Hill's book (
http://www.amazon.com/Analysis-Regression-Multilevel-Hierarchical-Models/dp/052168689X/ref=pd_bbs_1?ie=UTF8&s=books&qid=1237069199&sr=8-1
).

I add an "region" indicator (has numeric values from 1 to 5) as the
varying
intercept in my model (I use "county" data in Minnesota [MN] as my
county-level indicator and interact it with "basement"(bsmt)) and
write my
model in Winbugs as:

model{
for (i in 1:n){
y[i] ~ dnorm(y.hat[i], tau.y)
y.hat[i] <- alpha[region[i]] + beta[county[i]]*bsmt[i]
}
for (j in 1:J){
alpha[j] ~ dnorm(mu.alpha[j], tau.alpha)
}
for (k in 1:K){
beta[k] ~ dnorm(mu.beta[k], tau.beta)
}
mu.y ~ dnorm(0, .0001)
tau.y <- pow(sigma.y, -2)
sigma.y ~ dunif(0, 100)
mu.alpha ~ dnorm(0, .0001)
mu.beta ~ dnorm(0, .0001)
tau.alpha <- pow(sigma.alpha, -2)
sigma.alpha ~ dunif (0, 100)
tau.beta <- pow(sigma.beta, -2)
sigma.beta ~ dunif(0, 100)
}

but my Bugs crashed because it couldn't read "region" data, and as
I checked
out my "region" data in R, it has 919 observations (which means that I
didn't define the vector of "region" properly, if I did it right,
it should
be [1] 5, and J <- 5), does anyone know how to specify this kind of
categorical indicator? (particularly if it has numeric values, which makes
"as.vector" function inappropriate here) and how do I transform it
into the
kind of distributional form I want (in this example, J = 5)?
also, most importantly, are there any useful websits that have definition
for these R and Bugs syntax and their applications? (I hate those textbooks
that always assume their readers as veterans in a particular statistical
package...)

Thanks.


Sincerely,
H K. Tseng

--
Ph.D. student
Department of Political Science
The George Washington University

	[[alternative HTML version deleted]]