Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check fixes and fitIndices now works for multiple group objects

  • Loading branch information...
commit 06e2bfa7a3af3cb075df590eea268862043c3c7b 1 parent 2403284
@philchalmers authored
View
1  NAMESPACE
@@ -1,4 +1,3 @@
-S3method(print,mirtFitIndices)
S3method(print,wald)
export(bfactor)
export(calcLogLik)
View
2  R/03-estimation.R
@@ -225,7 +225,7 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1
tabdata=PrepList[[g]]$tabdata2, data=data[group == groupNames[[g]], ],
converge=ESTIMATE$converge, esttype='MHRM', F=F, h2=h2,
K=PrepList[[g]]$K, tabdatalong=PrepList[[g]]$tabdata, nfact=nfact,
- constrain=constrain, G2=G2group[g],
+ constrain=constrain, G2=G2group[g], Pl = rlist[[g]]$expected,
mixedlist=if(method == 'MIXED') mixedlist else list(),
fulldata=PrepList[[g]]$fulldata, factorNames=PrepList[[g]]$factorNames)
}
View
48 R/fitIndices.R
@@ -6,7 +6,7 @@
#'
#'
#' @aliases fitIndices
-#' @param data matrix or data.frame
+#' @param obj an estimated model object from the mirt package
#' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com}
#' @references
#' Maydeu-Olivares, A. & Joe, H. (2006). Limited information goodness-of-fit testing in
@@ -26,6 +26,31 @@
#' }
fitIndices <- function(obj){
#if MG loop
+ if(is(obj, 'MixedClass'))
+ stop('mixedmirt objects not yet supported')
+ if(is(obj, 'MultipleGroupClass')){
+ cmods <- obj@cmods
+ r <- obj@tabdata[, ncol(obj@tabdata)]
+ ngroups <- length(cmods)
+ ret <- vector('list', length(cmods))
+ for(g in 1:ngroups){
+ attr(cmods[[g]], 'MG') <- TRUE
+ ret[[g]] <- fitIndices(cmods[[g]])
+ }
+ newret <- list()
+ newret$M2 <- numeric(ngroups)
+ names(newret$M2) <- obj@groupNames
+ for(g in 1:ngroups)
+ newret$M2[g] <- ret[[g]]$M2
+ newret$M2Total <- sum(newret$M2)
+ Tsum <- 0
+ for(g in 1:ngroups) Tsum <- Tsum + ret[[g]]$nrowT
+ newret$dfM2 <- obj@df - (nrow(obj@tabdata) - Tsum)
+ newret$p.M2 <- 1 - pchisq(newret$M2Total, newret$dfM2)
+ newret$RMSEA.M2 <- ifelse((newret$M2Total - newret$dfM2) > 0,
+ sqrt(newret$M2Total - newret$dfM2) / sqrt(newret$dfM2 * (sum(r)-1)), 0)
+ return(newret)
+ }
ret <- list()
tabdata <- obj@tabdatalong
K <- obj@K
@@ -67,8 +92,7 @@ fitIndices <- function(obj){
T <- na.omit(T)
Eta <- T %*% Gamma %*% t(T)
T.p <- T %*% p
- T.p_theta <- T %*% p_theta
- dfM2 <- obj@df - (nrow(tabdata) - nrow(T))
+ T.p_theta <- T %*% p_theta
inv.Eta <- try(solve(Eta), silent = TRUE)
if(is(inv.Eta, 'try-error')){
diag(Eta) <- diag(Eta) + .01 * diag(Eta)
@@ -102,13 +126,15 @@ fitIndices <- function(obj){
delta2 <- T %*% delta
C2 <- inv.Eta - inv.Eta %*% delta2 %*% solve(t(delta2) %*% inv.Eta %*% delta2) %*%
t(delta2) %*% inv.Eta
- M2 <- N * t(T.p - T.p_theta) %*% C2 %*% (T.p - T.p_theta)
- p.M2 <- 1 - pchisq(M2, dfM2)
- RMSEA.M2 <- ifelse((M2 - dfM2) > 0,
- sqrt(M2 - dfM2) / sqrt(dfM2 * (sum(r)-1)), 0)
- ret$M2 <- M2
- ret$dfM2 <- dfM2
- ret$p.M2 <- p.M2
- ret$RMSEA.M2 <- RMSEA.M2
+ M2 <- N * t(T.p - T.p_theta) %*% C2 %*% (T.p - T.p_theta)
+ ret$M2 <- M2
+ if(is.null(attr(obj, 'MG'))){
+ ret$dfM2 <- obj@df - (nrow(tabdata) - nrow(T))
+ ret$p.M2 <- 1 - pchisq(M2, ret$dfM2)
+ ret$RMSEA.M2 <- ifelse((M2 - ret$dfM2) > 0,
+ sqrt(M2 - ret$dfM2) / sqrt(ret$dfM2 * (sum(r)-1)), 0)
+ } else {
+ ret$nrowT <- nrow(T)
+ }
ret
}
View
16 R/mirt-package.R
@@ -81,3 +81,19 @@ NULL
#'
#' @keywords data
NULL
+
+#' Description of LSAT6 data
+#'
+#' Data from Thissen (1982); contains 5 dichotomously scored
+#' items obtained from the Law School Admissions Test, section 6.
+#'
+#'
+#' @name LSAT6
+#' @docType data
+#' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com}
+#' @references
+#' Thissen, D. (1982). Marginal maximum likelihood estimation for the one-parameter logistic model.
+#' \emph{Psychometrika, 47}, 175-186.
+#'
+#' @keywords data
+NULL
View
20 man/LSAT6.Rd
@@ -0,0 +1,20 @@
+\docType{data}
+\name{LSAT6}
+\alias{LSAT6}
+\title{Description of LSAT6 data}
+\description{
+ Data from Thissen (1982); contains 5 dichotomously scored
+ items obtained from the Law School Admissions Test,
+ section 6.
+}
+\author{
+ Phil Chalmers \email{rphilip.chalmers@gmail.com}
+}
+\references{
+ Thissen, D. (1982). Marginal maximum likelihood
+ estimation for the one-parameter logistic model.
+ \emph{Psychometrika, 47}, 175-186.
+}
+\keyword{data}
+\keyword{datasets}
+
View
10 man/fitIndices.Rd
@@ -1,18 +1,12 @@
\name{fitIndices}
\alias{fitIndices}
-\alias{print.mirtFitIndices}
\title{Compute Extra Model Fit Indices}
\usage{
fitIndices(obj)
-
- \method{print}{mirtFitIndices} (x, ...)
}
\arguments{
- \item{data}{matrix or data.frame}
-
- \item{x}{an estimated model object from the mirt package}
-
- \item{...}{additional arguments}
+ \item{obj}{an estimated model object from the mirt
+ package}
}
\description{
Compute additional model fit indecies that do not come as
Please sign in to comment.
Something went wrong with that request. Please try again.