Iavaan provide us with a confusion matrix to calculate specificity, sensibility and accuracy?
myData <- read.table("http://www.statmodel.com/usersguide/chap5/ex5.16.dat")
names(myData) <- c("u1","u2","u3","u4","u5","u6","x1","x2","x3","g")
myData$u1 <- ordered(myData$u1)
fit <- sem('u1 + u2 ~ x1 + x2', data = myData)
## choose an outcome to focus on
DV <- "u1"
## the slopes are in "gamma" because x1 and x2 are exogenous,
## but other slopes could be in $beta
(est <- lavInspect(fit, "est"))
## predicted values in probit scale
B <- est$gamma[DV, ]
X <- as.matrix(myData[ , c("x1","x2")])
yHat <- X %*% B
## transform to probabilities
M <- lavInspect(fit, "mean.ov")[DV] # 0
SD <- sqrt(lavInspect(fit, "cov.ov")[DV, DV]) # 1
myData$yHat <- qnorm(yHat, m = M, sd = SD)
## apply arbitrary cutoff of 50% to predict classification
myData$pred.50 <- ifelse(myData$yHat >= .5, 1, 0)
tab.50 <- table(obs = myData$u1, pred = myData$pred.50) # confusion matrix
## column %s show sensitivity (1) and specificity (0) on the diagonal
prop.table(tab.50, margin = 2)
## row %s show PPV (1) and NPV (0) on the diagonal
prop.table(tab.50, margin = 1)