Giter Club home page Giter Club logo

distcrete's Introduction

Build Status Build status Coverage Status CRAN_Status_Badge

reconhub

This packages installs and loads all stable RECON packages similiar to the tidyverse package.

Installing the package

To install the current stable, CRAN version of the package, type:

install.packages("reconhub")

To benefit from the latest features and bug fixes, install the development, github version of the package using:

devtools::install_github("reconhub/reconhub")

Note that this requires the package devtools installed.

What does it do?

# attaches all stable recon packages
library(reconhub)
## Attaching package epicontacts

## Attaching package outbreaks

## Attaching package incidence

Also, you can install all development versions of RECON packages:

reconhub::install_dev_versions()

Getting help online

Bug reports and feature requests should be posted on github using the issue system. All other questions should be posted on the RECON forum:
http://www.repidemicsconsortium.org/forum/

Contributions are welcome via pull requests.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

distcrete's People

Contributors

dirkschumacher avatar richfitz avatar stephlocke avatar thibautjombart avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

thibautjombart

distcrete's Issues

Add @details to core function

Needs to be sufficiently latex'd for render - iteration in a688070 did not pass CRAN but did pass various checks

- $x_c$: a random variable with a known continous distribution, with $f_c$ its p.d.f and $F_c$ the corresponding c.d.f.
- $x_d$: a random variable following a discrete distribution derived from 'f_c'

