Skip to content

Commit

Permalink
updated T() from I(); incorporated CRAN suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenkewu committed Dec 20, 2023
1 parent e84d564 commit 5096733
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 24 deletions.
12 changes: 6 additions & 6 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
Title: "Nested Partially Latent Class Models"
Version: 1.0.2
Date: 2023-12-18
Date: 2023-12-20
Authors@R: c(
person("Zhenke", "Wu", email="zhenkewu@gmail.com",role=c("cre","aut","cph"),
comment = c(ORCID = "0000-0001-7582-669X")),
Expand All @@ -15,13 +15,13 @@ Authors@R: c(
)
Description: Provides functions to specify, fit and visualize
nested partially-latent class models (
'Wu, Deloria-Knoll, Hammitt, and Zeger, 2016, JRSS-C' <doi:10.1111/rssc.12101>;
'Wu, Deloria-Knoll, and Zeger, 2017, Biostatistics' <doi:10.1093/biostatistics/kxw037>;
'Wu and Chen, 2021, Statistics in Medicine' <doi:10.1002/sim.8804>) for
Wu, Deloria-Knoll, Hammitt, and Zeger (2016) <doi:10.1111/rssc.12101>;
Wu, Deloria-Knoll, and Zeger (2017) <doi:10.1093/biostatistics/kxw037>;
Wu and Chen (2021) <doi:10.1002/sim.8804>) for
inference of population disease etiology and individual diagnosis. In the motivating
Pneumonia Etiology Research for Child Health (PERCH) study, because both quantities
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.
them as population etiology pie and individual etiology pie, hence the name of the package.
Depends:
R(>= 4.3.0)
Imports:
Expand Down
3 changes: 2 additions & 1 deletion R/eda.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ plot_logORmat = function(data_nplcm,
cex_main= min(2,20/n)
cex_se = min(1.5,15/n)

graphics::par(mar = c(0, 1, 5, 0), bg = "white",xpd=TRUE)
op <- graphics::par(mar = c(0, 1, 5, 0), bg = "white",xpd=TRUE)
on.exit(par(op))
graphics::plot(c(0, n + 0.8), c(0, n + 0.8), axes = axes, xlab = "",
ylab = "", asp = 1, type = "n")
##add grid
Expand Down
8 changes: 4 additions & 4 deletions R/nplcm.R
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ nplcm_fit_NoReg<-
curr_model_txt_file <- file.path(mcmc_options$result.folder,model_bugfile_name)
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)
# 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=""}
Expand Down Expand Up @@ -1772,7 +1772,7 @@ nplcm_fit_Reg_discrete_predictor_NoNest <-
curr_model_txt_file <- file.path(mcmc_options$result.folder,model_bugfile_name)
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)
# 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=""}
Expand Down Expand Up @@ -2461,7 +2461,7 @@ nplcm_fit_Reg_NoNest <-
curr_model_txt_file <- file.path(mcmc_options$result.folder,model_bugfile_name)
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)
# 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=""}
Expand Down Expand Up @@ -3223,7 +3223,7 @@ nplcm_fit_Reg_Nest <- function(data_nplcm,model_options,mcmc_options){
curr_model_txt_file <- file.path(mcmc_options$result.folder,model_bugfile_name)
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)
# 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=""}
Expand Down
20 changes: 14 additions & 6 deletions R/plot-etiology-regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@ plot_etiology_regression <- function(DIR_NPLCM,stratum_bool,slice=1,plot_basis=F
# plot results:
#################
if (do_plot){
par(mfcol=c(2,Jcause),oma=c(3,0,3,0))
op <- par(mfcol=c(2,Jcause),oma=c(3,0,3,0))
on.exit(par(op))
for (j in 1:Jcause){ # <--- the marginal dimension of measurements.
# need to fix this for NoA! <------------------------ FIX!
#
# Figure 1 for case and control positive rates:
#
par(mar=c(2,5,0,1))
op1 <- par(mar=c(2,5,0,1))
on.exit(par(op1))
#<------------------------ FIX!
if (model_options$likelihood$cause_list[j] == "other"){
plot(0,0.5,type="l",ylim=c(0,1),pch="n",
Expand Down Expand Up @@ -376,7 +378,8 @@ plot_etiology_regression <- function(DIR_NPLCM,stratum_bool,slice=1,plot_basis=F
#
# Figure 2 for Etiology Regression:
#
par(mar=c(2,5,0,1))
op2 <- par(mar=c(2,5,0,1))
on.exit(par(op2))
plot(curr_date_Eti,Eti_mean[j,],type="l",ylim=c(0,1),xlab="standardized date",
ylab=c("","etiologic fraction")[(j==1)+1],bty="n",xaxt="n",yaxt="n",las=2)
## ONLY FOR SIMULATIONS <---------------------- FIX!
Expand Down Expand Up @@ -614,6 +617,7 @@ plot_subwt_regression <- function(DIR_NPLCM,stratum_bool,case=0,slice=1,truth=NU
#' @param show_levels a vector of integers less than or equal to the total number of
#' levels of strata; default to `0` for overall.
#' @param is_plot default to TRUE, plotting the figures; if `FALSE` only returning summaries
#' @param VERBOSE default to `TRUE`, print actual meanings of the levels
#' @import graphics ggplot2
#' @importFrom ggpubr ggarrange
#' @importFrom stats aggregate
Expand All @@ -623,7 +627,7 @@ plot_subwt_regression <- function(DIR_NPLCM,stratum_bool,case=0,slice=1,truth=NU
#' @return plotting function
plot_etiology_strat <- function(DIR_NPLCM,strata_weights = "empirical",
truth=NULL,
RES_NPLCM=NULL,show_levels=0,is_plot=TRUE){
RES_NPLCM=NULL,show_levels=0,is_plot=TRUE,VERBOSE=TRUE){
# ### test
# DIR_NPLCM = result_folder_discrete
# strata_weights = "empirical"
Expand Down Expand Up @@ -868,8 +872,12 @@ plot_etiology_strat <- function(DIR_NPLCM,strata_weights = "empirical",
}
}

print("==[baker] actual meanings of levels (by row):")
print(unique_Eti_level)
if(VERBOSE){
print("==[baker] actual meanings of levels (by row):")
print(unique_Eti_level)
}
# this following is plotting, because this is a plotting function to be fed
# into a genric plot function, so we keep it out of VERBOSE if else logic:
print(ggpubr::ggarrange(plotlist=plot_list_show,nrow = length(plot_list_show)))
}

Expand Down
3 changes: 3 additions & 0 deletions R/plot-panels.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ get_plot_num <- function(e, height){
plot_leftmost <- function(model_options,height){

op <- graphics::par(mar=c(5.1,4,4.1,0))
on.exit(par(op))
graphics::plot(rep(0,3*height),
c(sapply(1:height,get_plot_num,height)),
xlim=c(0,0.1),
Expand Down Expand Up @@ -675,6 +676,7 @@ plot_BrS_panel <- function(slice,data_nplcm,model_options,
#
#op <- graphics::par(mar=c(5.1,4.1,4.1,0))
op <- graphics::par(mar=c(5.1,0,4.1,0))
on.exit(par(op))

if (!is_length_all_one(pos_vec)){
#stop("== Not implemented for combo latent status.==")
Expand Down Expand Up @@ -1277,6 +1279,7 @@ plot_SS_panel <- function(slice,data_nplcm,model_options,
# plotting:
#
op <- graphics::par(mar=c(5.1,0,4.1,0))
on.exit(par(op))

if (check_combo_SS){
#stop("== Not implemented for combo latent status.==")
Expand Down
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ visualize_case_control_matrix <- function(mat, dim_names = ncol(mat),
cex_main = min(2,20 / n)
cex_se = min(1.5,15 / n)

graphics::par(mar = c(0, 0, 5, 0), bg = "white",xpd = TRUE)
op <- graphics::par(mar = c(0, 0, 5, 0), bg = "white",xpd = TRUE)
on.exit(par(op))

graphics::plot(
c(0, n + 0.8), c(0, n + 0.8), axes = axes, xlab = "",
ylab = "", asp = 1, type = "n"
Expand Down
4 changes: 2 additions & 2 deletions R/write-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ add_meas_BrS_param_Nest_Slice <- function(s,Mobs,cause_list) { #note: has separa
",r0_nm[s],"[",K_nm[s],"]<-1
for(j in 2:",K_nm[s],") {",Lambda0_nm[s],"[j]<-",r0_nm[s],"[j]*(1-",r0_nm[s],"[j-1])*",Lambda0_nm[s],"[j-1]/",r0_nm[s],"[j-1]}
for(k in 1:(",K_nm[s],"-1)){
",r0_nm[s],"[k]~dbeta(1,",alphadp0_nm[s],")I(0.000001,0.999999)
",r0_nm[s],"[k]~dbeta(1,",alphadp0_nm[s],")T(0.000001,0.999999)
}
for (k in 1:(",K_nm[s],"-1)){",Lambda_nm[s],"[k]<-max(0.000001,min(0.999999,",Lambda0_nm[s],"[k]))}
Expand All @@ -1283,7 +1283,7 @@ add_meas_BrS_param_Nest_Slice <- function(s,Mobs,cause_list) { #note: has separa
",r1_nm[s],"[",K_nm[s],"]<-1
for(j in 2:",K_nm[s],") {",Eta0_nm[s],"[j]<-",r1_nm[s],"[j]*(1-",r1_nm[s],"[j-1])*",Eta0_nm[s],"[j-1]/",r1_nm[s],"[j-1]}
for(k in 1:(",K_nm[s],"-1)){
",r1_nm[s],"[k]~dbeta(1,",alphadp0_case_nm[s],")I(0.000001,0.999999)
",r1_nm[s],"[k]~dbeta(1,",alphadp0_case_nm[s],")T(0.000001,0.999999)
}
for (k in 1:(",K_nm[s],"-1)){",Eta_nm[s],"[k]<-max(0.000001,min(0.999999,",Eta0_nm[s],"[k]))}
Expand Down
28 changes: 25 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
## Resubmission
This is a resubmission. In this version I have:

* 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 was not corrected in time)
* Fixed an issue related to JAGS being updated to 4.3.x
(Package was archived on CRAN because of a tricky interfacing issue between
JAGS 4.3.x and R 4.3.x was not corrected in time); I contacted the author of JAGS and he confirmed the issue
was a bug but will not release a debugged version soon. So I went ahead to fix the issue
in my package; the changes primarily occurred in the `jags2_baker` function which interfaces with
the JAGS. Also JAGS 4.3.x retired a function`cut` so I modified the functoins in `nplcm.R` to accommodate this change.
- And these fixes passes the suggested checks (see Test `Environments` below).

* winbuilder gave a note on new submission and possible misspelling - but because
I was intructed to not put single quotes around these names (which would overcome this issue),
I will leave as is.

- ```
New submission
Package was archived on CRAN
Possibly misspelled words in DESCRIPTION:
Deloria (18:9, 19:9)
Hammitt (18:24)
Zeger (18:37, 19:28)
```

## Reverse dependencies; revdecp_check result `OK: 0` `BROKEN: 0`

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.
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.


## Test environments
Expand Down
5 changes: 4 additions & 1 deletion man/plot_etiology_strat.Rd

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

0 comments on commit 5096733

Please sign in to comment.