R/moyciph.R

Defines functions moypciph moyciph

Documented in moyciph moypciph

#' Title Intervalle de Confiance par Bootstrap pour une moyenne
#'Calcul des  IC par bootstrap pour une variable numérique
#'
#' @param varx la variable à étudier
#' @param ci Intervalle de confiance en % (95 par défaut)
#'
#' @return bornes inf & sup de l'IC
#'
#' @import boot
#' @import stats
#'
#' @examples moyciph(iris$Sepal.Width, ci = 95)
#'
#' @export
moyciph <- function(varx,ci=95){
  ci = ci/100
moy <- function(data, ind){
  deb <- data[ind]
  moye <- mean(deb, na.rm = TRUE)
}
if (min(varx,na.rm=T)==max(varx,na.rm=T)){
  bbr <- c(binf = NA, bsup = NA)
}
else{
set.seed(1234)
b1 <- boot(varx, statistic = moy, R = 1000)
bb <- boot.ci(b1, conf = ci)
binf <- bb$percent[4]
bsup <- bb$percent[5]
bbr <- c(binf = binf, bsup = bsup)
}
return(bbr)
}


#' Title Intervalle de Confiance (Student) pour une moyenne
#' Calcul des  IC par Student pour une variable numérique
#'
#' @param varx la variable à étudier
#' @param ci Intervalle de confiance en % (95 par défaut)
#'
#' @return bornes inf & sup de l'IC
#'
#' @import stats
#'
#' @examples moyciph(iris$Sepal.Width, ci = 95)
#'
#' @export
moypciph <- function(varx,ci=95){
  if (min(varx,na.rm=T)==max(varx,na.rm=T)){
    bbr <- c(binf = NA, bsup = NA)
  }
  else{
    ff <- t.test(varx,conf.level = ci/100)
    binf <- signif(ff$conf.int[[1]],3)
    bsup <- signif(ff$conf.int[[2]],3)
    bbr <- c(binf = binf, bsup = bsup)
  }
  return(bbr)
}
philippemichel/thesisph documentation built on Dec. 22, 2020, 11:08 a.m.