The p.m.f. of $x_d$ is defined for any discrete value $X$ by:
$$
p(x_d = X) = p(x_c \in [X - (wi/2) ; X + (wi/2)[) = F_c(X + wi/2) - F_c(X - wi/2)
$$
where $i$ is the width of the discretising interval, and $w$ is an offset describing how continuous values are mapped onto a discrete scale. For instance, with $i = 1$ and $w = 0.5$, any values on $[2.5 ; 3.5[$ are mapped to 2; for $i = 1$ and $w = 0$, any values on $[1 ; 2[$ is mapped to $1$.

Non-finite values flanked by finite values in the tail of the distribution

Hello,
In the example below I would not expect non-finite values flanked by finite values in the tail of the distribution (see from index 92) when generating the values of the probability mass function.
Shouldn't all subsequent values after the 1st -Inf also be -Inf?
Thank you

library(distcrete)
#> Warning: package 'distcrete' was built under R version 4.1.1
packageVersion("distcrete")
#> [1] '1.0.3'

dist <- distcrete::distcrete(
  "gamma",
  shape = 2.652245,
  scale = 2.149123,
  interval = 1,
  w = 1
)

log(dist$d(1:100))
#>   [1]  -3.734979  -2.467984  -2.085171  -1.990748  -2.038198  -2.170087
#>   [7]  -2.358006  -2.585823  -2.843500  -3.124365  -3.423756  -3.738292
#>  [13]  -4.065437  -4.403246  -4.750190  -5.105048  -5.466827  -5.834710
#>  [19]  -6.208019  -6.586181  -6.968708  -7.355186  -7.745253  -8.138598
#>  [25]  -8.534946  -8.934056  -9.335717  -9.739739 -10.145952 -10.554207
#>  [31] -10.964365 -11.376305 -11.789914 -12.205092 -12.621746 -13.039792
#>  [37] -13.459152 -13.879755 -14.301536 -14.724434 -15.148393 -15.573362
#>  [43] -15.999292 -16.426139 -16.853860 -17.282418 -17.711775 -18.141897
#>  [49] -18.572753 -19.004313 -19.436548 -19.869432 -20.302941 -20.737049
#>  [55] -21.171736 -21.606980 -22.042761 -22.479060 -22.915860 -23.353143
#>  [61] -23.790895 -24.229099 -24.667734 -25.106803 -25.546273 -25.986137
#>  [67] -26.426416 -26.867025 -27.308048 -27.749354 -28.191020 -28.633306
#>  [73] -29.075273 -29.517891 -29.961434 -30.403521 -30.847923 -31.294383
#>  [79] -31.732854 -32.182924 -32.625927 -33.073239 -33.517925 -33.964212
#>  [85] -34.338905 -34.945041 -35.127363 -36.043653 -36.043653 -36.736801
#>  [91] -36.736801       -Inf       -Inf -36.736801       -Inf       -Inf
#>  [97]       -Inf       -Inf       -Inf       -Inf
log(dist$d(1:100)[93])
#> [1] -Inf
log(dist$d(1:100)[94])
#> [1] -36.7368
log(dist$d(1:100)[95])
#> [1] -Inf

Created on 2022-03-07 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info  --------------------------------------------------------------
#>  hash: flag: Madagascar, closed mailbox with raised flag, person in suit levitating: medium skin tone
#> 
#>  setting  value
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Windows 10 x64 (build 22000)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/London
#>  date     2022-03-07
#>  pandoc   2.11.4 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  backports     1.3.0   2021-10-27 [1] CRAN (R 4.1.1)
#>  cli           3.1.0   2021-10-27 [1] CRAN (R 4.1.1)
#>  crayon        1.5.0   2022-02-14 [1] CRAN (R 4.1.2)
#>  digest        0.6.28  2021-09-23 [1] CRAN (R 4.1.1)
#>  distcrete   * 1.0.3   2017-11-23 [1] CRAN (R 4.1.1)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.1)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.1)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.1)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.1)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.1)
#>  glue          1.5.0   2021-11-07 [1] CRAN (R 4.1.0)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.1)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.1)
#>  knitr         1.37    2021-12-16 [1] CRAN (R 4.1.2)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.1)
#>  pillar        1.6.5   2022-01-25 [1] CRAN (R 4.1.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.1)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.2)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.1.1)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.1.1)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.2)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         0.4.12  2021-10-18 [1] CRAN (R 4.1.1)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.1)
#>  sessioninfo   1.2.1   2021-11-02 [1] CRAN (R 4.1.0)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.1)
#>  styler        1.6.2   2021-09-23 [1] CRAN (R 4.1.2)
#>  tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.0)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.1)
#>  withr         2.4.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.28    2021-11-04 [1] CRAN (R 4.1.0)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.1)
#> 
#>  [1] C:/Users/cygei/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.0/library
#> 
#> ------------------------------------------------------------------------------

Build skeleton of vignette

I'll write a few paragraphs with empty code chunks for you to fill. Should be a fun (ish) way to see how well the use-case has been laid out :)

Note: if you'd rather, can be done in the README.Rmd

CRAN release checklist

  • increase version to 1.0.0
  • update repo status to "active"
  • add CRAN badge to README
  • add CRAN installation instructions to README
  • generate pkgdown website to replace old staticdocs one
  • test on r-release (rhub)
  • test on r-devel (rhub)
  • update maintainer field

Allow easier changing of parameters

For things like #9, the pattern of recreating a distribution seems really ugly. Better might be to replace parameters. So the workflow would look more like:

ll2 <- function(param, obj, x) {
  obj$d(x, scale = param[[1]], rate = param[[2]])
}

or

ll2 <- function(param, obj, x) {
  obj$d(x, parameters = param)
}

Thoughts @thibautjombart?

New testthat is going to make the README look a bit gross

With the development testthat (which is headed to CRAN very shortly) the print method is new and does not render well to a file. We can select the old one with a tweak to test I think. New version will render like below:

devtools::test()
#> Loading distcrete
#> Testing distcrete
#> Warning: `encoding` is deprecated; all files now assumed to be UTF-8
#> ✔ | OK F W S | Context
#> |  0       | distcrete|  1       | distcrete|  2       | distcrete|  3       | distcrete|  4       | distcrete|  5       | distcrete|  6       | distcrete|  7       | distcrete|  8       | distcrete|  9       | distcrete| 10       | distcrete| 11       | distcrete| 12       | distcrete| 13       | distcrete| 14       | distcrete| 15       | distcrete| 16       | distcrete| 17       | distcrete| 18       | distcrete| 19       | distcrete| 20       | distcrete| 21       | distcrete| 22       | distcrete| 23       | distcrete| 24       | distcrete| 25       | distcrete| 26       | distcrete| 27       | distcrete| 28       | distcrete| 29       | distcrete| 30       | distcrete| 31       | distcrete| 32       | distcrete| 33       | distcrete| 34       | distcrete| 35       | distcrete| 36       | distcrete| 37       | distcrete| 38       | distcrete| 39       | distcrete| 40       | distcrete| 41       | distcrete| 42       | distcrete| 43       | distcrete| 44       | distcrete| 45       | distcrete| 46       | distcrete| 47       | distcrete| 48       | distcrete| 49       | distcrete| 50       | distcrete| 51       | distcrete| 52       | distcrete| 53       | distcrete| 54       | distcrete| 55       | distcrete| 56       | distcrete| 57       | distcrete| 58       | distcrete| 59       | distcrete| 60       | distcrete| 61       | distcrete| 62       | distcrete| 63       | distcrete| 64       | distcrete| 65       | distcrete| 66       | distcrete| 67       | distcrete| 68       | distcrete| 69       | distcrete| 70       | distcrete| 71       | distcrete| 72       | distcrete| 73       | distcrete| 74       | distcrete| 75       | distcrete| 76       | distcrete| 77       | distcrete| 78       | distcrete| 79       | distcrete| 80       | distcrete| 81       | distcrete| 82       | distcrete| 83       | distcrete| 84       | distcrete| 85       | distcrete| 86       | distcrete| 87       | distcrete| 88       | distcrete| 89       | distcrete| 90       | distcrete| 91       | distcrete| 92       | distcrete| 93       | distcrete| 94       | distcrete| 95       | distcrete| 96       | distcrete| 97       | distcrete| 98       | distcrete| 99       | distcrete| 100       | distcrete| 101       | distcrete| 102       | distcrete| 103       | distcrete| 104       | distcrete| 105       | distcrete| 106       | distcrete| 107       | distcrete| 108       | distcrete| 109       | distcrete| 110       | distcrete| 111       | distcrete| 112       | distcrete| 113       | distcrete| 114       | distcrete| 115       | distcrete| 116       | distcrete| 117       | distcrete| 118       | distcrete| 119       | distcrete| 120       | distcrete| 121       | distcrete| 122       | distcrete| 123       | distcrete| 124       | distcrete| 125       | distcrete| 126       | distcrete| 127       | distcrete| 128       | distcrete| 129       | distcrete| 130       | distcrete| 131       | distcrete| 132       | distcrete| 133       | distcrete| 133       | distcrete [0.3 s]
#> |  0       | utils|  1       | utils|  2       | utils|  3       | utils|  4       | utils|  5       | utils|  6       | utils|  7       | utils|  8       | utils|  9       | utils| 10       | utils| 11       | utils| 12       | utils| 13       | utils| 14       | utils| 15       | utils| 15       | utils
#> 
#> ══ Results ════════════════════════════════════════════════════════════════
#> Duration: 0.3 s
#> 
#> OK:       148
#> Failed:   0
#> Warnings: 0
#> Skipped:  0

warnings in gamma distribution (*ml* vignette)

See the ml vignette, warnings when using ML estimation to fit a discretised gamma distribution. Reproducible code:

shape <- 10
rate <- 1.2
y <- distcrete("gamma", interval = 1L, shape, rate)
set.seed(1)
sim2 <- y$r(300)

ll2 <- function(param) {
   d <- distcrete("gamma", interval = 1L, param[1], param[2])$d
   sum(d(sim2, log = TRUE))
}

dev2 <- function(param) -2 * ll2(param)

optim(c(1,1), dev2)

Gives:

## Warning in cdf(x, ..., log.p = log): NaNs produced

## Warning in cdf(x, ..., log.p = log): NaNs produced

## Warning in cdf(x, ..., log.p = log): NaNs produced

## Warning in cdf(x, ..., log.p = log): NaNs produced

## Warning in cdf(x, ..., log.p = log): NaNs produced

## Warning in cdf(x, ..., log.p = log): NaNs produced

Warning in vignette

x <- seq(0, 20, length = 30)
y <- seq(0, 5, length = 30)
grid <- expand.grid(x, y)
names(grid) <- c("shape", "rate")
ll2.val <- apply(grid, 1, ll2)
df <- cbind.data.frame(grid, ll = ll2.val)

library(ggplot2)
ggplot(df, aes(x = shape, y = rate, fill = ll)) +
    geom_raster() +
    geom_contour(aes(z = ll), color = "black")

## Warning: Removed 59 rows containing non-finite values (stat_contour).

@thibautjombart can you remove this please

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.