-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix notes, update package to use roxygen and add github actions.
- Loading branch information
Showing
88 changed files
with
3,018 additions
and
1,247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} | ||
|
||
|
||
|
Oops, something went wrong.