diff --git a/DESCRIPTION b/DESCRIPTION index 86bbb09a..f6137551 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: RoBMA Title: Robust Bayesian Meta-Analyses -Version: 2.2.1 +Version: 2.2.2 Maintainer: František Bartoš Authors@R: c( person("František", "Bartoš", role = c("aut", "cre"), @@ -34,7 +34,7 @@ License: GPL-3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 SystemRequirements: JAGS >= 4.3.0 (https://mcmc-jags.sourceforge.io/) NeedsCompilation: yes Depends: diff --git a/NEWS.md b/NEWS.md index afd4303a..db0b02d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## version 2.2.2 +### Fixes +- updating the C++ to compile on M1 Mac + ## version 2.2.1 ### Changes - message about the effect size scale of parameter estimates is always shown diff --git a/R/utilities.R b/R/utilities.R index b57f7ce7..60db7fa5 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -81,12 +81,15 @@ assign("max_cores", parallel::detectCores(logical = TRUE) - 1, envir = Ro "2.1.1" = c("0.1.3", "0.1.3"), "2.1.2" = c("0.1.3", "0.1.3"), "2.2.0" = c("0.1.3", "0.1.3"), - "2.2.1" = c("0.2.3", "0.2.999"), + "2.2.1" = c("0.2.3", "999.999.999"), + "2.2.2" = c("0.2.3", "999.999.999"), stop("New RoBMA version needs to be defined in '.check_BayesTools' function!") ) - min_OK <- all(as.integer(strsplit(BayesTools_required[1], ".", fixed = TRUE)[[1]]) <= unlist(BayesTools.version)) - max_OK <- all(as.integer(strsplit(BayesTools_required[2], ".", fixed = TRUE)[[1]]) >= unlist(BayesTools.version)) + min_OK <- sum(as.numeric(strsplit(BayesTools_required[1], ".", fixed = TRUE)[[1]]) * c(1e9, 1e6, 1e3)) <= + sum(unlist(BayesTools.version) * c(1e9, 1e6, 1e3)) + max_OK <- sum(as.numeric(strsplit(BayesTools_required[2], ".", fixed = TRUE)[[1]]) * c(1e9, 1e6, 1e3)) >= + sum(unlist(BayesTools.version) * c(1e9, 1e6, 1e3)) if(min_OK && max_OK){ return(invisible(TRUE)) diff --git a/README.Rmd b/README.Rmd index 5b26ef45..7ce1d8c0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -6,7 +6,11 @@ output: github_document --- - +```{r include = FALSE, eval = FALSE} +library(RoBMA) +fit <- RoBMA(d = Bem2011$d, se = Bem2011$se, study_names = Bem2011$study, seed = 1) +saveRDS(fit, file = "models/README/Bem2011.RDS") +``` ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, @@ -49,7 +53,7 @@ The package was updated to version 2.0 to provides Bayesian model-averaging acro Please note that the RoBMA 2.0 is not backwards compatible with the previous versions of RoBMA. Use ``` r -remotes::install_version("RoBMA", version = 1.2.1) +remotes::install_version("RoBMA", version = "1.2.1") ``` to install the previous version if needed. (Or use the source packages archived with at OSF repositories associated with the corresponding projects.) diff --git a/README.md b/README.md index f7dbf20f..c36883e8 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,14 @@ heterogeneity, and publication bias components (including selection, PET, and PEESE style models). The package provides convenient functions for summary, visualizations, and fit diagnostics. -See our new pre-print Bartoš, Maier, Wagenmakers, et al. (2021) +See our new pre-print Bartoš et al. (2021) () for the description of the newest version, RoBMA-PSMA, or our previous paper introducing the method Maier et al. (in press) (). The previous version of the methods is also implemented within the the user-friendly graphical user interface of JASP (JASP Team, 2020) and -accompanied by a tutorial paper with more examples (Bartoš, Maier, -Quintana, et al., 2021) (). +accompanied by a tutorial paper with more examples (Bartoš et al., in +press) (). We also prepared multiple vignettes that illustrate functionality of the package: @@ -48,8 +48,7 @@ package: The package was updated to version 2.0 to provides Bayesian model-averaging across selection models and PET-PEESE (as described in -Bartoš, Maier, Wagenmakers, et al. (2021) at -). +Bartoš et al. (2021) at ). ### Backwards Compatibility @@ -57,7 +56,7 @@ Please note that the RoBMA 2.0 is not backwards compatible with the previous versions of RoBMA. Use ``` r -remotes::install_version("RoBMA", version = 1.2.1) +remotes::install_version("RoBMA", version = "1.2.1") ``` to install the previous version if needed. (Or use the source packages @@ -70,11 +69,11 @@ The 2.0 version brings several updates to the package: - naming of the arguments specifying prior distributions for the different parameters/components of the models changed (`priors_mu` - -> `priors_effect`, `priors_tau` -> `priors_heterogeneity`, and - `priors_omega` -> `priors_bias`), + -\> `priors_effect`, `priors_tau` -\> `priors_heterogeneity`, and + `priors_omega` -\> `priors_bias`), - prior distributions for specifying weight functions now use a dedicated function - (`prior(distribution = "two.sided", parameters = ...)` -> + (`prior(distribution = "two.sided", parameters = ...)` -\> `prior_weightfunction(distribution = "two.sided", parameters = ...)`), - new dedicated function for specifying no publication bias adjustment component / no heterogeneity component (`prior_none()`), @@ -84,7 +83,7 @@ The 2.0 version brings several updates to the package: `prior_PEESE(distribution = "Cauchy", parameters = ...)`), - new default prior distribution specification for the publication bias adjustment part of the models (corresponding to the RoBMA-PSMA - model from Bartoš, Maier, Wagenmakers, et al. (2021)), + model from Bartoš et al. (2021)), - new `model_type` argument allowing to specify different “pre-canned” models (`"PSMA"` = RoBMA-PSMA, `"PP"` = RoBMA-PP, `"2w"` = corresponding to Maier et al. (in press)), @@ -120,12 +119,12 @@ devtools::install_github("fbartos/RoBMA") ## Example To illustrate the functionality of the package, we fit the RoBMA-PSMA -model from the example in Bartoš, Maier, Wagenmakers, et al. (2021) to -adjust for publication bias in the infamous Bem (2011) “Feeling the -future” pre-cognition study. The RoBMA-PSMA model combines six selection -models and PET-PEESE to adjust for publication bias. As in the -pre-print, we analyze the data as described by Bem et al. (2011) in his -reply to methodological critiques. +model from the example in Bartoš et al. (2021) to adjust for publication +bias in the infamous Bem (2011) “Feeling the future” pre-cognition +study. The RoBMA-PSMA model combines six selection models and PET-PEESE +to adjust for publication bias. As in the pre-print, we analyze the data +as described by Bem et al. (2011) in his reply to methodological +critiques. First, we load the package and the data set included in the package. @@ -134,7 +133,6 @@ library(RoBMA) #> Loading required namespace: runjags #> Loading required namespace: mvtnorm #> module RoBMA loaded -#> This is a 2.0 version of the RoBMA package (see NEWS for detailed overview of the changes). data("Bem2011", package = "RoBMA") Bem2011 @@ -155,12 +153,14 @@ models (the new default settings of RoBMA fitting function). These models represent all possible combinations of prior distributions for the following components: -- effect size (the mean parameter *μ*) +- effect size (the mean parameter + ![\\mu](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cmu "\mu")) - a spike at zero, representing the null hypothesis of the absence of effect - a standard normal distribution, representing the alternative hypothesis of the presence of effect -- heterogeneity (the heterogeneity parameter *τ*) +- heterogeneity (the heterogeneity parameter + ![\\tau](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctau "\tau")) - a spike at zero, representing the null hypothesis of the absence of heterogeneity (i.e., fixed effect meta-analysis) - an inverse gamma distribution with shape = 1 and scale = 0.15, @@ -195,21 +195,27 @@ inclusion Bayes factor of the ensemble components representing the alternative hypothesis of the presence of the effect, heterogeneity, and publication bias, We can see the data show very weak evidence, barely worth mentioning, against the presence of the effect -(BF10 = 0.479 -> BF01 = 2.09), moderate evidence -for the absence of heterogeneity (BFrf = 0.143 -> -*B**F*fr = 7.00), and strong evidence for the presence of -publication bias (BFpb = 16.32). +(![\\text{BF}\_{10} = 0.479](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctext%7BBF%7D_%7B10%7D%20%3D%200.479 "\text{BF}_{10} = 0.479") +-\> +![\\text{BF}\_{01} = 2.09](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctext%7BBF%7D_%7B01%7D%20%3D%202.09 "\text{BF}_{01} = 2.09")), +moderate evidence for the absence of heterogeneity +(![\\text{BF}\_{\\text{rf}} = 0.143](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctext%7BBF%7D_%7B%5Ctext%7Brf%7D%7D%20%3D%200.143 "\text{BF}_{\text{rf}} = 0.143") +-\> +![BF\_{\\text{fr}} = 7.00](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;BF_%7B%5Ctext%7Bfr%7D%7D%20%3D%207.00 "BF_{\text{fr}} = 7.00")), +and strong evidence for the presence of publication bias +(![\\text{BF}\_{\\text{pb}} = 16.32](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctext%7BBF%7D_%7B%5Ctext%7Bpb%7D%7D%20%3D%2016.32 "\text{BF}_{\text{pb}} = 16.32")). The second table shows model-averaged estimates weighted by the individual models’ posterior probabilities. The mean estimate -*μ* = 0.037, 95% CI \[-0.041, 0.213\], is very close to zero, -corresponding to the a priory expected absence of pre-cognition. The -heterogeneity estimate *τ* has most of its probability mass around zero -due to the higher support of models assuming absence of the -heterogeneity. The parameters omega, representing the publication -weights at each *p*-value interval are decreasing with increasing -*p*-values, showing the publication bias, as well as the non zero PET -and PEESE estimates. +![\\mu =0.037](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cmu%20%3D0.037 "\mu =0.037"), +95% CI \[-0.041, 0.213\], is very close to zero, corresponding to the a +priory expected absence of pre-cognition. The heterogeneity estimate +![\\tau](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctau "\tau") +has most of its probability mass around zero due to the higher support +of models assuming absence of the heterogeneity. The parameters omega, +representing the publication weights at each *p*-value interval are +decreasing with increasing *p*-values, showing the publication bias, as +well as the non zero PET and PEESE estimates. ``` r summary(fit) @@ -236,15 +242,19 @@ summary(fit) #> omega[0.975,1] 0.801 1.000 0.007 1.000 #> PET 0.759 0.000 0.000 2.805 #> PEESE 6.183 0.000 0.000 25.463 +#> The estimates are summarized on the Cohen's d scale (priors were specified on the Cohen's d scale). #> (Estimated publication weights omega correspond to one-sided p-values.) ``` We can visualize the estimated mean and heterogeneity parameters using the `plot.RoBMA()` function. The arrows in both figures represent the -point probability mass at *μ* = 0 and *τ* = 0, corresponding to the null -hypotheses of the absence of effect and heterogeneity, both increasing -in the posterior model probability from 0.5 to 0.676 and 0.875 -respectively. +point probability mass at +![\\mu = 0](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cmu%20%3D%200 "\mu = 0") +and +![\\tau = 0](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ctau%20%3D%200 "\tau = 0"), +corresponding to the null hypotheses of the absence of effect and +heterogeneity, both increasing in the posterior model probability from +0.5 to 0.676 and 0.875 respectively. ``` r plot(fit, parameter = "mu", xlim = c(-0.5, 0.5)) @@ -308,9 +318,11 @@ We can also visualize the MCMC diagnostics using the diagnostics function. The function can display the chains `type = "chain"` / posterior sample densities `type = "densities"`, and averaged auto-correlations `type = "autocorrelation"`. Here, we request the -chains trace plot of the *μ* parameter of the most complex model by -setting `show_models = 36` (the model numbers can be obtained from the -summary function with `type = "models"` argument). +chains trace plot of the +![\\mu](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cmu "\mu") +parameter of the most complex model by setting `show_models = 36` (the +model numbers can be obtained from the summary function with +`type = "models"` argument). ``` r diagnostics(fit, parameter = "mu", type = "chains", show_models = 36) @@ -333,9 +345,10 @@ line-spacing="2">
-Bartoš, F., Maier, M., Quintana, D. S., & Wagenmakers, E.-J. (2021). +Bartoš, F., Maier, M., Quintana, D. S., & Wagenmakers, E.-J. (in press). Adjusting for publication bias in JASP & R – selection models, -PET-PEESE, and robust Bayesian meta-analysis. In *PsyArXiv*. +PET-PEESE, and robust Bayesian meta-analysis. *Advances in Methods and +Practices in Psychological Science*.
@@ -343,8 +356,8 @@ PET-PEESE, and robust Bayesian meta-analysis. In *PsyArXiv*.
Bartoš, F., Maier, M., Wagenmakers, E.-J., Doucouliagos, H., & Stanley, -T. D. (2021). *Need to choose: Robust Bayesian meta-analysis with -competing publication bias adjustment methods*. PsyArXiv. +T. D. (2021). *Robust Bayesian meta-analysis: Model-averaging across +complementary publication bias adjustment methods*. PsyArXiv.
diff --git a/inst/REFERENCES.bib b/inst/REFERENCES.bib index bd128065..5aa58147 100644 --- a/inst/REFERENCES.bib +++ b/inst/REFERENCES.bib @@ -54,7 +54,7 @@ @article{maier2020robust @unpublished{bartos2021no, - title = {Need to choose: {R}obust {B}ayesian meta-analysis with competing publication bias adjustment methods}, + title = {Robust {B}ayesian meta-analysis: {M}odel-averaging across complementary publication bias adjustment methods}, author = {Barto{\v{s}}, Franti{\v{s}}ek and Maier, Maximilian and Wagenmakers, Eric-Jan and Doucouliagos, Hristos and Stanley, Tom D.}, year = {2021}, publisher = {PsyArXiv}, diff --git a/models/CustomEnsembles/Bem_update1.RDS b/models/CustomEnsembles/Bem_update1.RDS index 7248e677..d5e88aeb 100644 Binary files a/models/CustomEnsembles/Bem_update1.RDS and b/models/CustomEnsembles/Bem_update1.RDS differ diff --git a/models/CustomEnsembles/Bem_update2.RDS b/models/CustomEnsembles/Bem_update2.RDS index 92366ef5..0459a483 100644 Binary files a/models/CustomEnsembles/Bem_update2.RDS and b/models/CustomEnsembles/Bem_update2.RDS differ diff --git a/models/MedicineBMA/fit_BMA.RDS b/models/MedicineBMA/fit_BMA.RDS index e1834c72..58d83725 100644 Binary files a/models/MedicineBMA/fit_BMA.RDS and b/models/MedicineBMA/fit_BMA.RDS differ diff --git a/models/MedicineBMA/fit_BMAb.RDS b/models/MedicineBMA/fit_BMAb.RDS index 13051c00..16175514 100644 Binary files a/models/MedicineBMA/fit_BMAb.RDS and b/models/MedicineBMA/fit_BMAb.RDS differ diff --git a/models/MedicineBMA/fit_RoBMA.RDS b/models/MedicineBMA/fit_RoBMA.RDS index fb74b5c1..7b730948 100644 Binary files a/models/MedicineBMA/fit_RoBMA.RDS and b/models/MedicineBMA/fit_RoBMA.RDS differ diff --git a/models/README/Bem2011.RDS b/models/README/Bem2011.RDS index 45963b78..76734fef 100644 Binary files a/models/README/Bem2011.RDS and b/models/README/Bem2011.RDS differ diff --git a/models/ReproducingBMA/PowerPoseEst.RDS b/models/ReproducingBMA/PowerPoseEst.RDS index cc6002ef..80e17fc6 100644 Binary files a/models/ReproducingBMA/PowerPoseEst.RDS and b/models/ReproducingBMA/PowerPoseEst.RDS differ diff --git a/models/ReproducingBMA/PowerPoseTest.RDS b/models/ReproducingBMA/PowerPoseTest.RDS index 3b8d0be2..3707aefd 100644 Binary files a/models/ReproducingBMA/PowerPoseTest.RDS and b/models/ReproducingBMA/PowerPoseTest.RDS differ diff --git a/src/distributions/DMN.cc b/src/distributions/DMN.cc index 601e94be..c0f48c75 100644 --- a/src/distributions/DMN.cc +++ b/src/distributions/DMN.cc @@ -8,32 +8,19 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DMN::dim(vector > const &dims) const + std::vector DMN::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DMN::checkParameterDim (vector > const &dims) const + bool DMN::checkParameterDim (std::vector > const &dims) const { bool sigma_OK = true; // check that sigma and mu dimension matches @@ -42,7 +29,7 @@ namespace jags { return sigma_OK; } - bool DMN::checkParameterValue(vector const &par, vector > const &dims) const + bool DMN::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *sigma = par[1]; @@ -62,8 +49,8 @@ namespace jags { DMN::DMN():ArrayDist("dmnorm", 2) {} - double DMN::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DMN::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -77,8 +64,8 @@ namespace jags { return log_lik; } - void DMN::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DMN::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -86,8 +73,8 @@ namespace jags { } void DMN::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -97,14 +84,14 @@ namespace jags { } void DMN::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DMN::isSupportFixed(vector const &fixmask) const + bool DMN::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DMNv.cc b/src/distributions/DMNv.cc index fb5f2296..8a088b4b 100644 --- a/src/distributions/DMNv.cc +++ b/src/distributions/DMNv.cc @@ -8,33 +8,20 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DMNv::dim(vector > const &dims) const + std::vector DMNv::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DMNv::checkParameterDim (vector > const &dims) const + bool DMNv::checkParameterDim (std::vector > const &dims) const { bool se2_OK = true; // check that standard errors squared and mu dimension matches bool tau2_OK = true; // check that tau squared is a single double @@ -48,7 +35,7 @@ namespace jags { } - bool DMNv::checkParameterValue(vector const &par, vector > const &dims) const + bool DMNv::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *tau2 = par[2]; const double *rho = par[3]; @@ -65,8 +52,8 @@ namespace jags { DMNv::DMNv():ArrayDist("dmnorm_v", 5) {} - double DMNv::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DMNv::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -109,8 +96,8 @@ namespace jags { return log_lik; } - void DMNv::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DMNv::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -118,8 +105,8 @@ namespace jags { } void DMNv::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -129,14 +116,14 @@ namespace jags { } void DMNv::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DMNv::isSupportFixed(vector const &fixmask) const + bool DMNv::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWMN1.cc b/src/distributions/DWMN1.cc index b8a0f71d..ba88f1fe 100644 --- a/src/distributions/DWMN1.cc +++ b/src/distributions/DWMN1.cc @@ -8,34 +8,21 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/wmnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DWMN1::dim(vector > const &dims) const + std::vector DWMN1::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DWMN1::checkParameterDim (vector > const &dims) const + bool DWMN1::checkParameterDim (std::vector > const &dims) const { bool sigma_OK = true; // check that sigma and mu dimension matches @@ -54,7 +41,7 @@ namespace jags { } - bool DWMN1::checkParameterValue(vector const &par, vector > const &dims) const + bool DWMN1::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *sigma = par[1]; @@ -82,8 +69,8 @@ namespace jags { DWMN1::DWMN1():ArrayDist("dwmnorm_1s", 4) {} - double DWMN1::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DWMN1::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -101,8 +88,8 @@ namespace jags { return log_lik; } - void DWMN1::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DWMN1::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -110,8 +97,8 @@ namespace jags { } void DWMN1::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -121,14 +108,14 @@ namespace jags { } void DWMN1::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DWMN1::isSupportFixed(vector const &fixmask) const + bool DWMN1::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWMN1v.cc b/src/distributions/DWMN1v.cc index 83f7d471..78a1b6d6 100644 --- a/src/distributions/DWMN1v.cc +++ b/src/distributions/DWMN1v.cc @@ -8,34 +8,21 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/wmnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DWMN1v::dim(vector > const &dims) const + std::vector DWMN1v::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DWMN1v::checkParameterDim (vector > const &dims) const + bool DWMN1v::checkParameterDim (std::vector > const &dims) const { bool se2_OK = true; // check that standard errors squared and mu dimension matches bool tau2_OK = true; // check that tau squared is a single double @@ -58,7 +45,7 @@ namespace jags { } - bool DWMN1v::checkParameterValue(vector const &par, vector > const &dims) const + bool DWMN1v::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *tau2 = par[2]; const double *rho = par[3]; @@ -83,8 +70,8 @@ namespace jags { DWMN1v::DWMN1v():ArrayDist("dwmnorm_1s_v", 7) {} - double DWMN1v::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DWMN1v::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -132,8 +119,8 @@ namespace jags { return log_lik; } - void DWMN1v::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DWMN1v::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -141,8 +128,8 @@ namespace jags { } void DWMN1v::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -152,14 +139,14 @@ namespace jags { } void DWMN1v::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DWMN1v::isSupportFixed(vector const &fixmask) const + bool DWMN1v::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWMN2.cc b/src/distributions/DWMN2.cc index 835e07ec..6cd19a57 100644 --- a/src/distributions/DWMN2.cc +++ b/src/distributions/DWMN2.cc @@ -8,34 +8,21 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/wmnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DWMN2::dim(vector > const &dims) const + std::vector DWMN2::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DWMN2::checkParameterDim (vector > const &dims) const + bool DWMN2::checkParameterDim (std::vector > const &dims) const { bool sigma_OK = true; // check that sigma and mu dimension matches bool omega_OK = true; // check that omega and crit_x dimension matches @@ -54,7 +41,7 @@ namespace jags { } - bool DWMN2::checkParameterValue(vector const &par, vector > const &dims) const + bool DWMN2::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *sigma = par[1]; const double *omega = par[3]; @@ -81,8 +68,8 @@ namespace jags { DWMN2::DWMN2():ArrayDist("dwmnorm_2s", 4) {} - double DWMN2::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DWMN2::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -100,8 +87,8 @@ namespace jags { return log_lik; } - void DWMN2::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DWMN2::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -109,8 +96,8 @@ namespace jags { } void DWMN2::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -120,14 +107,14 @@ namespace jags { } void DWMN2::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DWMN2::isSupportFixed(vector const &fixmask) const + bool DWMN2::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWMN2v.cc b/src/distributions/DWMN2v.cc index 2f6003ba..49c98b98 100644 --- a/src/distributions/DWMN2v.cc +++ b/src/distributions/DWMN2v.cc @@ -8,34 +8,21 @@ #include #include - #include #include "../source/mnorm.h" #include "../source/wmnorm.h" #include "../source/tools.h" -#include - - -using std::vector; -using std::log; -using std::exp; -using std::sqrt; -using std::fabs; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { - vector DWMN2v::dim(vector > const &dims) const + std::vector DWMN2v::dim(std::vector > const &dims) const { - return vector(1,dims[0][0]); + return std::vector(1,dims[0][0]); } - bool DWMN2v::checkParameterDim (vector > const &dims) const + bool DWMN2v::checkParameterDim (std::vector > const &dims) const { bool se2_OK = true; // check that standard errors squared and mu dimension matches bool tau2_OK = true; // check that tau squared is a single double @@ -58,7 +45,7 @@ namespace jags { } - bool DWMN2v::checkParameterValue(vector const &par, vector > const &dims) const + bool DWMN2v::checkParameterValue(std::vector const &par, std::vector > const &dims) const { const double *tau2 = par[2]; const double *rho = par[3]; @@ -83,8 +70,8 @@ namespace jags { DWMN2v::DWMN2v():ArrayDist("dwmnorm_2s_v", 7) {} - double DWMN2v::logDensity(double const *x, unsigned int length, PDFType type, vector const &par, - vector > const &dims, double const *lower, double const *upper) const + double DWMN2v::logDensity(double const *x, unsigned int length, PDFType type, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // reassign the addresses to pointers const double *mu = par[0]; @@ -132,8 +119,8 @@ namespace jags { return log_lik; } - void DWMN2v::randomSample(double *x, unsigned int length, vector const &par, - vector > const &dims, + void DWMN2v::randomSample(double *x, unsigned int length, std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper, RNG *rng) const { @@ -141,8 +128,8 @@ namespace jags { } void DWMN2v::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector > const &dims) const + std::vector const &par, + std::vector > const &dims) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -152,14 +139,14 @@ namespace jags { } void DWMN2v::typicalValue(double *x, unsigned int length, - vector const &par, - vector > const &dims, + std::vector const &par, + std::vector > const &dims, double const *lower, double const *upper) const { // not implemented } - bool DWMN2v::isSupportFixed(vector const &fixmask) const + bool DWMN2v::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWN1.cc b/src/distributions/DWN1.cc index fd9a82b6..9e7c3788 100644 --- a/src/distributions/DWN1.cc +++ b/src/distributions/DWN1.cc @@ -5,11 +5,6 @@ #include #include -using std::vector; -using std::log; -using std::exp; -using std::fabs; - // define parameters // mu = par[0] @@ -27,17 +22,16 @@ namespace RoBMA { DWN1::DWN1() : VectorDist("dwnorm_1s", 4) {} -bool DWN1::checkParameterLength(vector const &len) const +bool DWN1::checkParameterLength(std::vector const &len) const { // there is one less cut-point then weights return n_crit_x(len) == n_omega(len) - 1; } -bool DWN1::checkParameterValue(vector const &par, - vector const &len) const +bool DWN1::checkParameterValue(std::vector const &par, + std::vector const &len) const { bool omega_OK = true; - bool var_OK; // all omegas are within [0, 1] for(unsigned j = 0; j < (n_omega(len)-1); ++j){ @@ -45,55 +39,52 @@ bool DWN1::checkParameterValue(vector const &par, } // var is positive - var_OK = *par[1] > 0.0; + bool var_OK = *par[1] > 0.0; return omega_OK && var_OK; } double DWN1::logDensity(double const *x, unsigned int length, PDFType type, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { double mu = *par[0]; double var = 1/ *par[1]; - double w; - double nom; double denom = 0; - double denom_sum; - vector denoms; - double log_lik; + double w = -68; + std::vector denoms; // select weight to correspond to the current cut-off if(*x >= crit_x(par)[n_crit_x(len)-1]){ - w = log(omega(par)[n_omega(len)-1]); + w = std::log(omega(par)[n_omega(len)-1]); }else if(*x < crit_x(par)[0]){ - w = log(omega(par)[0]); + w = std::log(omega(par)[0]); }else{ for(unsigned i = 1; i < n_omega(len); ++i){ if( (*x < crit_x(par)[i] ) && (*x >= crit_x(par)[i-1]) ){ - w = log(omega(par)[i]); + w = std::log(omega(par)[i]); break; } } } // compute the nominator - nom = dnorm(*x, mu, sqrt(var), true) + w; + double nom = dnorm(*x, mu, std::sqrt(var), true) + w; // compute the probabilities between cutpoints // the first one - denoms.push_back(pnorm(crit_x(par)[0], mu, sqrt(var), true, false)); + denoms.push_back(pnorm(crit_x(par)[0], mu, std::sqrt(var), true, false)); // check and correct for possibly negative numbers due to numerical imprecision if(denoms[0] < 0.0){ denoms[0] = 0.0; } - denom_sum = denoms[0]; + double denom_sum = denoms[0]; // the ones in the middle if(n_omega(len) > 1){ for(unsigned j = 1; j < n_omega(len) - 1; ++j){ - denoms.push_back(pnorm(crit_x(par)[j], mu, sqrt(var), true, false) - denom_sum); + denoms.push_back(pnorm(crit_x(par)[j], mu, std::sqrt(var), true, false) - denom_sum); // check and correct for possibly negative numbers due to numerical imprecision if(denoms[j] < 0.0){ denoms[j] = 0.0; @@ -110,18 +101,18 @@ double DWN1::logDensity(double const *x, unsigned int length, PDFType type, // weight and sum the denominators for(unsigned k = 0; k < n_omega(len); ++k){ - denom = denom + exp(log(denoms[k]) + log(omega(par)[k])); + denom = denom + std::exp(std::log(denoms[k]) + std::log(omega(par)[k])); } // compute the log likelihood - log_lik = nom-log(denom); + double log_lik = nom-std::log(denom); return log_lik; } void DWN1::randomSample(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper, RNG *rng) const { @@ -129,8 +120,8 @@ void DWN1::randomSample(double *x, unsigned int length, } void DWN1::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector const &len) const + std::vector const &par, + std::vector const &len) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -139,7 +130,7 @@ void DWN1::support(double *lower, double *upper, unsigned int length, } } -unsigned int DWN1::length(vector const &len) const +unsigned int DWN1::length(std::vector const &len) const { // no idea how this works return 1; @@ -147,15 +138,15 @@ unsigned int DWN1::length(vector const &len) const void DWN1::typicalValue(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { // not implemented } -bool DWN1::isSupportFixed(vector const &fixmask) const +bool DWN1::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWN2.cc b/src/distributions/DWN2.cc index fb1ef7e8..eb7e7ec8 100644 --- a/src/distributions/DWN2.cc +++ b/src/distributions/DWN2.cc @@ -4,10 +4,10 @@ #include #include -using std::vector; -using std::log; -using std::exp; -using std::fabs; + + + + // define parameters @@ -26,18 +26,17 @@ namespace RoBMA { DWN2::DWN2() : VectorDist("dwnorm_2s", 4) {} -bool DWN2::checkParameterLength(vector const &len) const +bool DWN2::checkParameterLength(std::vector const &len) const { // there is one less cut-point then weights return n_crit_x(len) == n_omega(len) - 1; } -bool DWN2::checkParameterValue(vector const &par, - vector const &len) const +bool DWN2::checkParameterValue(std::vector const &par, + std::vector const &len) const { bool crit_x_OK = true; bool omega_OK = true; - bool var_OK; // all crit_x must be non-negative for(unsigned i = 1; i < n_crit_x(len); ++i){ @@ -50,59 +49,54 @@ bool DWN2::checkParameterValue(vector const &par, } // var is positive - var_OK = *par[1] > 0.0; + bool var_OK = *par[1] > 0.0; return crit_x_OK && omega_OK && var_OK; } double DWN2::logDensity(double const *x, unsigned int length, PDFType type, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { - double abs_x = fabs(*x); + double abs_x = std::fabs(*x); double mu = *par[0]; double var = 1/ *par[1]; - double w; - double nom; double denom = 0; - double denom_sum; - vector denoms; - double log_lik; - - + double w = -68; + std::vector denoms; // select weight to correspond to the current cut-off if(abs_x >= crit_x(par)[n_crit_x(len)-1]){ - w = log(omega(par)[n_omega(len)-1]); + w = std::log(omega(par)[n_omega(len)-1]); }else if(abs_x < crit_x(par)[0]){ - w = log(omega(par)[0]); + w = std::log(omega(par)[0]); }else{ for(unsigned i = 1; i < n_omega(len); ++i){ if( ( abs_x < crit_x(par)[i] ) && ( abs_x >= crit_x(par)[i-1]) ){ - w = log(omega(par)[i]); + w = std::log(omega(par)[i]); break; } } } // compute the nominator - nom = dnorm(*x, mu, sqrt(var), true) + w; + double nom = dnorm(*x, mu, std::sqrt(var), true) + w; // compute the probabilities between cutpoints // the first one - denoms.push_back(pnorm(crit_x(par)[0], mu, sqrt(var), true, false) - pnorm(-crit_x(par)[0], mu, sqrt(var), true, false)); + denoms.push_back(pnorm(crit_x(par)[0], mu, std::sqrt(var), true, false) - pnorm(-crit_x(par)[0], mu, std::sqrt(var), true, false)); // check and correct for possibly negative numbers due to numerical imprecision if(denoms[0] < 0.0){ denoms[0] = 0.0; } - denom_sum = denoms[0]; + double denom_sum = denoms[0]; // the ones in the middle if(n_omega(len) > 1){ for(unsigned j = 1; j < n_omega(len) - 1; ++j){ - denoms.push_back(pnorm(crit_x(par)[j], mu, sqrt(var), true, false) - pnorm(-crit_x(par)[j], mu, sqrt(var), true, false) - denom_sum); + denoms.push_back(pnorm(crit_x(par)[j], mu, std::sqrt(var), true, false) - pnorm(-crit_x(par)[j], mu, std::sqrt(var), true, false) - denom_sum); // check and correct for possibly negative numbers due to numerical imprecision if(denoms[j] < 0.0){ denoms[j] = 0.0; @@ -119,18 +113,18 @@ double DWN2::logDensity(double const *x, unsigned int length, PDFType type, // weight and sum the denominators for(unsigned k = 0; k < n_omega(len); ++k){ - denom = denom + exp(log(denoms[k]) + log(omega(par)[k])); + denom = denom + std::exp(std::log(denoms[k]) + std::log(omega(par)[k])); } // compute the log likelihood - log_lik = nom-log(denom); + double log_lik = nom-std::log(denom); return log_lik; } void DWN2::randomSample(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper, RNG *rng) const { @@ -138,8 +132,8 @@ void DWN2::randomSample(double *x, unsigned int length, } void DWN2::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector const &len) const + std::vector const &par, + std::vector const &len) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -148,7 +142,7 @@ void DWN2::support(double *lower, double *upper, unsigned int length, } } -unsigned int DWN2::length(vector const &len) const +unsigned int DWN2::length(std::vector const &len) const { // no idea how this works return 1; @@ -156,15 +150,15 @@ unsigned int DWN2::length(vector const &len) const void DWN2::typicalValue(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { // not implemented } -bool DWN2::isSupportFixed(vector const &fixmask) const +bool DWN2::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWT1.cc b/src/distributions/DWT1.cc index 7709abb5..6648c2a7 100644 --- a/src/distributions/DWT1.cc +++ b/src/distributions/DWT1.cc @@ -5,12 +5,6 @@ #include #include -using std::vector; -using std::log; -using std::exp; -using std::fabs; - - // define parameters // df = par[0] // ncp = par[1] @@ -22,65 +16,61 @@ using std::fabs; namespace jags { -namespace RoBMA { +namespace RoBMA { DWT1::DWT1() : VectorDist("dwt_1s", 4) {} -bool DWT1::checkParameterLength(vector const &len) const +bool DWT1::checkParameterLength(std::vector const &len) const { // there is one less cut-point then weights return n_crit_t(len) == n_omega(len) - 1; } -bool DWT1::checkParameterValue(vector const &par, - vector const &len) const +bool DWT1::checkParameterValue(std::vector const &par, + std::vector const &len) const { bool omega_OK = true; - bool df_OK; // all omegas are within [0, 1] for(unsigned j = 0; j < (n_omega(len)-1); ++j){ omega_OK = omega_OK && ( omega(par)[j] >= 0.0 ) && ( omega(par)[j] <= 1.0 ); } - + // df are positive - df_OK = *par[0] > 0.0; + bool df_OK = *par[0] > 0.0; return omega_OK && df_OK; } double DWT1::logDensity(double const *x, unsigned int length, PDFType type, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { double df = *par[0]; double ncp = *par[1]; - double w; - double nom; double denom = 0; - double denom_sum; - vector denoms; - double log_lik; + double w = -68; + std::vector denoms; // select weight to correspond to the current cut-off if(*x >= crit_t(par)[n_crit_t(len)-1]){ - w = log(omega(par)[n_omega(len)-1]); + w = std::log(omega(par)[n_omega(len)-1]); }else if(*x < crit_t(par)[0]){ - w = log(omega(par)[0]); + w = std::log(omega(par)[0]); }else{ for(unsigned i = 1; i < n_omega(len); ++i){ if( (*x < crit_t(par)[i] ) && (*x >= crit_t(par)[i-1]) ){ - w = log(omega(par)[i]); + w = std::log(omega(par)[i]); break; } } } // compute the nominator - nom = dnt(*x, df, ncp, true) + w; + double nom = dnt(*x, df, ncp, true) + w; // compute the probabilities between cutpoints // the first one @@ -88,7 +78,7 @@ double DWT1::logDensity(double const *x, unsigned int length, PDFType type, if(denoms[0] < 0.0){ // check and correct for possibly negative numbers due to numerical imprecission denoms[0] = 0.0; } - denom_sum = denoms[0]; + double denom_sum = denoms[0]; // the ones in the middle if(n_omega(len) > 1){ for(unsigned j = 1; j < n_omega(len) - 1; ++j){ @@ -107,18 +97,18 @@ double DWT1::logDensity(double const *x, unsigned int length, PDFType type, // weight and sum the denominators for(unsigned k = 0; k < n_omega(len); ++k){ - denom = denom + exp(log(denoms[k]) + log(omega(par)[k])); + denom = denom + std::exp(std::log(denoms[k]) + std::log(omega(par)[k])); } // compute the log likelihood - log_lik = nom-log(denom); + double log_lik = nom-std::log(denom); return log_lik; } void DWT1::randomSample(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper, RNG *rng) const { @@ -126,8 +116,8 @@ void DWT1::randomSample(double *x, unsigned int length, } void DWT1::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector const &len) const + std::vector const &par, + std::vector const &len) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -136,7 +126,7 @@ void DWT1::support(double *lower, double *upper, unsigned int length, } } -unsigned int DWT1::length(vector const &len) const +unsigned int DWT1::length(std::vector const &len) const { // no idea how this works return 1; @@ -144,15 +134,15 @@ unsigned int DWT1::length(vector const &len) const void DWT1::typicalValue(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { // not implemented } -bool DWT1::isSupportFixed(vector const &fixmask) const +bool DWT1::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/distributions/DWT2.cc b/src/distributions/DWT2.cc index 13382eea..bf04b462 100644 --- a/src/distributions/DWT2.cc +++ b/src/distributions/DWT2.cc @@ -4,11 +4,6 @@ #include #include -using std::vector; -using std::log; -using std::exp; -using std::fabs; - // define parameters // df = par[0] @@ -21,23 +16,22 @@ using std::fabs; namespace jags { -namespace RoBMA { +namespace RoBMA { DWT2::DWT2() : VectorDist("dwt_2s", 4) {} -bool DWT2::checkParameterLength(vector const &len) const +bool DWT2::checkParameterLength(std::vector const &len) const { // there is one less cut-point then weights return n_crit_t(len) == n_omega(len) - 1; } -bool DWT2::checkParameterValue(vector const &par, - vector const &len) const +bool DWT2::checkParameterValue(std::vector const &par, + std::vector const &len) const { bool crit_t_OK = true; bool omega_OK = true; - bool df_OK; // all crit_t must be non-negative for(unsigned i = 1; i < n_crit_t(len); ++i){ @@ -50,43 +44,40 @@ bool DWT2::checkParameterValue(vector const &par, } // df are positive - df_OK = *par[0] > 0.0; + bool df_OK = *par[0] > 0.0; return crit_t_OK && omega_OK && df_OK; } double DWT2::logDensity(double const *x, unsigned int length, PDFType type, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { - double abs_x = fabs(*x); + double abs_x = std::fabs(*x); double df = *par[0]; double ncp = *par[1]; - double w; - double nom; double denom = 0; - double denom_sum; - vector denoms; - double log_lik; + double w = -68; + std::vector denoms; // select weight to correspond to the current cut-off if(abs_x >= crit_t(par)[n_crit_t(len)-1]){ - w = log(omega(par)[n_omega(len)-1]); + w = std::log(omega(par)[n_omega(len)-1]); }else if(abs_x < crit_t(par)[0]){ - w = log(omega(par)[0]); + w = std::log(omega(par)[0]); }else{ for(unsigned i = 1; i < n_omega(len); ++i){ if( ( abs_x < crit_t(par)[i] ) && ( abs_x >= crit_t(par)[i-1]) ){ - w = log(omega(par)[i]); + w = std::log(omega(par)[i]); break; } } } // compute the nominator - nom = dnt(*x, df, ncp, true) + w; + double nom = dnt(*x, df, ncp, true) + w; // compute the probabilities between cutpoints // the first one @@ -94,7 +85,7 @@ double DWT2::logDensity(double const *x, unsigned int length, PDFType type, if(denoms[0] < 0.0){ // check and correct for possibly negative numbers due to numerical imprecission denoms[0] = 0.0; } - denom_sum = denoms[0]; + double denom_sum = denoms[0]; // the ones in the middle if(n_omega(len) > 1){ for(unsigned j = 1; j < n_omega(len) - 1; ++j){ @@ -113,18 +104,18 @@ double DWT2::logDensity(double const *x, unsigned int length, PDFType type, // weight and sum the denominators for(unsigned k = 0; k < n_omega(len); ++k){ - denom = denom + exp(log(denoms[k]) + log(omega(par)[k])); + denom = denom + std::exp(std::log(denoms[k]) + std::log(omega(par)[k])); } // compute the log likelihood - log_lik = nom-log(denom); + double log_lik = nom-std::log(denom); return log_lik; } void DWT2::randomSample(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper, RNG *rng) const { @@ -132,8 +123,8 @@ void DWT2::randomSample(double *x, unsigned int length, } void DWT2::support(double *lower, double *upper, unsigned int length, - vector const &par, - vector const &len) const + std::vector const &par, + std::vector const &len) const { // no idea whether this is correct for (unsigned int i = 0; i < length; ++i) { @@ -142,7 +133,7 @@ void DWT2::support(double *lower, double *upper, unsigned int length, } } -unsigned int DWT2::length(vector const &len) const +unsigned int DWT2::length(std::vector const &len) const { // no idea how this works return 1; @@ -150,15 +141,15 @@ unsigned int DWT2::length(vector const &len) const void DWT2::typicalValue(double *x, unsigned int length, - vector const &par, - vector const &len, + std::vector const &par, + std::vector const &len, double const *lower, double const *upper) const { // not implemented } -bool DWT2::isSupportFixed(vector const &fixmask) const +bool DWT2::isSupportFixed(std::vector const &fixmask) const { return true; } diff --git a/src/functions/mnorm.cc b/src/functions/mnorm.cc index 04a46772..e0f499ec 100644 --- a/src/functions/mnorm.cc +++ b/src/functions/mnorm.cc @@ -1,16 +1,10 @@ #include "mnorm.h" #include "../source/mnorm.h" -#include #include #include #include -using std::vector; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { @@ -18,7 +12,7 @@ namespace jags { // one-sided multivariate normal mnorm_lpdf::mnorm_lpdf() :ArrayFunction("mnorm_lpdf", 3) {} - void mnorm_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void mnorm_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -32,26 +26,26 @@ namespace jags { *value = cpp_mnorm_lpdf(&x[0], &mu[0], &sigma[0], K);; } - bool mnorm_lpdf::checkParameterDim (vector > const &dims) const + bool mnorm_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool mnorm_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool mnorm_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector mnorm_lpdf::dim(vector > const &dims, vector const &values) const + std::vector mnorm_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } //// vector input type ---- mnorm_v_lpdf::mnorm_v_lpdf() :ArrayFunction("mnorm_v_lpdf", 6) {} - void mnorm_v_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void mnorm_v_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -116,19 +110,19 @@ namespace jags { *value = log_lik; } - bool mnorm_v_lpdf::checkParameterDim (vector > const &dims) const + bool mnorm_v_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool mnorm_v_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool mnorm_v_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector mnorm_v_lpdf::dim(vector > const &dims, vector const &values) const + std::vector mnorm_v_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } } diff --git a/src/functions/wmnorm.cc b/src/functions/wmnorm.cc index 8d054da8..e0aac293 100644 --- a/src/functions/wmnorm.cc +++ b/src/functions/wmnorm.cc @@ -1,16 +1,10 @@ #include "wmnorm.h" #include "../source/wmnorm.h" -#include #include #include #include -using std::vector; -using std::cout; -using std::endl; - - namespace jags { namespace RoBMA { @@ -18,7 +12,7 @@ namespace jags { // one-sided multivariate normal wmnorm_1s_lpdf::wmnorm_1s_lpdf() :ArrayFunction("wmnorm_1s_lpdf", 5) {} - void wmnorm_1s_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void wmnorm_1s_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -35,26 +29,26 @@ namespace jags { *value = cpp_wmnorm_1s_lpdf(&x[0], &mu[0], &sigma[0], &crit_x[0], &omega[0], K, J); } - bool wmnorm_1s_lpdf::checkParameterDim (vector > const &dims) const + bool wmnorm_1s_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool wmnorm_1s_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool wmnorm_1s_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector wmnorm_1s_lpdf::dim(vector > const &dims, vector const &values) const + std::vector wmnorm_1s_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } // two-sided multivariate normal wmnorm_2s_lpdf::wmnorm_2s_lpdf() :ArrayFunction("wmnorm_2s_lpdf", 5) {} - void wmnorm_2s_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void wmnorm_2s_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -71,19 +65,19 @@ namespace jags { *value = cpp_wmnorm_2s_lpdf(&x[0], &mu[0], &sigma[0], &crit_x[0], &omega[0], K, J); } - bool wmnorm_2s_lpdf::checkParameterDim (vector > const &dims) const + bool wmnorm_2s_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool wmnorm_2s_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool wmnorm_2s_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector wmnorm_2s_lpdf::dim(vector > const &dims, vector const &values) const + std::vector wmnorm_2s_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } @@ -91,7 +85,7 @@ namespace jags { // one-sided multivariate normal wmnorm_1s_v_lpdf::wmnorm_1s_v_lpdf() :ArrayFunction("wmnorm_1s_v_lpdf", 8) {} - void wmnorm_1s_v_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void wmnorm_1s_v_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -167,26 +161,26 @@ namespace jags { *value = log_lik; } - bool wmnorm_1s_v_lpdf::checkParameterDim (vector > const &dims) const + bool wmnorm_1s_v_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool wmnorm_1s_v_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool wmnorm_1s_v_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector wmnorm_1s_v_lpdf::dim(vector > const &dims, vector const &values) const + std::vector wmnorm_1s_v_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } // two-sided multivariate normal wmnorm_2s_v_lpdf::wmnorm_2s_v_lpdf() :ArrayFunction("wmnorm_2s_v_lpdf", 8) {} - void wmnorm_2s_v_lpdf::evaluate(double *value, vector const &args, vector > const &dims) const + void wmnorm_2s_v_lpdf::evaluate(double *value, std::vector const &args, std::vector > const &dims) const { // reassign the addresses to pointers const double *x = args[0]; @@ -262,19 +256,19 @@ namespace jags { *value = log_lik; } - bool wmnorm_2s_v_lpdf::checkParameterDim (vector > const &dims) const + bool wmnorm_2s_v_lpdf::checkParameterDim (std::vector > const &dims) const { return true; } - bool wmnorm_2s_v_lpdf::checkParameterValue(vector const &par, vector > const &dims) const + bool wmnorm_2s_v_lpdf::checkParameterValue(std::vector const &par, std::vector > const &dims) const { return true; } - vector wmnorm_2s_v_lpdf::dim(vector > const &dims, vector const &values) const + std::vector wmnorm_2s_v_lpdf::dim(std::vector > const &dims, std::vector const &values) const { - return vector(1,1); + return std::vector(1,1); } } } diff --git a/src/source/mnorm.cc b/src/source/mnorm.cc index bdbbc50a..2b40a65e 100644 --- a/src/source/mnorm.cc +++ b/src/source/mnorm.cc @@ -8,12 +8,6 @@ #include #include #include -#include - -using std::log; -using std::sqrt; -using std::cout; -using std::endl; // wrapper around the mvtnorm package double cpp_mnorm_cdf(double *lower, double *upper, int *infin, double *mu, double *sigma_stdev, double *sigma_corr, int K) @@ -86,7 +80,7 @@ double cpp_mnorm_lpdf(double const *x, double const *mu, double const *sigma, co // product of the diagonal ellements double diag_prod = 0; for(int i = 0; i < K; i++){ - diag_prod += log(*(chol_inv+K*i+i)); + diag_prod += std::log(*(chol_inv+K*i+i)); } // standardized means? (based on arma::inplace_tri_mat_mult) @@ -109,7 +103,7 @@ double cpp_mnorm_lpdf(double const *x, double const *mu, double const *sigma, co // log lik double log_lik = 0; for(int i = 0; i < K; i++){ - log_lik += pow(*(z+i), 2); + log_lik += std::pow(*(z+i), 2); } log_lik = - 0.5 * log_lik + diag_prod - K * 0.9189385; @@ -133,8 +127,8 @@ void chol(double const *matrix, const int n, double *lower) if (j == i) { // summation for diagnols for (int k = 0; k < j; k++) - sum += pow(lower[n*j+k], 2); - lower[n*j+j] = sqrt(*(matrix+n*j+j) - sum); + sum += std::pow(lower[n*j+k], 2); + lower[n*j+j] = std::sqrt(*(matrix+n*j+j) - sum); } else { // Evaluating L(i, j) using L(j, j) for (int k = 0; k < j; k++) diff --git a/src/source/tools.cc b/src/source/tools.cc index 39d14f42..57cf3e6a 100644 --- a/src/source/tools.cc +++ b/src/source/tools.cc @@ -4,17 +4,10 @@ #include "mnorm.h" -#include - -using std::log; -using std::fabs; -using std::cout; -using std::endl; - // assigns log of weights product corresponding to the outcome x based on a one-sided weightfunction double log_weight_onesided(double const *x, double const *crit_x, double const *omega, const int J) { - double w; + double w = -68; if(*x >= *(crit_x + J - 2)){ // return the last omega if x > last crit_x @@ -32,14 +25,14 @@ double log_weight_onesided(double const *x, double const *crit_x, double const * } } - return log(w); + return std::log(w); } // assigns log of weights product corresponding to the outcome x based on a two-sided weightfunction double log_weight_twosided(double const *x, double const *crit_x, double const *omega, const int J) { - double w; - double abs_x = fabs(*x); + double w = -68; + double abs_x = std::fabs(*x); if(abs_x >= *(crit_x + J - 2)){ // return the last omega if abs(x) > last crit_x @@ -56,7 +49,7 @@ double log_weight_twosided(double const *x, double const *crit_x, double const * } } } - return log(w); + return std::log(w); } @@ -74,12 +67,12 @@ double log_std_constant_onesided(double const *x, double const *const_mu, double mu = new double [K]; for(int k = 0; k < K; k++){ - *(sigma_stdev + k) = sqrt( *(sigma+ K * k + k) ); + *(sigma_stdev + k) = std::sqrt( *(sigma+ K * k + k) ); *(mu + k) = *(const_mu + k); } for(int k = 0; k < K; k++){ for(int j = 0; j < K && j < k; j++){ - *(sigma_corr + k * (k - 1) / 2 + j) = *(sigma + K * k + j) / sqrt( *(sigma + K * k + k) * *(sigma + K * j + j)); + *(sigma_corr + k * (k - 1) / 2 + j) = *(sigma + K * k + j) / std::sqrt( *(sigma + K * k + k) * *(sigma + K * j + j)); } } @@ -103,7 +96,7 @@ double log_std_constant_onesided(double const *x, double const *const_mu, double } // iterate over all subspaces created by the cutpoints - for(int i = 0; i < pow(J, K); i++){ + for(int i = 0; i < std::pow(J, K); i++){ // reset the current weight temp_log_weight = 0; @@ -112,7 +105,7 @@ double log_std_constant_onesided(double const *x, double const *const_mu, double for(int k = 0; k < K; k++){ // weight - temp_log_weight += log(*(omega + *(index_weights + k))); + temp_log_weight += std::log(*(omega + *(index_weights + k))); // the upper and lower bounds if(*(index_weights + k) == 0){ @@ -136,11 +129,11 @@ double log_std_constant_onesided(double const *x, double const *const_mu, double double temp_prob = cpp_mnorm_cdf(&temp_lower[0], &temp_upper[0], &temp_infin[0], &mu[0], &sigma_stdev[0], &sigma_corr[0], K); // check and skip negative numbers due to numerical impressions for very low probabilities if(temp_prob > 0){ - std_constant += exp(log(temp_prob) + temp_log_weight); + std_constant += std::exp(std::log(temp_prob) + temp_log_weight); } // increase index for the next iteration - if((i + 1) < pow(J, K)){ + if((i + 1) < std::pow(J, K)){ increase_index( &index_weights[0], K-1, J-1); } } @@ -154,7 +147,7 @@ double log_std_constant_onesided(double const *x, double const *const_mu, double delete[] temp_infin; delete[] index_weights; - return log(std_constant); + return std::log(std_constant); } diff --git a/src/source/transformations.cc b/src/source/transformations.cc index ac58a06e..73fd8bbd 100644 --- a/src/source/transformations.cc +++ b/src/source/transformations.cc @@ -3,11 +3,6 @@ #include #include -using std::exp; -using std::sqrt; -using std::pow; -using std::log; - double pi(){ return 3.14159265358979323846; } @@ -15,22 +10,22 @@ double pi(){ // based on Borenstein, M., Hedges, L. V., Higgins, J. P., & Rothstein, H. R. (2011). Introduction to meta-analysis. John Wiley & Sons. // main effect size transformation functions double cpp_d2r (double d){ - return d / sqrt(pow(d, 2) + 4); + return d / std::sqrt(std::pow(d, 2) + 4); } double cpp_d2logOR (double d){ - return d * pi() / sqrt(3); + return d * pi() / std::sqrt(3); } double cpp_r2d (double r){ - return 2 * r / sqrt( 1 - pow(r, 2) ); + return 2 * r / std::sqrt( 1 - std::pow(r, 2) ); } double cpp_r2z (double r){ - return 0.5 * log( (1 + r) / (1 - r) ); + return 0.5 * std::log( (1 + r) / (1 - r) ); } double cpp_logOR2d (double logOR){ - return logOR * sqrt(3)/pi(); + return logOR * std::sqrt(3)/pi(); } double cpp_z2r (double z){ - return (exp(2 * z) - 1) / (1 + exp(2 * z)); + return (std::exp(2 * z) - 1) / (1 + std::exp(2 * z)); } // composite functions @@ -55,16 +50,16 @@ double cpp_z2logOR (double z){ // main standard error transformation functions double cpp_se_d2se_logOR (double se_d){ - return sqrt(pow(se_d, 2) * pow(pi(), 2) / 3); + return std::sqrt(std::pow(se_d, 2) * std::pow(pi(), 2) / 3); } double cpp_se_d2se_r (double se_d, double d){ - return sqrt( (pow(4, 2) * pow(se_d, 2)) / pow( pow(d, 2) + 4, 3) ); + return std::sqrt( (std::pow(4, 2) * std::pow(se_d, 2)) / std::pow( std::pow(d, 2) + 4, 3) ); } double cpp_se_r2se_d (double se_r, double r){ - return sqrt( (4 * pow(se_r, 2)) / pow( 1 - pow(r, 2), 3) ); + return std::sqrt( (4 * std::pow(se_r, 2)) / std::pow( 1 - std::pow(r, 2), 3) ); } double cpp_se_logOR2se_d (double se_logOR){ - return sqrt( pow(se_logOR, 2) * 3 / pow(pi(), 2) ); + return std::sqrt( std::pow(se_logOR, 2) * 3 / std::pow(pi(), 2) ); } // composite standard error transformation functions @@ -107,13 +102,13 @@ double cpp_se_z2se_logOR (double se_z, double z){ // linear scaling function double cpp_scale_d2logOR (double d){ - return d * (pi()/sqrt(3)); + return d * (pi()/std::sqrt(3)); } double cpp_scale_d2z (double d){ return d / 2; } double cpp_scale_logOR2d (double logOR){ - return logOR / (pi()/sqrt(3)); + return logOR / (pi()/std::sqrt(3)); } double cpp_scale_z2d (double z){ return z * 2; @@ -149,7 +144,7 @@ double cpp_scale_logOR2r (double logOR){ // helper functions double cpp_n_d (double d, double se){ - return (pow(d,2) + 8) / (2 * pow(se,2)); + return (std::pow(d,2) + 8) / (2 * std::pow(se,2)); } double cpp_n_r (double r, double se){ // (r^4 - 2*r^2 + se^2 + 1)/se^2 : according to the Borenstein, however, it is not consistent with the remaining @@ -158,17 +153,17 @@ double cpp_n_r (double r, double se){ return cpp_n_d(d, se_d); } double cpp_n_z (double se){ - return (3 * pow(se,2) + 1) / pow(se,2); + return (3 * std::pow(se,2) + 1) / std::pow(se,2); } double cpp_se_d (double d, double n){ - return sqrt( 4 / n + pow(d,2) / ( 2 * n)); + return std::sqrt( 4 / n + std::pow(d,2) / ( 2 * n)); } double cpp_se_r (double r, double n){ - // sqrt((1-r^2)^2/(n-1)) : according to the Borenstein, however, it is not consistent with the remaining transformations + // std::sqrt((1-r^2)^2/(n-1)) : according to the Borenstein, however, it is not consistent with the remaining transformations double d = cpp_r2d(r); double se_d = cpp_se_d(d, n); return cpp_se_d2se_r(se_d, d); } double cpp_se_z (double n){ - return sqrt( 1 / (n - 3)); + return std::sqrt( 1 / (n - 3)); } diff --git a/src/source/wmnorm.cc b/src/source/wmnorm.cc index 7f6ec532..83847c5c 100644 --- a/src/source/wmnorm.cc +++ b/src/source/wmnorm.cc @@ -1,14 +1,11 @@ #include "wmnorm.h" #include "mnorm.h" #include "tools.h" -#include + #include #include #include -using std::cout; -using std::endl; - double cpp_wmnorm_1s_lpdf(double const *x, double const *mu, double const *sigma, double const *crit_x, double const *omega, const int K, const int J) { diff --git a/src/transformations/d.cc b/src/transformations/d.cc index 63d8bffa..1c126ad6 100644 --- a/src/transformations/d.cc +++ b/src/transformations/d.cc @@ -4,7 +4,7 @@ #include #include -using std::vector; + namespace jags { namespace RoBMA { @@ -12,33 +12,33 @@ namespace jags { // effect sizes transformations d2r::d2r() :ScalarFunction("d2r", 1) {} - bool d2r::checkParameterValue(vector const &args) const + bool d2r::checkParameterValue(std::vector const &args) const { return(true); } - double d2r::evaluate(vector const &args) const + double d2r::evaluate(std::vector const &args) const { return cpp_d2r(*args[0]); } d2z::d2z() :ScalarFunction("d2z", 1) {} - bool d2z::checkParameterValue(vector const &args) const + bool d2z::checkParameterValue(std::vector const &args) const { return(true); } - double d2z::evaluate(vector const &args) const + double d2z::evaluate(std::vector const &args) const { return cpp_d2z(*args[0]); } d2logOR::d2logOR() :ScalarFunction("d2logOR", 1) {} - bool d2logOR::checkParameterValue(vector const &args) const + bool d2logOR::checkParameterValue(std::vector const &args) const { return(true); } - double d2logOR::evaluate(vector const &args) const + double d2logOR::evaluate(std::vector const &args) const { return cpp_d2logOR(*args[0]); } @@ -46,33 +46,33 @@ namespace jags { // standard errors transformations se_d2se_r::se_d2se_r() :ScalarFunction("se_d2se_r", 2) {} - bool se_d2se_r::checkParameterValue(vector const &args) const + bool se_d2se_r::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_d2se_r::evaluate(vector const &args) const + double se_d2se_r::evaluate(std::vector const &args) const { return cpp_se_d2se_r(*args[0], *args[1]); } se_d2se_z::se_d2se_z() :ScalarFunction("se_d2se_z", 2) {} - bool se_d2se_z::checkParameterValue(vector const &args) const + bool se_d2se_z::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0 && cpp_n_d(*args[1], *args[0]) > 3); } - double se_d2se_z::evaluate(vector const &args) const + double se_d2se_z::evaluate(std::vector const &args) const { return cpp_se_d2se_z(*args[0], *args[1]); } se_d2se_logOR::se_d2se_logOR() :ScalarFunction("se_d2se_logOR", 2) {} - bool se_d2se_logOR::checkParameterValue(vector const &args) const + bool se_d2se_logOR::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_d2se_logOR::evaluate(vector const &args) const + double se_d2se_logOR::evaluate(std::vector const &args) const { return cpp_se_d2se_logOR(*args[0]); } @@ -80,33 +80,33 @@ namespace jags { // linear scaling function scale_d2z::scale_d2z() :ScalarFunction("scale_d2z", 1) {} - bool scale_d2z::checkParameterValue(vector const &args) const + bool scale_d2z::checkParameterValue(std::vector const &args) const { return(true); } - double scale_d2z::evaluate(vector const &args) const + double scale_d2z::evaluate(std::vector const &args) const { return cpp_scale_d2z(*args[0]); } scale_d2logOR::scale_d2logOR() :ScalarFunction("scale_d2logOR", 1) {} - bool scale_d2logOR::checkParameterValue(vector const &args) const + bool scale_d2logOR::checkParameterValue(std::vector const &args) const { return(true); } - double scale_d2logOR::evaluate(vector const &args) const + double scale_d2logOR::evaluate(std::vector const &args) const { return cpp_scale_d2logOR(*args[0]); } scale_d2r::scale_d2r() :ScalarFunction("scale_d2r", 1) {} - bool scale_d2r::checkParameterValue(vector const &args) const + bool scale_d2r::checkParameterValue(std::vector const &args) const { return(true); } - double scale_d2r::evaluate(vector const &args) const + double scale_d2r::evaluate(std::vector const &args) const { return cpp_scale_d2r(*args[0]); } diff --git a/src/transformations/logOR.cc b/src/transformations/logOR.cc index e6263241..f28f198b 100644 --- a/src/transformations/logOR.cc +++ b/src/transformations/logOR.cc @@ -4,7 +4,7 @@ #include #include -using std::vector; + namespace jags { namespace RoBMA { @@ -12,33 +12,33 @@ namespace jags { // effect sizes transformations logOR2d::logOR2d() :ScalarFunction("logOR2d", 1) {} - bool logOR2d::checkParameterValue(vector const &args) const + bool logOR2d::checkParameterValue(std::vector const &args) const { return(true); } - double logOR2d::evaluate(vector const &args) const + double logOR2d::evaluate(std::vector const &args) const { return cpp_logOR2d(*args[0]); } logOR2z::logOR2z() :ScalarFunction("logOR2z", 1) {} - bool logOR2z::checkParameterValue(vector const &args) const + bool logOR2z::checkParameterValue(std::vector const &args) const { return(true); } - double logOR2z::evaluate(vector const &args) const + double logOR2z::evaluate(std::vector const &args) const { return cpp_logOR2z(*args[0]); } logOR2r::logOR2r() :ScalarFunction("logOR2r", 1) {} - bool logOR2r::checkParameterValue(vector const &args) const + bool logOR2r::checkParameterValue(std::vector const &args) const { return(true); } - double logOR2r::evaluate(vector const &args) const + double logOR2r::evaluate(std::vector const &args) const { return cpp_logOR2r(*args[0]); } @@ -46,33 +46,33 @@ namespace jags { // standard errors transformations se_logOR2se_d::se_logOR2se_d() :ScalarFunction("se_logOR2se_d", 2) {} - bool se_logOR2se_d::checkParameterValue(vector const &args) const + bool se_logOR2se_d::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_logOR2se_d::evaluate(vector const &args) const + double se_logOR2se_d::evaluate(std::vector const &args) const { return cpp_se_logOR2se_d(*args[0]); } se_logOR2se_z::se_logOR2se_z() :ScalarFunction("se_logOR2se_z", 2) {} - bool se_logOR2se_z::checkParameterValue(vector const &args) const + bool se_logOR2se_z::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_logOR2se_z::evaluate(vector const &args) const + double se_logOR2se_z::evaluate(std::vector const &args) const { return cpp_se_logOR2se_z(*args[0], *args[1]); } se_logOR2se_r::se_logOR2se_r() :ScalarFunction("se_logOR2se_r", 2) {} - bool se_logOR2se_r::checkParameterValue(vector const &args) const + bool se_logOR2se_r::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_logOR2se_r::evaluate(vector const &args) const + double se_logOR2se_r::evaluate(std::vector const &args) const { return cpp_se_logOR2se_r(*args[0], *args[1]); } @@ -80,33 +80,33 @@ namespace jags { // linear scaling function scale_logOR2d::scale_logOR2d() :ScalarFunction("scale_logOR2d", 1) {} - bool scale_logOR2d::checkParameterValue(vector const &args) const + bool scale_logOR2d::checkParameterValue(std::vector const &args) const { return(true); } - double scale_logOR2d::evaluate(vector const &args) const + double scale_logOR2d::evaluate(std::vector const &args) const { return cpp_scale_logOR2d(*args[0]); } scale_logOR2z::scale_logOR2z() :ScalarFunction("scale_logOR2z", 1) {} - bool scale_logOR2z::checkParameterValue(vector const &args) const + bool scale_logOR2z::checkParameterValue(std::vector const &args) const { return(true); } - double scale_logOR2z::evaluate(vector const &args) const + double scale_logOR2z::evaluate(std::vector const &args) const { return cpp_scale_logOR2z(*args[0]); } scale_logOR2r::scale_logOR2r() :ScalarFunction("scale_logOR2r", 1) {} - bool scale_logOR2r::checkParameterValue(vector const &args) const + bool scale_logOR2r::checkParameterValue(std::vector const &args) const { return(true); } - double scale_logOR2r::evaluate(vector const &args) const + double scale_logOR2r::evaluate(std::vector const &args) const { return cpp_scale_logOR2r(*args[0]); } diff --git a/src/transformations/r.cc b/src/transformations/r.cc index 4c0bc403..8198eb2e 100644 --- a/src/transformations/r.cc +++ b/src/transformations/r.cc @@ -4,8 +4,8 @@ #include #include -using std::vector; -using std::fabs; + + namespace jags { namespace RoBMA { @@ -13,33 +13,33 @@ namespace jags { // effect sizes transformations r2d::r2d() :ScalarFunction("r2d", 1) {} - bool r2d::checkParameterValue(vector const &args) const + bool r2d::checkParameterValue(std::vector const &args) const { - return(fabs(*args[0]) < 1); + return(std::fabs(*args[0]) < 1); } - double r2d::evaluate(vector const &args) const + double r2d::evaluate(std::vector const &args) const { return cpp_r2d(*args[0]); } r2z::r2z() :ScalarFunction("r2z", 1) {} - bool r2z::checkParameterValue(vector const &args) const + bool r2z::checkParameterValue(std::vector const &args) const { - return(fabs(*args[0]) < 1); + return(std::fabs(*args[0]) < 1); } - double r2z::evaluate(vector const &args) const + double r2z::evaluate(std::vector const &args) const { return cpp_r2z(*args[0]); } r2logOR::r2logOR() :ScalarFunction("r2logOR", 1) {} - bool r2logOR::checkParameterValue(vector const &args) const + bool r2logOR::checkParameterValue(std::vector const &args) const { - return(fabs(*args[0]) < 1); + return(std::fabs(*args[0]) < 1); } - double r2logOR::evaluate(vector const &args) const + double r2logOR::evaluate(std::vector const &args) const { return cpp_r2logOR(*args[0]); } @@ -47,33 +47,33 @@ namespace jags { // standard errors transformations se_r2se_d::se_r2se_d() :ScalarFunction("se_r2se_d", 2) {} - bool se_r2se_d::checkParameterValue(vector const &args) const + bool se_r2se_d::checkParameterValue(std::vector const &args) const { - return(*args[0] >= 0 && fabs(*args[1]) < 1); + return(*args[0] >= 0 && std::fabs(*args[1]) < 1); } - double se_r2se_d::evaluate(vector const &args) const + double se_r2se_d::evaluate(std::vector const &args) const { return cpp_se_r2se_d(*args[0], *args[1]); } se_r2se_z::se_r2se_z() :ScalarFunction("se_r2se_z", 2) {} - bool se_r2se_z::checkParameterValue(vector const &args) const + bool se_r2se_z::checkParameterValue(std::vector const &args) const { - return(*args[0] >= 0 && fabs(*args[1]) < 1 && cpp_n_r(*args[1], *args[0]) > 3); + return(*args[0] >= 0 && std::fabs(*args[1]) < 1 && cpp_n_r(*args[1], *args[0]) > 3); } - double se_r2se_z::evaluate(vector const &args) const + double se_r2se_z::evaluate(std::vector const &args) const { return cpp_se_r2se_z(*args[0], *args[1]); } se_r2se_logOR::se_r2se_logOR() :ScalarFunction("se_r2se_logOR", 2) {} - bool se_r2se_logOR::checkParameterValue(vector const &args) const + bool se_r2se_logOR::checkParameterValue(std::vector const &args) const { - return(*args[0] >= 0 && fabs(*args[1]) < 1); + return(*args[0] >= 0 && std::fabs(*args[1]) < 1); } - double se_r2se_logOR::evaluate(vector const &args) const + double se_r2se_logOR::evaluate(std::vector const &args) const { return cpp_se_r2se_logOR(*args[0], *args[1]); } @@ -81,33 +81,33 @@ namespace jags { // linear scaling function (not used, for completeness) scale_r2d::scale_r2d() :ScalarFunction("scale_r2d", 1) {} - bool scale_r2d::checkParameterValue(vector const &args) const + bool scale_r2d::checkParameterValue(std::vector const &args) const { return(true); } - double scale_r2d::evaluate(vector const &args) const + double scale_r2d::evaluate(std::vector const &args) const { return cpp_scale_r2d(*args[0]); } scale_r2z::scale_r2z() :ScalarFunction("scale_r2z", 1) {} - bool scale_r2z::checkParameterValue(vector const &args) const + bool scale_r2z::checkParameterValue(std::vector const &args) const { return(true); } - double scale_r2z::evaluate(vector const &args) const + double scale_r2z::evaluate(std::vector const &args) const { return cpp_scale_r2z(*args[0]); } scale_r2logOR::scale_r2logOR() :ScalarFunction("scale_r2logOR", 1) {} - bool scale_r2logOR::checkParameterValue(vector const &args) const + bool scale_r2logOR::checkParameterValue(std::vector const &args) const { return(true); } - double scale_r2logOR::evaluate(vector const &args) const + double scale_r2logOR::evaluate(std::vector const &args) const { return cpp_scale_r2logOR(*args[0]); } diff --git a/src/transformations/z.cc b/src/transformations/z.cc index 61b0c85c..920407a1 100644 --- a/src/transformations/z.cc +++ b/src/transformations/z.cc @@ -4,7 +4,7 @@ #include #include -using std::vector; + namespace jags { namespace RoBMA { @@ -12,33 +12,33 @@ namespace jags { // effect sizes transformations z2d::z2d() :ScalarFunction("z2d", 1) {} - bool z2d::checkParameterValue(vector const &args) const + bool z2d::checkParameterValue(std::vector const &args) const { return(true); } - double z2d::evaluate(vector const &args) const + double z2d::evaluate(std::vector const &args) const { return cpp_z2d(*args[0]); } z2r::z2r() :ScalarFunction("z2r", 1) {} - bool z2r::checkParameterValue(vector const &args) const + bool z2r::checkParameterValue(std::vector const &args) const { return(true); } - double z2r::evaluate(vector const &args) const + double z2r::evaluate(std::vector const &args) const { return cpp_z2r(*args[0]); } z2logOR::z2logOR() :ScalarFunction("z2logOR", 1) {} - bool z2logOR::checkParameterValue(vector const &args) const + bool z2logOR::checkParameterValue(std::vector const &args) const { return(true); } - double z2logOR::evaluate(vector const &args) const + double z2logOR::evaluate(std::vector const &args) const { return cpp_z2logOR(*args[0]); } @@ -46,33 +46,33 @@ namespace jags { // standard errors transformations se_z2se_d::se_z2se_d() :ScalarFunction("se_z2se_d", 2) {} - bool se_z2se_d::checkParameterValue(vector const &args) const + bool se_z2se_d::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_z2se_d::evaluate(vector const &args) const + double se_z2se_d::evaluate(std::vector const &args) const { return cpp_se_z2se_d(*args[0], *args[1]); } se_z2se_r::se_z2se_r() :ScalarFunction("se_z2se_r", 2) {} - bool se_z2se_r::checkParameterValue(vector const &args) const + bool se_z2se_r::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_z2se_r::evaluate(vector const &args) const + double se_z2se_r::evaluate(std::vector const &args) const { return cpp_se_z2se_r(*args[0], *args[1]); } se_z2se_logOR::se_z2se_logOR() :ScalarFunction("se_z2se_logOR", 2) {} - bool se_z2se_logOR::checkParameterValue(vector const &args) const + bool se_z2se_logOR::checkParameterValue(std::vector const &args) const { return(*args[0] >= 0); } - double se_z2se_logOR::evaluate(vector const &args) const + double se_z2se_logOR::evaluate(std::vector const &args) const { return cpp_se_z2se_logOR(*args[0], *args[1]); } @@ -80,33 +80,33 @@ namespace jags { // linear scaling function scale_z2d::scale_z2d() :ScalarFunction("scale_z2d", 1) {} - bool scale_z2d::checkParameterValue(vector const &args) const + bool scale_z2d::checkParameterValue(std::vector const &args) const { return(true); } - double scale_z2d::evaluate(vector const &args) const + double scale_z2d::evaluate(std::vector const &args) const { return cpp_scale_z2d(*args[0]); } scale_z2logOR::scale_z2logOR() :ScalarFunction("scale_z2logOR", 1) {} - bool scale_z2logOR::checkParameterValue(vector const &args) const + bool scale_z2logOR::checkParameterValue(std::vector const &args) const { return(true); } - double scale_z2logOR::evaluate(vector const &args) const + double scale_z2logOR::evaluate(std::vector const &args) const { return cpp_scale_z2logOR(*args[0]); } scale_z2r::scale_z2r() :ScalarFunction("scale_z2r", 1) {} - bool scale_z2r::checkParameterValue(vector const &args) const + bool scale_z2r::checkParameterValue(std::vector const &args) const { return(true); } - double scale_z2r::evaluate(vector const &args) const + double scale_z2r::evaluate(std::vector const &args) const { return cpp_scale_z2r(*args[0]); } diff --git a/tests/results/fits/fit_1.RDS b/tests/results/fits/fit_1.RDS index 50ab355e..6f598a5c 100644 Binary files a/tests/results/fits/fit_1.RDS and b/tests/results/fits/fit_1.RDS differ diff --git a/tests/results/fits/fit_10.RDS b/tests/results/fits/fit_10.RDS index 4a15e171..a4286604 100644 Binary files a/tests/results/fits/fit_10.RDS and b/tests/results/fits/fit_10.RDS differ diff --git a/tests/results/fits/fit_11.RDS b/tests/results/fits/fit_11.RDS index fa3de4ed..2e6a937d 100644 Binary files a/tests/results/fits/fit_11.RDS and b/tests/results/fits/fit_11.RDS differ diff --git a/tests/results/fits/fit_12.RDS b/tests/results/fits/fit_12.RDS index d7755251..3554b1aa 100644 Binary files a/tests/results/fits/fit_12.RDS and b/tests/results/fits/fit_12.RDS differ diff --git a/tests/results/fits/fit_13.RDS b/tests/results/fits/fit_13.RDS index 9f70d65e..27ef4809 100644 Binary files a/tests/results/fits/fit_13.RDS and b/tests/results/fits/fit_13.RDS differ diff --git a/tests/results/fits/fit_2.RDS b/tests/results/fits/fit_2.RDS index ca39ec1b..3cb3aad7 100644 Binary files a/tests/results/fits/fit_2.RDS and b/tests/results/fits/fit_2.RDS differ diff --git a/tests/results/fits/fit_3.RDS b/tests/results/fits/fit_3.RDS index 90c7d585..247b76c4 100644 Binary files a/tests/results/fits/fit_3.RDS and b/tests/results/fits/fit_3.RDS differ diff --git a/tests/results/fits/fit_4.RDS b/tests/results/fits/fit_4.RDS index a4e0242e..426f852e 100644 Binary files a/tests/results/fits/fit_4.RDS and b/tests/results/fits/fit_4.RDS differ diff --git a/tests/results/fits/fit_5.RDS b/tests/results/fits/fit_5.RDS index 56e8ec35..47ee2eaf 100644 Binary files a/tests/results/fits/fit_5.RDS and b/tests/results/fits/fit_5.RDS differ diff --git a/tests/results/fits/fit_6.RDS b/tests/results/fits/fit_6.RDS index eda254a6..09f86f78 100644 Binary files a/tests/results/fits/fit_6.RDS and b/tests/results/fits/fit_6.RDS differ diff --git a/tests/results/fits/fit_7.RDS b/tests/results/fits/fit_7.RDS index ba90c0ec..72074a61 100644 Binary files a/tests/results/fits/fit_7.RDS and b/tests/results/fits/fit_7.RDS differ diff --git a/tests/results/fits/fit_9.RDS b/tests/results/fits/fit_9.RDS index 0fe2d218..9081fece 100644 Binary files a/tests/results/fits/fit_9.RDS and b/tests/results/fits/fit_9.RDS differ