Skip to content

Commit

Permalink
Fix notes, update package to use roxygen and add github actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbertran committed Mar 13, 2021
1 parent 2a7ef03 commit ca6b64c
Show file tree
Hide file tree
Showing 88 changed files with 3,018 additions and 1,247 deletions.
15 changes: 15 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
genlogo.R
^_pkgdown\.yml$
^figure$
^pkgdown$
^Meta$
^doc$
#All packages
^.*\.Rproj$
^\.Rproj\.user$
Expand All @@ -15,3 +21,12 @@
#Specific
^raw-image*$
^articles*$
^\.github$
#Vignette cache
^cran-comments[.].*$
^vignettes/.*[.](pdf|PDF)$
^vignettes/.*[.](r|R)$
^vignettes/[.]install_extras$
^vignettes/.*_cache$
^vignettes/.*_files$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
32 changes: 32 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v1
- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))
remotes::install_deps(dependencies = TRUE)
shell: Rscript {0}
- name: Check
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
shell: Rscript {0}
23 changes: 16 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
.Rproj.user
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
*.pper
*.pper
.DS_Store
.Rproj.user/AF86C25B/pcs/source-pane.pper
.Rproj.user/AF86C25B/pcs/windowlayoutstate.pper
*.pper

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/
2 changes: 2 additions & 0 deletions BioStatR.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ LaTeX: pdfLaTeX

BuildType: Package
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --force
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace,vignette
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: BioStatR
Type: Package
Title: Initiation à La Statistique Avec R
Version: 3.1.1
Date: 2019-01-26
Version: 3.1.2
Date: 2021-03-13
Depends: R (>= 2.10)
Imports: ggplot2
Authors@R: c(
Expand All @@ -16,6 +16,6 @@ LazyData: yes
License: GPL-3
Encoding: UTF-8
Classification/MSC:
URL: http://www-irma.u-strasbg.fr/~fbertran/, https://github.com/fbertran/BioStatR
BugReports: https://github.com/fbertran/BioStatR/issues
RoxygenNote: 6.1.1
URL: http://www-irma.u-strasbg.fr/~fbertran/, https://github.com/fbertran/BioStatR/
BugReports: https://github.com/fbertran/BioStatR/issues/
RoxygenNote: 7.1.1
14 changes: 0 additions & 14 deletions INDEX

This file was deleted.

35 changes: 22 additions & 13 deletions NAMESPACE
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import(ggplot2)
importFrom("grDevices", "colorRampPalette", "gray")
importFrom("graphics", "hist", "par", "persp", "rect")
importFrom("stats", "as.formula", "lm", "qchisq", "qf", "qnorm",
"quantile", "sd")
# Generated by roxygen2: do not edit by hand

# functions
export(cvar)
export(eta2)
export(panel.hist)
export(poi.ci)
export(binom.ci)
export(plotcdf2)
export(gg_qqplot)
export(binom.ci)
export(cvar)
export(eta2)
export(gg_qqplot)
export(panel.hist)
export(plotcdf2)
export(poi.ci)
import(ggplot2)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,gray)
importFrom(graphics,hist)
importFrom(graphics,par)
importFrom(graphics,persp)
importFrom(graphics,rect)
importFrom(stats,as.formula)
importFrom(stats,lm)
importFrom(stats,qchisq)
importFrom(stats,qf)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,sd)
11 changes: 0 additions & 11 deletions NEWS

This file was deleted.

4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# BioStatR 3.1.2

* Update to Roxygen and fix CRAN notes.

# BioStatR 3.1.1

* Update of the reference to the book in the description file.
Expand Down
32 changes: 32 additions & 0 deletions R/BioStatR-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' BioStatR
#'
#' Motivation: Package compagnon du livre Initiation à la statistique avec R.
#' Il contient les codes des chapitres du livre ainsi que les solutions des
#' exercices mais aussi d'autres compléments à découvrir.
#'
#'
#' @name BioStatR
#' @docType package
#' @references F. Bertrand, M. Maumy-Bertrand, Initiation à la Statistique avec
#' R, 3ème edition, ISBN:9782100782826, Dunod, Paris, 2018.
#' @references \emph{Initiation à la Statistique avec R}, Frédéric Bertrand,
#' Myriam Maumy-Bertrand, 2018, ,
#' \url{https://www.dunod.com/sciences-techniques/initiation-statistique-avec-r-cours-exemples-exercices-et-problemes-corriges-0},
#' \url{https://github.com/fbertran/BioStatR/} et
#' \url{https://fbertran.github.io/BioStatR/}
#'
#' @importFrom grDevices colorRampPalette gray
#' @importFrom graphics hist par persp rect
#' @importFrom stats as.formula lm qchisq qf qnorm quantile sd
#' @import ggplot2
#'
#' @examples
#' set.seed(314)
#'
NULL






