Commit be0052a6 authored by Joshua Pritikin's avatar Joshua Pritikin

Make failure modes more forgiving

parent 22f3d3c0
......@@ -329,7 +329,11 @@ SitemFit1Internal <- function(out) {
mask <- apply(observed, 1, sum) != 0
observed = observed[mask,,drop=FALSE]
expected = expected[mask,,drop=FALSE]
if (!length(observed)) stop("No data for item")
if (!length(observed)) {
out$statistic <- NA
out$pval <- NA
return(out)
}
method <- out$method
if (method == "pearson") {
......@@ -646,8 +650,9 @@ ptw2011.gof.test <- function(observed, expected) {
}
if (any(c(expected)==0)) {
zeros <- sum(c(expected)==0)
stop(paste("There are", zeros, "zeros in the expected distribution.",
warning(paste("There are", zeros, "zeros in the expected distribution.",
"Did you swap the observed and expected arguments"))
return(NA)
}
observed <- observed / orig.draws
expected <- expected / orig.draws
......
......@@ -77,6 +77,8 @@ ssEAP <- function(grp, qwidth, qpoints, mask, twotier=FALSE, debug=FALSE) {
}
sumScoreEAPTestInternal <- function(result) {
class(result) <- "summary.sumScoreEAPTest"
if (result[['n']] == 0) return(result)
expected <- matrix(result$expected, ncol=1)
obs <- matrix(result$observed, ncol=1)
......@@ -89,8 +91,6 @@ sumScoreEAPTestInternal <- function(result) {
result$pearson.chisq <- sum((obs[mask] - expected[mask])^2 / expected[mask])
result$pearson.df <- sum(mask)-1L
result$pearson.p <- pchisq(result$pearson.chisq, result$pearson.df, lower.tail=FALSE, log.p=TRUE)
class(result) <- "summary.sumScoreEAPTest"
result
}
......@@ -239,6 +239,9 @@ observedSumScore <- function(grp, ..., mask, summary=TRUE) {
return(ss)
}
got <- .Call(observedSumScore_wrapper, grp, mask)
if (got[['n']] == 0) {
warning("Some columns are all missing; cannot compute observedSumScore")
}
class(got) <- "summary.observedSumScore"
got
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment