philchalmers / mirt

Multidimensional item response theory
https://philchalmers.github.io/mirt/
199 stars 75 forks source link

createItem lbound condition on pars #167

Closed wjakethompson closed 4 years ago

wjakethompson commented 4 years ago

When creating a new item type with createItem(), is there a way to specify dynamic lower bounds on parameters?

Take the following example:

p_func <- function(par, Theta, ncat) {
  z <- as.vector(Theta %*% par)
  p <- plogis(z)
  cbind(1 - p, p)
}

new_par <- c(0, 1, 1, 0, 0.5, 0, 0)
names(new_par) <- c("a1", "a2", "a3", "a4", "a5", "a6", "a7")
new_par
#>  a1  a2  a3  a4  a5  a6  a7 
#> 0.0 1.0 1.0 0.0 0.5 0.0 0.0

new_est <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)

new_lbound <- c(-Inf, 0, 0, -Inf, -1 * min(new_par["a2"], new_par["a3"]), -Inf, -Inf)
new_lbound
#> [1] -Inf    0    0 -Inf   -1 -Inf -Inf

mirt::createItem("testItem",
                 par = new_par,
                 est = new_est,
                 P = p_func,
                 lbound = new_lbound)
#> Custom item object named: testItem

Created on 2019-09-21 by the reprex package (v0.3.0)

The lower bound of parameter a5 should be -1 * min(a2, a3). With the specification in the example above, the lower bound is set to -1 times the minimum of the starting values of a2 and a3. But the lower bound should actually be dynamic, based on what the actual values of a2 and a3 are, not just the starting values.

Is there a way to specify this type of lower bound? Or is there a work around that can be implemented in p_func()?

philchalmers commented 4 years ago

I don't think I've ever seen a dynamic lower bound implemented in R. If you have access to some code that uses one of R's optimizers to do so (e.g., optim(), nlminb(), etc) then I might be able to add something like this to the package. But, for these types of problems it no doubt makes more sense to reparameterize the model instead if possible.

philchalmers commented 4 years ago

Any luck tracking down an example of this type of dynamic bound in R? My superficial search hasn't revealed much. If not, I may close this issue until a suitable approach is found.

wjakethompson commented 4 years ago

I haven't had any luck yet, so I'm going to close the issue. If I am able to track something down, I'll re-open with the example. Thanks!