alexanderrobitzsch / sirt

Supplementary Item Response Theory Models
https://alexanderrobitzsch.github.io/sirt/
22 stars 11 forks source link

Computing standard errors with invariance.alignment() #25

Closed meltemozcan closed 7 months ago

meltemozcan commented 7 months ago

I am following along to example 8 from the manual to compute standard errors with invariance.alignment() . To my understanding, the meth parameter isn't defined before the function call, so I tried calling the function with the default value of 1 as well as 2-4 as mentioned in the function documentation. I am getting the following error: `#> Error in (function (x, lambda, nu, overparam, eps, meth) : argument "meth" is missing, with no default

variance matrix and standard errors`

I am pasting the reprex with the error below for your reference. I'm not sure if this is a bug or if I'm missing something, and I would appreciate if you could let me know how to proceed. Thank you very much in advance!

#############################################################################
# EXAMPLE 8: Computation of standard errors
#############################################################################
G <- 3 # number of groups
I <- 5 # number of items
# define lambda and nu parameters
lambda <- matrix(1, nrow=G, ncol=I)
nu <- matrix(0, nrow=G, ncol=I)
# define size of noninvariance
dif <- 1
mu1 <- c(0,.3,.8)
sigma1 <- c(1,1.25,1.1)

lambda[1,3] <- 1+dif*.4; nu[1,5] <- dif*.5

gg <- 2
lambda[gg,5] <- 1-.5*dif; nu[gg,1] <- -.5*dif

gg <- 3
lambda[gg,4] <- 1-.7*dif; nu[gg,2] <- -.5*dif

dat <- sirt::invariance_alignment_simulate(nu=nu, 
                                           lambda=lambda,
                                           err_var=1+0*lambda,
                                           mu=mu1, 
                                           sigma=sigma1, 
                                           N=500, 
                                           output="data", 
                                           exact=TRUE)
# estimate CFA
res <- sirt::invariance_alignment_cfa_config(dat=dat[,-1], group=dat$group)
#> Compute CFA for group 1 | model 2PM
#> Loading required namespace: MASS
#> Compute CFA for group 2 | model 2PM
#> Compute CFA for group 3 | model 2PM

eps <- .001 
align.pow <- 0.5*rep(1,2)
(lambda <- res$lambda)
#>     I1   I2   I3   I4    I5
#> 1 1.00 1.00 1.40 1.00 1.000
#> 2 1.25 1.25 1.25 1.25 0.625
#> 3 1.10 1.10 1.10 0.33 1.100
(nu <- res$nu)
#>              I1           I2          I3           I4   I5
#> 1 -4.218847e-17 4.263256e-17 2.04281e-17 1.554312e-17 0.50
#> 2 -2.000000e-01 3.000000e-01 3.00000e-01 3.000000e-01 0.15
#> 3  8.000000e-01 3.000000e-01 8.00000e-01 2.400000e-01 0.80

mod1 <- sirt::invariance.alignment(lambda=lambda,
                                   nu=nu,
                                   eps=eps,
                                   optimizer="optim",
                                   align.pow=align.pow,
                                   meth=1,
                                   vcov=res$vcov)
#> Error in (function (x, lambda, nu, overparam, eps, meth_) : argument "meth_" is missing, with no default
#variance matrix and standard errors
mod1$vcov
#> Error in eval(expr, envir, enclos): object 'mod1' not found
sqrt(diag(mod1$vcov))
#> Error in eval(expr, envir, enclos): object 'mod1' not found

Created on 2024-03-15 with reprex v2.1.0

alexanderrobitzsch commented 7 months ago

I might have be introduced a bug when I restructured the function. I will have a look at it in the next time.

alexanderrobitzsch commented 7 months ago

The bug should be fixed in the recent release sirt 4.2-32.

meltemozcan commented 7 months ago

Thank you very much for your quick response, it works as expected now!