Skip to content

Commit

Permalink
Use is.null vs is.missing where relevant (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
hturner committed Oct 1, 2019
1 parent 90a7e2a commit ecfff44
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -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
====================
Expand Down
14 changes: 7 additions & 7 deletions R/gnm.R
Expand Up @@ -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)`)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 <-
Expand All @@ -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,
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion R/gnmTerms.R
Expand Up @@ -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], ")"),
Expand Down
2 changes: 1 addition & 1 deletion R/pickCoef.R
Expand Up @@ -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:",
Expand Down
10 changes: 5 additions & 5 deletions R/predict.gnm.R
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions man/confint.gnm.Rd
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/gnm.Rd
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/pickCoef.Rd
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions man/profile.gnm.Rd
Expand Up @@ -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). }
Expand All @@ -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. }
Expand Down
2 changes: 1 addition & 1 deletion man/se.gnm.Rd
Expand Up @@ -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?}
Expand Down

0 comments on commit ecfff44

Please sign in to comment.