137 changes: 82 additions & 55 deletions R/binom.ci.R
Original file line number Diff line number Diff line change
@@ -1,55 +1,82 @@
binom.ci <- function (x, n, conf.level = 0.95, method = c("Wilson", "exact", "Wald",
"all"))
{
method <- match.arg(method)
bc <- function(x, n, conf.level, method) {
nu1 <- 2 * (n - x + 1)
nu2 <- 2 * x
ll <- if (x > 0)
x/(x + qf(1/2 + conf.level/2, nu1, nu2) * (n - x + 1))
else 0
nu1p <- nu2 + 2
nu2p <- nu1 - 2
pp <- if (x < n)
qf(1/2 + conf.level/2, nu1p, nu2p)
else 1
ul <- ((x + 1) * pp)/(n - x + (x + 1) * pp)
zcrit <- -qnorm((1-conf.level)/2)
z2 <- zcrit * zcrit
p <- x/n
cl <- (p + z2/2/n + c(-1, 1) * zcrit * sqrt((p * (1 -
p) + z2/4/n)/n))/(1 + z2/n)
if (x == 1)
cl[1] <- -log(conf.level)/n
if (x == (n - 1))
cl[2] <- 1 + log(conf.level)/n
asymp.lcl <- x/n - qnorm(1/2+conf.level/2) * sqrt(((x/n) *
(1 - x/n))/n)
asymp.ucl <- x/n + qnorm(1/2+conf.level/2) * sqrt(((x/n) *
(1 - x/n))/n)
res <- rbind(c(ll, ul), cl, c(asymp.lcl, asymp.ucl))
res <- cbind(rep(x/n, 3), res)
switch(method, Wilson = res[2, ], exact = res[1, ], Wald = res[3,
], all = res, res)
}
if ((length(x) != length(n)) & length(x) == 1)
x <- rep(x, length(n))
if ((length(x) != length(n)) & length(n) == 1)
n <- rep(n, length(x))
if ((length(x) > 1 | length(n) > 1) & method == "all") {
method <- "Wilson"
warning("method=all will not work with vectors...setting method to Wilson")
}
if (method == "all" & length(x) == 1 & length(n) == 1) {
mat <- bc(x, n, conf.level, method)
dimnames(mat) <- list(c("Exact", "Wilson", "Wald"),
c("PointEst", "Lower", "Upper"))
return(mat)
}
mat <- matrix(ncol = 3, nrow = length(x))
for (i in 1:length(x)) mat[i, ] <- bc(x[i], n[i], conf.level = conf.level,
method = method)
dimnames(mat) <- list(rep("", dim(mat)[1]), c("PointEst",
"Lower", "Upper"))
mat
}
#' Intervalles de confiance pour une proportion
#'
#' Cette fonction permet de calculer plusieurs types d'intervalles de confiance
#' pour une proportion.
#'
#'
#' @param x Nombre de succès
#' @param n Nombre d'essais
#' @param conf.level Niveau de confiance recherché pour l'intervalle
#' @param method Type d'intervalle de confiance à calculer : intervalle de
#' "Wilson", intervalle "exact" de Clopper-Pearson, intervalle asymptotique de
#' "Wald" ou tous les trois "all"
#' @return \item{matrix}{Limites des intervalles de confiance demandés.}
#' @author Frédéric Bertrand\cr \email{frederic.bertrand@@math.unistra.fr}\cr
#' \url{http://www-irma.u-strasbg.fr/~fbertran/}\cr
#' Maumy-Bertrand\cr \email{myriam.maumy@@math.unistra.fr}\cr
#' \url{http://www-irma.u-strasbg.fr/~mmaumy/}
#' @seealso \code{\link{binom.test}}, \code{\link{binom.ci}},
#' \code{\link{poi.ci}}
#' @references F. Bertrand, M. Maumy-Bertrand, Initiation à la Statistique avec
#' R, Dunod, 3ème edition, 2018.
#' @keywords univar
#' @examples
#'
#' binom.ci(5,10,method="all")
#'
#' @export binom.ci
binom.ci <- function (x, n, conf.level = 0.95, method = c("Wilson", "exact", "Wald",
"all"))
{
method <- match.arg(method)
bc <- function(x, n, conf.level, method) {
nu1 <- 2 * (n - x + 1)
nu2 <- 2 * x
ll <- if (x > 0)
x/(x + qf(1/2 + conf.level/2, nu1, nu2) * (n - x + 1))
else 0
nu1p <- nu2 + 2
nu2p <- nu1 - 2
pp <- if (x < n)
qf(1/2 + conf.level/2, nu1p, nu2p)
else 1
ul <- ((x + 1) * pp)/(n - x + (x + 1) * pp)
zcrit <- -qnorm((1-conf.level)/2)
z2 <- zcrit * zcrit
p <- x/n
cl <- (p + z2/2/n + c(-1, 1) * zcrit * sqrt((p * (1 -
p) + z2/4/n)/n))/(1 + z2/n)
if (x == 1)
cl[1] <- -log(conf.level)/n
if (x == (n - 1))
cl[2] <- 1 + log(conf.level)/n
asymp.lcl <- x/n - qnorm(1/2+conf.level/2) * sqrt(((x/n) *
(1 - x/n))/n)
asymp.ucl <- x/n + qnorm(1/2+conf.level/2) * sqrt(((x/n) *
(1 - x/n))/n)
res <- rbind(c(ll, ul), cl, c(asymp.lcl, asymp.ucl))
res <- cbind(rep(x/n, 3), res)
switch(method, Wilson = res[2, ], exact = res[1, ], Wald = res[3,
], all = res, res)
}
if ((length(x) != length(n)) & length(x) == 1)
x <- rep(x, length(n))
if ((length(x) != length(n)) & length(n) == 1)
n <- rep(n, length(x))
if ((length(x) > 1 | length(n) > 1) & method == "all") {
method <- "Wilson"
warning("method=all will not work with vectors...setting method to Wilson")
}
if (method == "all" & length(x) == 1 & length(n) == 1) {
mat <- bc(x, n, conf.level, method)
dimnames(mat) <- list(c("Exact", "Wilson", "Wald"),
c("PointEst", "Lower", "Upper"))
return(mat)
}
mat <- matrix(ncol = 3, nrow = length(x))
for (i in 1:length(x)) mat[i, ] <- bc(x[i], n[i], conf.level = conf.level,
method = method)
dimnames(mat) <- list(rep("", dim(mat)[1]), c("PointEst",
"Lower", "Upper"))
mat
}
31 changes: 27 additions & 4 deletions R/cvar.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
cvar <- function(x){100*sd(x)/mean(x)}



#' Coefficient de variation
#'
#' Calcule coefficent de variation d'une série statistique
#'
#' Le coefficient de variation est égal à l'écart-type corrigé divisé par la
#' moyenne. Il est exprimé en pourcents.
#'
#' @param x Un vecteur numérique
#' @return \item{num}{Valeur du coefficient de variation exprimé en pourcents}
#' @author Frédéric Bertrand\cr \email{frederic.bertrand@@math.unistra.fr}\cr
#' \url{http://www-irma.u-strasbg.fr/~fbertran/}\cr
#' Maumy-Bertrand\cr \email{myriam.maumy@@math.unistra.fr}\cr
#' \url{http://www-irma.u-strasbg.fr/~mmaumy/}
#' @seealso \code{\link{mean}}, \code{\link{sd}}
#' @references F. Bertrand, M. Maumy-Bertrand, Initiation à la Statistique avec
#' R, Dunod, 3ème edition, 2018.
#' @keywords univar
#' @examples
#'
#' data(Europe)
#' cvar(Europe[,2])
#'
#' @export cvar
cvar <- function(x){100*sd(x)/mean(x)}



Loading

0 comments on commit ca6b64c

Please sign in to comment.