Skip to content
Permalink
Browse files

0.3.0.9001

  • Loading branch information...
oeysan committed Dec 4, 2018
1 parent 07ad6d5 commit bd3aee4d33994422ef3d7e63abeaae408c6e03ab
Showing with 130 additions and 29 deletions.
  1. +6 −7 .travis.yml
  2. +3 −3 DESCRIPTION
  3. +6 −0 NAMESPACE
  4. +11 −1 NEWS.md
  5. +5 −3 R/basic_functions.R
  6. +51 −6 R/mcmc_misc.R
  7. +4 −4 README.md
  8. +2 −2 man/ComputeHDI.Rd
  9. +5 −3 man/ETA.Rd
  10. +37 −0 man/InverseHDI.Rd
@@ -2,7 +2,9 @@

language: r
sudo: required

cache: packages

jdk:
- oraclejdk8
- oraclejdk9
@@ -27,15 +29,13 @@ env:
- R_CHECK_FORCE_SUGGESTS_=false
- R_CHECK_ARGS=--no-manual --as-cran

r_github_packages:
- Rexamine/stringi

apt_packages:
- libv8-dev

r_packages:
- covr
- circlize
- devtools
- dplyr
- ggplot2
- knitr
@@ -50,15 +50,14 @@ r_packages:
- scales
- testthat

r_github_packages:
- Rexamine/stringi

notifications:
email:
on_success: change
on_failure: change

r_github_packages:
- r-lib/covr
- r-lib/devtools

after_success:
- Rscript -e 'covr::coveralls()'
- Rscript -e 'covr::codecov(type = "all")'
@@ -1,6 +1,6 @@
Package: bfw
Version: 0.3.0
Date: 2018-11-04
Version: 0.3.0.9001
Date: 2018-12-04
Title: Bayesian Framework for Computational Modeling
Authors@R: person( "Øystein Olav","Skaar", email="bayesianfw@gmail.com", role=c("aut","cre"))
Maintainer: Øystein Olav Skaar <bayesianfw@gmail.com>
@@ -39,6 +39,6 @@ Suggests:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
VignetteBuilder: knitr
NeedsCompilation: no
@@ -12,6 +12,7 @@ export(FlattenList)
export(GammaDist)
export(GetRange)
export(Interleave)
export(InverseHDI)
export(Layout)
export(MatrixCombn)
export(MergeMCMC)
@@ -87,9 +88,14 @@ importFrom(stats,approxfun)
importFrom(stats,complete.cases)
importFrom(stats,cor)
importFrom(stats,cov)
importFrom(stats,dbeta)
importFrom(stats,density)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,optimize)
importFrom(stats,pbeta)
importFrom(stats,qbeta)
importFrom(stats,rbeta)
importFrom(stats,sd)
importFrom(utils,capture.output)
importFrom(utils,combn)
12 NEWS.md
@@ -1,3 +1,13 @@
# bfw 0.3.0.9001

### Feature

* Added `InverseHDI` function to compute inverse cumulative density function of the distribution

#### Minor

* Added option to add results to `ETA` function

# bfw 0.3.0

