# loading data
data(GMAT)
y <- GMAT[, 1] # item 1
match <- scale(rowSums(GMAT[, 1:20])) # standardized total score
group <- GMAT[, "group"] # group membership variable
# formula for 3PL model with the same guessing for both groups,
# IRT parameterization
M <- formulaNLR(model = "3PLcg", type = "both", parameterization = "irt")
# starting values for 3PL model with the same guessing for item 1
start <- startNLR(GMAT[, 1:20], group, model = "3PLcg", parameterization = "irt")
start <- start[[1]][M$M1$parameters]
# nonlinear least squares
(fit_nls <- estimNLR(
y = y, match = match, group = group,
formula = M$M1$formula, method = "nls",
lower = M$M1$lower, upper = M$M1$upper, start = start
))
coef(fit_nls)
logLik(fit_nls)
vcov(fit_nls)
vcov(fit_nls, sandwich = TRUE)
fitted(fit_nls)
residuals(fit_nls)
# maximum likelihood method
(fit_mle <- estimNLR(
y = y, match = match, group = group,
formula = M$M1$formula, method = "mle",
lower = M$M1$lower, upper = M$M1$upper, start = start
))
coef(fit_mle)
logLik(fit_mle)
vcov(fit_mle)
fitted(fit_mle)
residuals(fit_mle)
# formula for 3PL model with the same guessing for both groups
# intercept-slope parameterization
M <- formulaNLR(model = "3PLcg", type = "both", parameterization = "is")
# starting values for 3PL model with the same guessing for item 1,
start <- startNLR(GMAT[, 1:20], group, model = "3PLcg", parameterization = "is")
start <- start[[1]][M$M1$parameters]
# EM algorithm
(fit_em <- estimNLR(
y = y, match = match, group = group,
formula = M$M1$formula, method = "em",
lower = M$M1$lower, upper = M$M1$upper, start = start
))
coef(fit_em)
logLik(fit_em)
vcov(fit_em)
fitted(fit_em)
residuals(fit_em)
# PLF algorithm
(fit_plf <- estimNLR(
y = y, match = match, group = group,
formula = M$M1$formula, method = "plf",
lower = M$M1$lower, upper = M$M1$upper, start = start
))
coef(fit_plf)
logLik(fit_plf)
vcov(fit_plf)
fitted(fit_plf)
residuals(fit_plf)
# iteratively reweighted least squares for 2PL model
M <- formulaNLR(model = "2PL", parameterization = "logistic")
(fit_irls <- estimNLR(
y = y, match = match, group = group,
formula = M$M1$formula, method = "irls"
))
coef(fit_irls)
logLik(fit_irls)
vcov(fit_irls)
fitted(fit_irls)
residuals(fit_irls)
Run the code above in your browser using DataLab