Skip to content

Commit

Permalink
fix the cut, I(), and dim to .Dim issues; updated the bibentry; updat…
Browse files Browse the repository at this point in the history
…ed cran-comments
  • Loading branch information
zhenkewu committed Dec 14, 2023
1 parent 216a4a3 commit 3e71349
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 56 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: baker
Type: Package
Title: Nested Partially Latent Class Models
Version: 1.0.0.9000
Date: 2022-02-02
Version: 1.0.2
Date: 2023-12-14
Authors@R: c(
person("Zhenke", "Wu", email="zhenkewu@gmail.com",role=c("cre","aut","cph"),
comment = c(ORCID = "0000-0001-7582-669X")),
Expand All @@ -23,7 +23,7 @@ Description: Provides functions to specify, fit and visualize
of interest sum to one hundred percent, the PERCH scientists frequently refer to
them as "population etiology pie" and "individual etiology pie", hence the name of the package.
Depends:
R(>= 3.5.0)
R(>= 4.3.0)
Imports:
rjags(>= 4-6),
R2jags(>= 0.5),
Expand All @@ -44,7 +44,7 @@ Imports:
abind
License: MIT + file LICENSE
Language: en-US
SystemRequirements: JAGS (>= 4.1.0) (http://mcmc-jags.sourceforge.net)
SystemRequirements: JAGS (>= 4.3.2) (http://mcmc-jags.sourceforge.net)
Suggests:
spelling,
knitr,
Expand All @@ -53,7 +53,7 @@ Suggests:
covr,
knitcitations
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
Encoding: UTF-8
URL: https://github.com/zhenkewu/baker
BugReports: https://github.com/zhenkewu/baker/issues
Expand Down
3 changes: 1 addition & 2 deletions R/example_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#' @usage data("data_nplcm_reg_nest")
"data_nplcm_reg_nest"

#' Simulated dataset that is structured in the format necessary for an [nplcm()] with regression
#' Simulated dataset that is structured in the format necessary for an [nplcm()] without regression
#'
#' Data set for illustrating regression functionalities
#'
Expand All @@ -86,7 +86,6 @@
"data_nplcm_noreg"



# NB: a few more data sets: data_nplcm_no_reg (no regression setting); this can be used in a lot of functions
# for visualization. Perhaps also need to add posterior samples as data set just as a way to
# demonstrate the plotting functionality and unit test.
7 changes: 3 additions & 4 deletions R/nplcm-read-folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ nplcm_read_folder <- function(DIR_NPLCM){
#' n.itermcmc = as.integer(200),
#' n.burnin = as.integer(100),
#' n.thin = 1,
#' individual.pred = TRUE, # <- must set to TRUE! <------- NOTE!
#' individual.pred = TRUE, # <- must set to TRUE!
#' ppd = FALSE,
#' result.folder = thedir,
#' bugsmodel.dir = thedir
Expand All @@ -251,9 +251,8 @@ nplcm_read_folder <- function(DIR_NPLCM){
#'
#' rjags::load.module("glm")
#'
#' nplcm_noreg <- nplcm(data_nplcm_noreg,model_options_no_reg,mcmc_options_no_reg)
#'
#' image(get_individual_prediction(nplcm_noreg))
#' fitted_nplcm_noreg <- nplcm(data_nplcm_noreg,model_options_no_reg,mcmc_options_no_reg)
#' image(get_individual_prediction(fitted_nplcm_noreg))
#'
#' }
#'
Expand Down
35 changes: 27 additions & 8 deletions R/nplcm.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ nplcm <- function(data_nplcm,model_options,mcmc_options){
Mobs <- data_nplcm$Mobs
Y <- data_nplcm$Y
if (length(rle(Y)[["values"]])>2 | Y[1]!=1) {
stop("==[baker] 'data_nplcm$Y' must have cases on top of controls.
stop("==[baker] 'data_nplcm$Y' must have cases on top of controls.
Use 'baker::subset_data_nplcm_by_index()' to shuffle the rows. Then retry.==\n")}
X <- data_nplcm$X

Expand All @@ -232,7 +232,7 @@ nplcm <- function(data_nplcm,model_options,mcmc_options){
}
if (do_reg & !any(do_nested)){
if (do_discrete){
fitted_type <- "reg_nonest_strat"
fitted_type <- "reg_nonest_strat"
# when every regression is a regression upon discrete variables;
# when it is not a regression, the fitting function treats it as a single stratum
# when specifying the model in the .bug file (in the assign_model function, ~1
Expand Down Expand Up @@ -543,7 +543,8 @@ nplcm_fit_NoReg<-

for(i in seq_along(JBrS_list)){
assign(paste("JBrS", i, sep = "_"), JBrS_list[[i]])
assign(paste("MBS", i, sep = "_"), as.matrix_or_vec(MBS_list[[i]]))
xx <- as.matrix_or_vec(MBS_list[[i]]); attr(xx,"dimnames") <- NULL # remove dimnames.
assign(paste("MBS", i, sep = "_"), xx)
assign(paste("templateBS", i, sep = "_"), as.matrix_or_vec(template_BrS_list[[i]]))
}

Expand Down Expand Up @@ -995,7 +996,13 @@ nplcm_fit_NoReg<-
file = curr_data_txt_file)
## fix dimension problem.... convert say .Dmi=7:6 to c(7,6) (an issue for templateBS_1):
bad_jagsdata_txt <- readLines(curr_data_txt_file)
good_jagsdata_txt <- gsub( "([0-9]+):([0-9]+)", "c(\\1,\\2)", bad_jagsdata_txt,fixed = FALSE)
#good_jagsdata_txt <- gsub( "([0-9]+):([0-9]+)", "c(\\1,\\2)", bad_jagsdata_txt,fixed = FALSE)
## to add an additional complicatoin of dump creates a text file with , dim = but the JAGS only accepts .Dim=
good_jagsdata_txt <- gsub( ", dim =", ", .Dim=",
gsub( "([0-9]+):([0-9]+)", "c(\\1,\\2)", bad_jagsdata_txt,fixed = FALSE),
fixed = FALSE)


writeLines(good_jagsdata_txt, curr_data_txt_file)

# fix dimension problem.... convert say 7:6 to c(7,6) (an issue for a dumped matrix):
Expand All @@ -1007,6 +1014,15 @@ nplcm_fit_NoReg<-
good_jagsinits_txt <- gsub( "([0-9]+):([0-9]+)", "c(\\1,\\2)", bad_jagsinits_txt,fixed = FALSE)
writeLines(good_jagsinits_txt, curr_inits_txt_file)
}

## fixed some problems of JAGS 4.3.2 not having cut function; and I(a,b) functions weirdly, even though
## the two elements are already constants (errors says that are not constant).
curr_model_txt_file <- file.path(mcmc_options$result.folder,"model_NoReg.bug")
bad_model_txt <- readLines(curr_model_txt_file)
good_model_txt <- gsub( "cut\\(", "(", bad_model_txt,fixed = FALSE)
good_model_txt <- gsub( "I\\(0\\.000001,0\\.999999\\)", " ", good_model_txt,fixed = FALSE)
writeLines(good_model_txt, curr_model_txt_file)

if(is.null(mcmc_options$jags.dir)){mcmc_options$jags.dir=""}
gs <- jags2_baker(data = curr_data_txt_file,
inits = in_init,
Expand Down Expand Up @@ -1237,7 +1253,8 @@ nplcm_fit_Reg_discrete_predictor_NoNest <-
attributes(Z_FPR_list[[i]])[names(attributes(Z_FPR_list[[i]]))!="dim"] <- NULL

assign(paste("JBrS", i, sep = "_"), JBrS_list[[i]])
assign(paste("MBS", i, sep = "_"), as.matrix_or_vec(MBS_list[[i]]))
xx <- as.matrix_or_vec(MBS_list[[i]]); attr(xx,"dimnames") <- NULL # remove dimnames.
assign(paste("MBS", i, sep = "_"), xx)
assign(paste("templateBS", i, sep = "_"), as.matrix_or_vec(template_BrS_list[[i]]))

# Z_FPR0 <- Z_FPR_list[[i]]
Expand Down Expand Up @@ -1943,7 +1960,8 @@ nplcm_fit_Reg_NoNest <-
attributes(Z_FPR_list[[i]])[names(attributes(Z_FPR_list[[i]]))!="dim"] <- NULL

assign(paste("JBrS", i, sep = "_"), JBrS_list[[i]])
assign(paste("MBS", i, sep = "_"), as.matrix_or_vec(MBS_list[[i]]))
xx <- as.matrix_or_vec(MBS_list[[i]]); attr(xx,"dimnames") <- NULL # remove dimnames.
assign(paste("MBS", i, sep = "_"), xx)
assign(paste("templateBS", i, sep = "_"), as.matrix_or_vec(template_BrS_list[[i]]))

# Z_FPR0 <- Z_FPR_list[[i]]
Expand Down Expand Up @@ -2519,7 +2537,7 @@ nplcm_fit_Reg_Nest <- function(data_nplcm,model_options,mcmc_options){
}

if(is.null(prior$Eti_hyper_pflex)){
prior$Eti_hyper_pflex = c(1,0.5)
prior$Eti_hyper_pflex = c(1,0.5)
# beta prior for selecting constant vs non-constant additive component
}

Expand Down Expand Up @@ -2651,7 +2669,8 @@ nplcm_fit_Reg_Nest <- function(data_nplcm,model_options,mcmc_options){
attributes(Z_FPR_list[[i]])[names(attributes(Z_FPR_list[[i]]))!="dim"] <- NULL

assign(paste("JBrS", i, sep = "_"), JBrS_list[[i]])
assign(paste("MBS", i, sep = "_"), as.matrix_or_vec(MBS_list[[i]]))
xx <- as.matrix_or_vec(MBS_list[[i]]); attr(xx,"dimnames") <- NULL # remove dimnames.
assign(paste("MBS", i, sep = "_"), xx)
assign(paste("templateBS", i, sep = "_"), as.matrix_or_vec(template_BrS_list[[i]]))

# Z_FPR0 <- Z_FPR_list[[i]]
Expand Down
5 changes: 3 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,11 @@ set_strat <- function(X,X_reg) {
#'
#' @details Note that this function should be used with caution. It used
#' \deqn{nrow(X)/nrow(unique(X[,X_reg,drop=FALSE]))>10} as an *ad hoc* criterion.
#' It is not the same as `plyr::is.discrete()`
#' It is not the same as `is.discrete()` in `plyr`
#'
#' @param X A data frame of covariates
#' @param X_reg The vector of covariates that will stratify the analyses. These
#' variables have to be categorical. Or a formula (can be tested by `plyr::is.formula`),
#' variables have to be categorical. Or a formula (can be tested by `is.formula` in `plyr`),
#' e.g., `~as.factor(SITE8) + as.factor(AGECAT > 1)`.
#'
#' @return `TRUE` for all being discrete; `FALSE` otherwise.
Expand Down Expand Up @@ -1501,6 +1501,7 @@ as.matrix_or_vec <- function(x){
as.matrix(x)
}


#' get index of latent status
#'
#' @param cause_list see mode_options in [nplcm()]
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ date
2. Install [JAGS 4.2.0](https://sourceforge.net/projects/mcmc-jags/files/JAGS/4.x/Windows/); Add the path to JAGS 4.2.0 into the environmental variable (essential for R to find the jags program). See [this](https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10) for setting environmental variables;
- alternatives are `brew install -v jags` for OSX, `sudo apt-get install jags` for Ubuntu/Debian
3. Fire up `R`, run `R` command `install.packages("rjags")`
4. Install [`Rtools`](https://cran.r-project.org/bin/windows/Rtools/) (for building and installing R pacakges from source); Add the path to `Rtools` (e.g. `C:\Rtools\`) into your environmental variables so that R knows where to find it.
4. Install [`Rtools`](https://cran.r-project.org/bin/windows/Rtools/) (for building and installing R pacakges from source); Add the path to `Rtools` (e.g., `C:\Rtools\`) into your environmental variables so that R knows where to find it.
<!-- - [WinBUGS 1.4.3](http://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-winbugs/) -->
<!-- 1. Install the [patch](http://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-winbugs/the-bugs-project-winbugs-patches/) -->
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ status](https://ci.appveyor.com/api/projects/status/github/zhenkewu/baker?branch
[![](http://cranlogs.r-pkg.org/badges/grand-total/baker?color=green)](https://cran.r-project.org/package=baker)
[![](http://cranlogs.r-pkg.org/badges/last-month/baker?color=green)](https://cran.r-project.org/package=baker)
[![](http://cranlogs.r-pkg.org/badges/last-week/baker?color=green)](https://cran.r-project.org/package=baker)
[![](https://img.shields.io/badge/devel%20version-1.0.0.9000-blue.svg)](https://github.com/zhenkewu/baker)
[![](https://img.shields.io/badge/devel%20version-1.0.1-blue.svg)](https://github.com/zhenkewu/baker)
[![](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing)

<!-- [![Coverage status](https://codecov.io/gh/zhenkewu/baker/branch/master/graph/badge.svg)](https://codecov.io/github/zhenkewu/baker?branch=master) -->
Expand Down Expand Up @@ -303,8 +303,8 @@ date
3. Fire up `R`, run `R` command `install.packages("rjags")`
4. Install [`Rtools`](https://cran.r-project.org/bin/windows/Rtools/)
(for building and installing R pacakges from source); Add the path
to `Rtools` (e.g. `C:\Rtools\`) into your environmental variables so
that R knows where to find it.
to `Rtools` (e.g., `C:\Rtools\`) into your environmental variables
so that R knows where to find it.
<!-- - [WinBUGS 1.4.3](http://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-winbugs/) -->
<!-- 1. Install the [patch](http://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-winbugs/the-bugs-project-winbugs-patches/) -->
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ init:
install:
- ps: Bootstrap
- ps: (new-object net.webclient).DownloadFile('https://sourceforge.net/projects/mcmc-jags/files/JAGS/4.x/Windows/JAGS-4.2.0-Rtools33.exe', 'C:\projects\JAGS-4.2.0.exe')
- cmd: C:\projects\JAGS-4.2.0.exe /S
- ps: (new-object net.webclient).DownloadFile('https://sourceforge.net/projects/mcmc-jags/files/JAGS/4.x/Windows/JAGS-4.3.1.exe', 'C:\projects\JAGS-4.3.1.exe')
- cmd: C:\projects\JAGS-4.3.1.exe /S


cache:
Expand Down
34 changes: 21 additions & 13 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
## Resubmission
This is a resubmission. In this version I have:

* exported functions that used `baker:::`
* updated to fix an issue in the example of `nplcm` (Package was archived on CRAN because of a tricky interfacing issue between JAGS 4.3.x and R 4.3.x)

* [only appeared on Windows Server 2022, R-devel, 64 bit]checking for detritus in the temp directory ... NOTE
Found the following files/directories:
'lastMiKTeXException'
We checked online; it seems to be platform-specific and related to files produced during testing; we did not find any place in the source files where interactive use of the vignette was invoked. This note did not appear in other platforms.

* There is another note (occasionally) about some doi links being "Service Unavailable".
I checked that every link works. They were considered to be slow (by the checking functions)
when directed to the page.

* Previously I was asked to ignore the following note about spelling (for author names)
Possibly misspelled words in DESCRIPTION:
al (17:49, 19:11)
et (17:46, 19:8)

## Reverse dependencies

This is a precise fix to a previously a short and archived release taken down on 2022-06-08 (https://cran.r-project.org/web/packages/baker/index.html), so there are no reverse dependencies
given the short life of the previous release.

* removed all occurrences of `rm(list = ls())`


## Test environments
* local OS X install, R 4.0.2
* local OS X install, R 4.3.1
* ubuntu latest release (on Github-Action), R 4.1.2
* win-builder (devel and release), R 4.1.2

## R CMD check results

0 errors | 0 warnings | 1 note

* New submission

* [only appeared on Windows Server 2022, R-devel, 64 bit]checking for detritus in the temp directory ... NOTE
Found the following files/directories:
'lastMiKTeXException'
We checked online; it seems to be platform-specific and related to files produced during testing; we did not find any place in the source files where interactive use of the vignette was invoked. This note did not appear in other platforms.

## Reverse dependencies

This is a new release, so there are no reverse dependencies.

---

Expand Down
Binary file removed figure/common_pattern_check-1.png
Binary file not shown.
Binary file removed figure/pairwise_SLORD-1.png
Binary file not shown.
Binary file removed figure/plot_etiology_strat-1.png
Binary file not shown.
Binary file removed figure/plot_etiology_strat-2.png
Binary file not shown.
Binary file removed figure/plot_logORmat-1.png
Binary file not shown.
Binary file removed figure/plot_panels_with_SS-1.png
Binary file not shown.
Binary file removed figure/traceplots-1.png
Binary file not shown.
Binary file removed figure/traceplots-2.png
Binary file not shown.
Binary file removed figure/visualize_posterior_dist-1.png
Binary file not shown.
37 changes: 28 additions & 9 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
citHeader("To cite baker in publications, please use:")

citEntry(entry = "Article",
author = personList(as.person("Zhenke Wu"),
as.person("Maria Deloria-Knoll"),
as.person("Laura L Hammitt"),
as.person("Scott L Zeger")),
bibentry(
bibtype = "Article",
title = "Partially Latent Class Models for Case-Control Studies
of Childhood Pneumonia Aetiology",
author = c(person("Zhenke", "Wu"),
person("Maria", "Deloria-Knoll"),
person("Laura L", "Hammitt"),
person("Scott L", "Zeger")
),
journal = "Journal of the Royal Statistical Society: Series C (Applied Statistics)",
year = "2015",
doi = "10.1111/rssc.12101",
volume = "65",
number = "1",
pages = " 97–114",
url = "https://rss.onlinelibrary.wiley.com/doi/full/10.1111/rssc.12101",
textVersion = "Wu, Z., Deloria-Knoll, M., Hammitt, L.L., Zeger, S.L. and the Pneumonia Etiology Research for Child Health Core Team (2016), Partially latent class models for case-control studies of childhood pneumonia aetiology. Journal of the Royal Statistical Society: Series C (Applied Statistics). doi: 10.1111/rssc.12101."
doi = "10.1111/rssc.12101"
)


bibentry(
bibtype = "Article",
title = "Nested partially latent class models for dependent binary data; estimating disease etiology",
author = c(person("Zhenke", "Wu"),
person("Maria", "Deloria-Knoll"),
person("Scott L", "Zeger")
),
journal = "Biostatistics",
year = "2017",
volume = "18",
number = "2",
pages = " 200–213",
url = "https://academic.oup.com/biostatistics/article/18/2/200/2555349",
doi = "10.1093/biostatistics/kxw037"
)
2 changes: 1 addition & 1 deletion man/data_nplcm_noreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/get_individual_prediction.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/is_discrete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e71349

Please sign in to comment.