### Feature
@@ -36,7 +46,7 @@
* Added `MultiGrep` function to use multiple patterns to select an element from a vector
* Fixed bug in `kappa` function
* Fixed bug in `covariate` function
* Fixed inlinde comment bug in `TidyCode` function
* Fixed inline comment bug in `TidyCode` function
* Added option to define which parameters to use for diagnostics
* Removed (some of the...) unnecessary arguments in `bfw` function
* Added a `apa` PowerPoint template
@@ -588,22 +588,24 @@ TidyCode <- function(tidy.code,

#' @title ETA
#' @description Print estimated time for arrival (ETA)
#' @param start.time Start time (preset variable with Sys.time())
#' @param start.time start time (preset variable with Sys.time())
#' @param i incremental steps towards total
#' @param total Total number of steps
#' @param total total number of steps
#' @param results message to display, Default: NULL
#' @seealso
#' \code{\link[utils]{flush.console}}
#' @rdname ETA
#' @export
#' @importFrom utils flush.console

ETA <- function (start.time, i , total) {
ETA <- function (start.time, i , total, results = NULL) {
eta <- Sys.time() + ( (total - i) * ((Sys.time() - start.time) / i) )
eta.message <- sprintf("Progress: %.02f%% (%s/%s). ETA: %s ",
(i * 100) / total,
i,
total,
format(eta,"%d.%m.%Y - %H:%M:%S"))
if (length(results)) eta.message <- paste0("Results: ", results , ". " ,eta.message)
cat("\r" , eta.message , sep="")
utils::flush.console()
if (i == total) cat("\n")
@@ -78,8 +78,8 @@ AddNames <- function(par, job.names, job.group = NULL, keep.par = TRUE, names.on
#' data <-rnorm(100,0,1)
#' credible.region <- 0.95
#' ComputeHDI(data,credible.region)
#' # hdi.min hdi.max
#' # -1.99 1.60
#' # HDIlo HDIhi
#' # -1.99 1.60
#' @rdname ComputeHDI
#' @export

@@ -90,11 +90,56 @@ ComputeHDI <- function(data, credible.region) {
ci.mass <- lapply(1:length.ci, function(i) {
data[min(i + ci.interval,length(data))] - data[i]
})
hdi.min <- data[which.min(ci.mass)]
hdi.max <- data[which.min(ci.mass) + min(ci.interval,length(data)-1)]
hdi <- c(hdi.min = hdi.min, hdi.max = hdi.max)

HDI <- c(HDIlo = data[which.min(ci.mass)],
HDIhi = data[which.min(ci.mass) + min(ci.interval,length(data)-1)]
)

return (HDI)
}


#' @title Compute Inverse HDI
#' @description Compute inverse cumulative density function of the distribution
#' @param beta density, distribution function, quantile function and random generation for the Beta distribution with parameters shape1 and shape2
#' @param shape1 non-negative parameter of the Beta distribution.
#' @param shape2 non-negative parameter of the Beta distribution.
#' @param credible.region summarize uncertainty by defining a region of most credible values (e.g., 95 percent of the distribution), Default: 0.95
#' @param tolerance the desired accuracy, Default: 1e-8
#' @return Return HDI
#' @details values within the HDI have higher probability density than values outside the HDI, and the values inside the HDI have a total probability equal to the credible region (e.g., 95 percent).
#' @examples
#' InverseHDI( qbeta , 554 , 149 )
#' # HDIlo HDIhi
#' # 0.758 0.818
#' @seealso
#' \code{\link[stats]{Beta}},\code{\link[stats]{optimize}}
#' @rdname InverseHDI
#' @export
#' @importFrom stats optimize dbeta pbeta qbeta rbeta

return (hdi)
InverseHDI = function( beta , shape1 , shape2 , credible.region = 0.95 , tolerance = 1e-8) {

incredible.region <- 1.0 - credible.region

IntervalWidth <- function( beta , credible.region , low.tail , shape1 , shape2) {
beta(credible.region + low.tail , shape1 , shape2) - beta(low.tail , shape1 , shape2)
}

optimize.results = stats::optimize(IntervalWidth ,
c( 0 , incredible.region ) ,
beta = beta ,
credible.region = credible.region ,
tol = tolerance,
shape1 , shape2
)

HDI <- c(HDIlo = beta(optimize.results$minimum , shape1 , shape2 ),
HDIhi = beta(credible.region + optimize.results$minimum , shape1 , shape2 )
)

return (HDI)

}

#' @title Contrast Names
@@ -7,9 +7,9 @@
<a href="man/figures/logo2.png" id="logo2" title="Logo II"><img src="man/figures/logo2.png" width="250px" alt="Logo II" /></a>
</p>
<p align="center">
<a href="NEWS.md" id="news" title="News"><img src="https://img.shields.io/badge/News-2018.11.04 @ 11:21:49-purple.svg" alt="News" /></a>
<a href="NEWS.md" id="news" title="News"><img src="https://img.shields.io/badge/News-2018.12.04 @ 16:12:46-purple.svg" alt="News" /></a>
<a href="https://CRAN.R-project.org/package=bfw" id="cran" title="CRAN Version"><img src="https://www.r-pkg.org/badges/version/bfw" alt="CRAN Version" /></a>
<a href="https://github.com/oeysan/bfw" id="github" title="GitHub Version"><img src="https://img.shields.io/badge/GitHub-0.3.0-red.svg?style=flat-square" alt="GitHub Version" /></a>
<a href="https://github.com/oeysan/bfw" id="github" title="GitHub Version"><img src="https://img.shields.io/badge/GitHub-0.3.0.9001-red.svg?style=flat-square" alt="GitHub Version" /></a>
<br/>
<a href="LICENSE.md" id="license" title="License"><img src="https://img.shields.io/badge/Licence-MIT-blue.svg" alt="License" /></a>
<a href="https://travis-ci.org/oeysan/bfw" id="travis" title="Build Status"><img src="https://travis-ci.org/oeysan/bfw.svg?branch=master" alt="Build Status" /></a>
@@ -266,11 +266,11 @@ The cost of conducting robust estimates

# Running time for normal distribution analyis
biased.mcmc$run.time[2] - biased.mcmc$run.time[1]
#> Time difference of 7.35 secs
#> Time difference of 7.32 secs

# Running time for t-distribution analysis
biased.mcmc.robust$run.time[2] - biased.mcmc.robust$run.time[1]
#> Time difference of 31.3 secs
#> Time difference of 40.3 secs

License
-------

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit bd3aee4

Please sign in to comment.
You can’t perform that action at this time.