From aa7e044bbdbd1e3b8d8397e124c681976666f3cf Mon Sep 17 00:00:00 2001 From: merliseclyde Date: Mon, 4 Nov 2019 23:39:37 -0500 Subject: [PATCH] Fix for issue #44 warning when contrasts are not a list in bas.lm and bas.glm --- NEWS.md | 9 +++++++-- R/bas_glm.R | 3 ++- R/bas_lm.R | 2 ++ man/bas.glm.Rd | 16 +++++++++------- man/bas.lm.Rd | 12 +++++++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 52a87df3..9d930fd5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,15 @@ # BAS 1.5.4 -# Features +## Features -Modified prior probabilities to adjust for the number of variables always included when +* Modified prior probabilities to adjust for the number of variables always included when using include.always. [Pull request #41](https://github.com/merliseclyde/BAS/pull/41) by Don van de Bergh. [Issue #40](https://github.com/merliseclyde/BAS/issues/40) +## Bug Fixes + +* Added `contrast=NULL` argument to `bas.lm` and `bas.glm` so that non-NULL contrasts do not +trigger warning in `model.matrix` as of R 3.6.0. [Bug #44](https://github.com/merliseclyde/BAS/issues/44) + ## Other * Put ORCID in quotes in author list (per R-dev changes) diff --git a/R/bas_glm.R b/R/bas_glm.R index 8d31499b..d5acd0a0 100644 --- a/R/bas_glm.R +++ b/R/bas_glm.R @@ -61,6 +61,7 @@ normalize.initprobs.glm <- function(initprobs, glm.obj) { #' @param weights optional vector of weights to be used in the fitting process. #' May be missing in which case weights are 1. #' @param subset subset of data used in fitting +#' @param contrasts an optional list. See the contrasts.arg of `model.matrix.default()`. #' @param offset a priori known component to be included in the linear #' predictor; by default 0. #' @param na.action a function which indicates what should happen when the data @@ -226,7 +227,7 @@ normalize.initprobs.glm <- function(initprobs, glm.obj) { #' @rdname bas.glm #' @export bas.glm <- function(formula, family = binomial(link = "logit"), - data, weights, subset, offset, na.action = "na.omit", + data, weights, subset, contrasts=NULL, offset, na.action = "na.omit", n.models = NULL, betaprior = CCH(alpha = .5, beta = as.numeric(nrow(data)), s = 0), modelprior = beta.binomial(1, 1), diff --git a/R/bas_lm.R b/R/bas_lm.R index a7a9a2fb..23762e73 100644 --- a/R/bas_lm.R +++ b/R/bas_lm.R @@ -113,6 +113,7 @@ normalize.n.models <- function(n.models, p, initprobs, method, bigmem) { #' @param weights an optional vector of weights to be used in the fitting #' process. Should be NULL or a numeric vector. If non-NULL, Bayes estimates #' are obtained assuming that Y ~ N(Xb, sigma^2 diag(1/weights)). +#' @param contrasts an optional list. See the contrasts.arg of `model.matrix.default()`. #' @param na.action a function which indicates what should happen when the data #' contain NAs. The default is "na.omit". #' @param n.models number of models to sample either without replacement @@ -439,6 +440,7 @@ bas.lm <- function(formula, data, subset, weights, + contrasts=NULL, na.action = "na.omit", n.models = NULL, prior = "ZS-null", diff --git a/man/bas.glm.Rd b/man/bas.glm.Rd index b502a79c..1579cea5 100644 --- a/man/bas.glm.Rd +++ b/man/bas.glm.Rd @@ -6,13 +6,13 @@ Generalized Linear Models} \usage{ bas.glm(formula, family = binomial(link = "logit"), data, weights, - subset, offset, na.action = "na.omit", n.models = NULL, - betaprior = CCH(alpha = 0.5, beta = as.numeric(nrow(data)), s = 0), - modelprior = beta.binomial(1, 1), initprobs = "Uniform", - include.always = ~1, method = "MCMC", update = NULL, - bestmodel = NULL, prob.rw = 0.5, MCMC.iterations = NULL, - control = glm.control(), laplace = FALSE, renormalize = FALSE, - force.heredity = TRUE, bigmem = FALSE) + subset, contrasts = NULL, offset, na.action = "na.omit", + n.models = NULL, betaprior = CCH(alpha = 0.5, beta = + as.numeric(nrow(data)), s = 0), modelprior = beta.binomial(1, 1), + initprobs = "Uniform", include.always = ~1, method = "MCMC", + update = NULL, bestmodel = NULL, prob.rw = 0.5, + MCMC.iterations = NULL, control = glm.control(), laplace = FALSE, + renormalize = FALSE, force.heredity = TRUE, bigmem = FALSE) } \arguments{ \item{formula}{generalized linear model formula for the full model with all @@ -30,6 +30,8 @@ May be missing in which case weights are 1.} \item{subset}{subset of data used in fitting} +\item{contrasts}{an optional list. See the contrasts.arg of `model.matrix.default()`.} + \item{offset}{a priori known component to be included in the linear predictor; by default 0.} diff --git a/man/bas.lm.Rd b/man/bas.lm.Rd index 8f5c33fd..a36b7aa3 100644 --- a/man/bas.lm.Rd +++ b/man/bas.lm.Rd @@ -6,11 +6,11 @@ \title{Bayesian Adaptive Sampling for Bayesian Model Averaging and Variable Selection in Linear Models} \usage{ -bas.lm(formula, data, subset, weights, na.action = "na.omit", - n.models = NULL, prior = "ZS-null", alpha = NULL, - modelprior = beta.binomial(1, 1), initprobs = "Uniform", - include.always = ~1, method = "BAS", update = NULL, - bestmodel = NULL, prob.local = 0, prob.rw = 0.5, +bas.lm(formula, data, subset, weights, contrasts = NULL, + na.action = "na.omit", n.models = NULL, prior = "ZS-null", + alpha = NULL, modelprior = beta.binomial(1, 1), + initprobs = "Uniform", include.always = ~1, method = "BAS", + update = NULL, bestmodel = NULL, prob.local = 0, prob.rw = 0.5, MCMC.iterations = NULL, lambda = NULL, delta = 0.025, thin = 1, renormalize = FALSE, force.heredity = TRUE, pivot = FALSE, tol = 1e-07, bigmem = FALSE) @@ -30,6 +30,8 @@ used in the fitting process.} process. Should be NULL or a numeric vector. If non-NULL, Bayes estimates are obtained assuming that Y ~ N(Xb, sigma^2 diag(1/weights)).} +\item{contrasts}{an optional list. See the contrasts.arg of `model.matrix.default()`.} + \item{na.action}{a function which indicates what should happen when the data contain NAs. The default is "na.omit".}