diff --git a/NEWS.md b/NEWS.md index 19af2c9..19642a2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ Bug fixes --------- * `confint.profile.gnm()` now works for a single parameter ![(#10)](https://github.com/hturner/gnm/issues/10) + * `gnm()` now works when `eliminate` is specified as `NULL` ![(#14)](https://github.com/hturner/gnm/issues/14) Changes in gnm 1.1-0 ==================== diff --git a/R/gnm.R b/R/gnm.R index 5d43679..7615b1b 100755 --- a/R/gnm.R +++ b/R/gnm.R @@ -42,8 +42,8 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, drop.unused.levels = TRUE)) modelData <- eval(modelData, parent.frame()) - if (!missing(eliminate)) { - eliminate <- modelData$`(eliminate)` + eliminate <- modelData$`(eliminate)` + if (!is.null(eliminate)) { if (!is.factor(eliminate)) stop("'eliminate' must be a factor") xtf <- xtfrm(modelData$`(eliminate)`) @@ -106,7 +106,7 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, } } - if (is.empty.model(modelTerms) && missing(eliminate)) { + if (is.empty.model(modelTerms) && is.null(eliminate)) { if (method == "coefNames") return(numeric(0)) else if (method == "model.matrix") return(model.matrix(modelTerms, data = modelData)) @@ -176,7 +176,7 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, if (is.null(start)) start <- rep.int(NA, nElim + nParam) else if (length(start) != nElim + nParam) { - if (!missing(eliminate) && length(start) == nParam) + if (!is.null(eliminate) && length(start) == nParam) start <- c(rep.int(NA, nElim), start) else stop("length(start) must either equal the no. of parameters\n", @@ -270,7 +270,7 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, return() } - if (is.null(ofInterest) && !missing(eliminate)) + if (is.null(ofInterest) && !is.null(eliminate)) ofInterest <- seq_len(nParam) if (identical(ofInterest, "[?]")) call$ofInterest <- ofInterest <- @@ -291,7 +291,7 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, names(ofInterest) <- coefNames[ofInterest] } - if (missing(data)) + if (is.null(data)) data <- environment(formula) fit <- c(list(call = call, formula = formula, terms = modelTerms, data = data, eliminate = eliminate, @@ -301,7 +301,7 @@ gnm <- function(formula, eliminate = NULL, ofInterest = NULL, offset = offset, tolerance = tolerance, iterStart = iterStart, iterMax = iterMax), fit) - if (!missing(eliminate) && ordTRUE) { + if (!is.null(eliminate) && ordTRUE) { reorder <- order(ord) fit <- within(fit, { y <- y[reorder] diff --git a/R/gnmTerms.R b/R/gnmTerms.R index e8bb079..58cb57e 100755 --- a/R/gnmTerms.R +++ b/R/gnmTerms.R @@ -81,7 +81,7 @@ gnmTerms <- function(formula, eliminate = NULL, data = NULL) inst[patch] <- 1 nonsense <- tapply(inst, term, FUN = function(x) - {!is.na(x) && !identical(as.integer(x), seq(x))}) + {!all(is.na(x)) && !identical(as.integer(x), seq(x))}) if (any(nonsense)) stop("Specified instances of ", paste(names(nonsense)[nonsense], ")"), diff --git a/R/pickCoef.R b/R/pickCoef.R index 1d486d1..42497b3 100644 --- a/R/pickCoef.R +++ b/R/pickCoef.R @@ -17,7 +17,7 @@ pickCoef <- function(object, pattern = NULL, value = FALSE, ...){ coefs <- names(coef(object)) if (is.null(coefs)) stop("Coefficient names cannot be extracted from 'object'") - if (missing(pattern)) { + if (is.null(pattern)) { default <- list(setlabels = "Selected coefficients", title = "Select coefficients of interest", items.label = "Model coefficients:", diff --git a/R/predict.gnm.R b/R/predict.gnm.R index 84504d5..99759a1 100644 --- a/R/predict.gnm.R +++ b/R/predict.gnm.R @@ -28,7 +28,7 @@ predict.gnm <- function (object, newdata = NULL, terms <- setdiff(terms, "(eliminate)") } } - if (missing(newdata)) { + if (is.null(newdata)) { pred <- switch(type, link = object$predictors, response = object$fitted.values, terms = {pred <- termPredictors(object) @@ -97,7 +97,7 @@ predict.gnm <- function (object, newdata = NULL, if (se.fit) { V <- vcov(object, dispersion = dispersion, with.eliminate = TRUE) residual.scale <- as.vector(sqrt(attr(V, "dispersion"))) - if (missing(newdata)) { + if (is.null(newdata)) { X <- model.matrix(object) elim <- object$eliminate } else { @@ -123,14 +123,14 @@ predict.gnm <- function (object, newdata = NULL, 2*rowSums(X * covElim) + varElim) se.fit <- d * se.fit}, terms = { - if (missing(newdata)) { + if (is.null(newdata)) { assign <- split(seq(ncol(X)), attr(X, "assign")) } else { M <- model.matrix(object) assign <- split(seq(ncol(X)), attr(M, "assign")) } if (hasintercept) { - if (missing(newdata)) { + if (is.null(newdata)) { X <- sweep(X, 2, colMeans(X)) } else X <- sweep(X, 2, colMeans(M)) } @@ -151,7 +151,7 @@ predict.gnm <- function (object, newdata = NULL, } }) ## check estimability of predictions - if (!missing(newdata) && type != "terms"){ + if (!is.null(newdata) && type != "terms"){ estimable <- checkEstimable(object, t(X)) is.na(se.fit)[estimable %in% c(FALSE, NA)] <- TRUE } diff --git a/man/confint.gnm.Rd b/man/confint.gnm.Rd index a456dc4..eabee08 100644 --- a/man/confint.gnm.Rd +++ b/man/confint.gnm.Rd @@ -16,7 +16,7 @@ \item{object}{ an object of class \code{"gnm"} or \code{"profile.gnm"}} \item{parm}{ (optional) either a numeric vector of indices or a character vector of names, specifying the parameters for which - confidence intervals are to be estimated. If \code{parm} is missing, + confidence intervals are to be estimated. If \code{parm} is \code{NULL}, confidence intervals are found for all parameters.} \item{level}{ the confidence level required. } \item{trace}{ a logical value indicating whether profiling should be @@ -29,7 +29,7 @@ For \code{"gnm"} objects, \code{profile.gnm} is first called to profile the deviance over each parameter specified by \code{parm}, or - over all parameters in the model if \code{parm} is missing. + over all parameters in the model if \code{parm} is \code{NULL}. The method for \code{"profile.gnm"} objects is then called, which interpolates the deviance profiles to estimate the limits of the diff --git a/man/gnm.Rd b/man/gnm.Rd index 41aba90..02cb92a 100755 --- a/man/gnm.Rd +++ b/man/gnm.Rd @@ -22,7 +22,7 @@ gnm(formula, eliminate = NULL, ofInterest = NULL, constrain = numeric(0), improve computational efficiency. See details. } \item{ofInterest}{ optional coefficients of interest, specified by a regular expression, a numeric vector of indices, a character vector of - names, or "[?]" to select from a Tk dialog. If missing, it is + names, or "[?]" to select from a Tk dialog. If \code{NULL}, it is assumed that all non-\code{eliminate}d coefficients are of interest. } \item{constrain}{ (non-eliminated) coefficients to constrain, specified by a regular expression, a numeric vector of indices, a logical vector, a diff --git a/man/pickCoef.Rd b/man/pickCoef.Rd index cb8795e..13352d3 100644 --- a/man/pickCoef.Rd +++ b/man/pickCoef.Rd @@ -12,7 +12,7 @@ pickCoef(object, pattern = NULL, value = FALSE, ...) \item{object}{ a model object. } \item{pattern}{ character string containing a regular expression or (with \code{fixed = TRUE}) a pattern to be matched exactly. If - missing, a Tk dialog will open for coefficient selection. } + \code{NULL}, a Tk dialog will open for coefficient selection. } \item{value}{ if \code{FALSE}, a named vector of indices, otherwise the value of the selected coefficients. } \item{\dots}{ arguments to pass on to \link[relimp]{pickFrom} if diff --git a/man/profile.gnm.Rd b/man/profile.gnm.Rd index 2433df9..c04442a 100644 --- a/man/profile.gnm.Rd +++ b/man/profile.gnm.Rd @@ -14,7 +14,7 @@ \item{fitted}{ an object of class \code{"gnm"}. } \item{which}{ (optional) either a numeric vector of indices or a character vector of names, specifying the parameters over which the - deviance is to be profiled. If missing, the deviance is profiled + deviance is to be profiled. If \code{NULL}, the deviance is profiled over all parameters. } \item{alpha}{ the significance level of the z statistic, indicating the range that the profile must cover (see details). } @@ -23,7 +23,7 @@ \item{stepsize}{ (optional) a numeric vector of length two, specifying the size of steps to take when profiling down and up respectively, or a single number specifying the step size in both directions. If - missing, the step sizes will be determined automatically. } + \code{NULL}, the step sizes will be determined automatically. } \item{trace}{ logical, indicating whether profiling should be traced. } \item{\dots}{ further arguments. } diff --git a/man/se.gnm.Rd b/man/se.gnm.Rd index 6f3c4d2..a917020 100644 --- a/man/se.gnm.Rd +++ b/man/se.gnm.Rd @@ -19,7 +19,7 @@ numeric vector of indices or \code{"[?]"} to select from a Tk dialog. In the second case coefficients given as a vector or the rows of a matrix, such that \code{NROW(estimate)} is equal to - \code{length(coef(object))}. If missing, standard errors are returned + \code{length(coef(object))}. If \code{NULL}, standard errors are returned for all (non-eliminated) parameters in the model.} \item{checkEstimability}{ logical: should the estimability of all specified combinations be checked?}