drizopoulos / ltm

Latent Trait Models under IRT
30 stars 12 forks source link

unidimTest #5

Closed GiulioCostantini closed 6 years ago

GiulioCostantini commented 6 years ago

dear Dr. Rizopoulos, I am experiencing an issue with function unidimTest, which I could reproduce with simulated data

set.seed(1)
dt <- sim.irt(nvar = 78, n = 153)$items
fit <- rasch(dt)
udt <- unidimTest(fit)

I get the following error

Error in eigen(rho., symmetric = TRUE, only.values = TRUE) : infinite or missing values in 'x'

And the following three warnings, repeated many times each

In optimise(f, interval = c(-maxcor, maxcor)) : NA/Inf replaced by maximum positive value

In log(P) : NaNs produced

In polychor(data[, r[1]], data[, r[2]], ...) : the table has fewer than 2 rows

Thank you for your help, Giulio

GiulioCostantini commented 6 years ago

Dear Dr. Rizopoulos, I think that I found a solution: The problem arises when one column has zero variance in the simulated datasets. Function unidimTest works by replacing this part


  for (b in 1:B) {
    if (!missing(object)) 
      z.vals <- rnorm(n, ablts, se.ablts)
    data.new <- rmvlogis(n, parms, IRT = IRT, z.vals = z.vals)
    T.boot[b, ] <- eigenRho(data.new)$ev
  }

with the following code, which simply checks whether there are columns with zero variance in the simulated dataset and, in that case, simply simulates a new dataset until all columns have at least some variance.


for (b in 1:B) {
    dataok <- FALSE
    while(!dataok)
    {
      if (!missing(object)) 
        z.vals <- rnorm(n, ablts, se.ablts)
      data.new <- rmvlogis(n, parms, IRT = IRT, z.vals = z.vals)
      if(all(apply(data.new, 2, sd) != 0))
        dataok <- TRUE
    }
    T.boot[b, ] <- eigenRho(data.new)$ev
  }

Kind regards

drizopoulos commented 6 years ago

Thanks! I'll have a look rectifying this.

mbrucato commented 3 years ago

Hi, I know this is an old thread, but just checking in to see if this was fixed. I am running into the same error.

chouikri commented 2 years ago

hi I have the same issue using the function UnidimTest. However, the written code is without comments so I couldn't make it work for my case