I have this for loop for creating a list of variables:
vars <- c( 'beta.o', 'sd.y')
for (x in c('ghs', 'site', 'trt')) {
if(model.parms[[x]] == 1) {
data <- data[, which(names(data) != x)]
} else {
data <- data
if(x!='ghs') {
vars <- c(vars, paste('sd.', x, sep = ''))
}
m <- min(model.parms[[x]], 5)
for (i in 1:m) {
if(i == 1 && x == 'site') {
vars <- c(vars, 'beta.site[1]')
}
if (i > 1) {
vars <- c(vars, paste('beta.', x, '[', i, ']', sep=''))
}
}
}
}
It has been bothering me terribly, and I have failed the last two times I have tried to replace it, although conceptually it should be able to be written in a few lines. Any advice?