aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2022-07-27 10:28:17 -0400
committerKen Kellner <ken@kenkellner.com>2022-07-27 10:28:17 -0400
commitbe8b9eb76ed14b85a395ab718c6bc8f467118865 (patch)
tree16090b877b4778c7dabc7fd1d160b5744d23a4db
parent9213a62c177ce9556a7a55fb87e900557e434e5f (diff)
Allow : notation for interactions among fixed effects
-rw-r--r--DESCRIPTION4
-rw-r--r--R/stanmodels.R2
-rw-r--r--R/submodel.R2
-rw-r--r--tests/testthat/test_distsamp.R2
-rw-r--r--tests/testthat/test_submodel.R9
5 files changed, 14 insertions, 5 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index 318d80a..4bf4d22 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: ubms
-Version: 1.1.9004
-Date: 2022-03-31
+Version: 1.1.9005
+Date: 2022-07-27
Title: Bayesian Models for Data from Unmarked Animals using 'Stan'
Authors@R: person("Ken", "Kellner", email="contact@kenkellner.com",
role=c("cre","aut"))
diff --git a/R/stanmodels.R b/R/stanmodels.R
index 016113d..e78fcd4 100644
--- a/R/stanmodels.R
+++ b/R/stanmodels.R
@@ -23,5 +23,5 @@ stanmodels <- sapply(stanmodels, function(model_name) {
model_name = stanfit$model_name,
model_code = stanfit$model_code,
model_cpp = stanfit$model_cpp,
- mk_cppmodule = function(x) get(paste0("model_", model_name)))
+ mk_cppmodule = function(x) get(paste0("rstantools_model_", model_name)))
})
diff --git a/R/submodel.R b/R/submodel.R
index 29e9911..f7b6c8d 100644
--- a/R/submodel.R
+++ b/R/submodel.R
@@ -164,7 +164,7 @@ check_formula <- function(formula, data){
rand <- lme4::findbars(formula)
if(is.null(rand)) return(invisible())
- char <- paste(formula, collapse=" ")
+ char <- paste(lme4::findbars(formula)[[1]], collapse=" ")
if(grepl(":|/", char)){
stop("Nested random effects (using / and :) are not supported",
call.=FALSE)
diff --git a/tests/testthat/test_distsamp.R b/tests/testthat/test_distsamp.R
index 101d22f..8a8c22a 100644
--- a/tests/testthat/test_distsamp.R
+++ b/tests/testthat/test_distsamp.R
@@ -95,7 +95,7 @@ test_that("stan_distsamp produces accurate results",{
stan_mod <- suppressWarnings(stan_distsamp(~1~1, ltUMF_big, keyfun="exp",
chains=2, iter=200, refresh=0))
um_mod <- distsamp(~1~1, ltUMF_big, keyfun="exp")
- expect_RMSE(coef(stan_mod), coef(um_mod), 0.01)
+ expect_RMSE(coef(stan_mod), coef(um_mod), 0.02)
stan_mod <- suppressWarnings(stan_distsamp(~1~1, ltUMF_big, output="abund",
chains=2, iter=200, refresh=0))
diff --git a/tests/testthat/test_submodel.R b/tests/testthat/test_submodel.R
index b57f03b..484026d 100644
--- a/tests/testthat/test_submodel.R
+++ b/tests/testthat/test_submodel.R
@@ -387,6 +387,15 @@ test_that("check_formula identifies unsupported formulas",{
expect_error(check_formula(~(1|x1 : x2), dat))
})
+test_that("check_formula allows : in non-random effects part of formula",{
+ dat <- data.frame(y=rnorm(10), x1=rnorm(10), x2=rnorm(10),
+ x3=sample(letters[1:3], 10, replace=T),
+ x4=sample(letters[4:6], 10, replace=T))
+ expect_error(check_formula(~x1*x2 + (1|x3), dat), NA)
+ expect_error(check_formula(~x1:x2 + (1|x3), dat), NA)
+ expect_error(check_formula(~x1:x2 + (1|x3:x2), dat))
+})
+
test_that("check_formula handles very long formulas",{
dat <- data.frame(y=rnorm(10), longcovariate1=rnorm(10), longcovariate2=rnorm(10),
longcovariate3=rnorm(10), longcovariate4=rnorm(10),