I have a data object that lists constraints for my MCMC (from library(MCMCpack) ) command:
constraints <- structure(list(state = c("CA", "CA", "CA", "CA"), justice = c("smith",
"lee", "bosworth", "dickens"), direction = c("-", "-", "+", "+"
)), class = "data.frame", row.names = c(NA, -4L))
I create a function for my constraints:
constraints_list <- paste(constraints$justice, "='", constraints$direction, "'", sep = "", collapse = ", ")
I then have a different dataset that I'm using to run the MCMC on:
sheet<-structure(list(hall = c(1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L), nolan = c(0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L,
1L, 1L, 1L, 0L, 0L), perez = c(1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 1L, 1L, 1L, 1L, 1L), chen = c(0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L), bush = c(1L, 1L, 1L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), simpson = c(0L, 1L, 0L, 1L,
0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), smith = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), lee = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), bosworth = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), dickens = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), time = c(1L,
1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L), term = c(2020L,
2020L, 2021L, 2021L, 2022L, 2022L, 2023L, 2023L, 2024L, 2024L,
2025L, 2025L, 2026L, 2026L), observation = 1:14), class = "data.frame", row.names = c(NA,
-14L))
And when I run this, I get an error:
result <- MCMCdynamicIRT1d(t(sheet[,1:10]),
item.time.map=sheet$time,
theta.start=NA,
mcmc=2500, burnin=250, thin=100,
verbose=1, tau2.start=rep(0.1, 23),
e0=0, E0=1,
a0=0, A0=1,
b0=0, B0=1, c0=-1, d0=-1,
store.item=FALSE,
theta.constraints=list(constraints_list))
This is the error:
Error in lambda.constraints[[i]] :
attempt to select less than one element in integerOneIndex
When I look at the constraints_list I just see this:
[1] "smith='-', lee='-', bosworth='+', dickens='+'"
So when I manually plug the list into the MCMCdynamicIRT1d command, the code works as expected:
result <- MCMCdynamicIRT1d(t(sheet[,1:10]),
item.time.map=sheet$time,
theta.start=NA,
mcmc=2500, burnin=250, thin=100,
verbose=1, tau2.start=rep(0.1, 23),
e0=0, E0=1,
a0=0, A0=1,
b0=0, B0=1, c0=-1, d0=-1,
store.item=FALSE,
theta.constraints=list(smith='-', lee='-', bosworth='+', dickens='+'))
How do I fix constraints_list so it will output the results as expected?