636
Le logiciel R
3.5- tmp <- data.frame(Maladie = c("Infarctus", "H´ epatite",
"Cancer du poumon"),FR = c("tabac, alcool", "alcool", "tabac"))
tmp
tmp$Maladie[grep("tabac",tmp$FR)]
F- Le chevalier de M´ er´ e
– # Fonction auxiliaire
quatrejets <- function() {
unsixouplus <- 0
jeu <- sample(1:6,4,replace=TRUE)
nbsix = sum(jeu == 6)
if(nbsix >= 1) unsixouplus <- 1
return(unsixouplus)
}
– # Fonction auxiliaire
vingtquatrejets <- function() {
undoublesixouplus <- 0
de1 <- sample(1:6,24,replace=TRUE)
de2 <- sample(1:6,24,replace=TRUE)
nbdoublesix <- sum(de1[which(de1 == de2)] == 6)
if(nbdoublesix >= 1) undoublesixouplus <- 1
return(undoublesixouplus)
}
– # Estimation de la probabilit´ e d’un ´ ev´ enement
meresix <- function(nsim = 2000) {
aumoinsunsix <- 0
aumoinsundoublesix <- 0
for(j in 1:nsim) {
aumoinsunsix <- aumoinsunsix + quatrejets()
aumoinsundoublesix <- aumoinsundoublesix + vingtquatrejets()
}
# ************* Affichage des r´ esultats *******************
cat("Fr´ equence des six =",aumoinsunsix/nsim,"\n")
cat("Fr´ equence des doubles six =",aumoinsundoublesix/nsim,"\n")
\}
Le logiciel R
3.5- tmp <- data.frame(Maladie = c("Infarctus", "H´ epatite",
"Cancer du poumon"),FR = c("tabac, alcool", "alcool", "tabac"))
tmp
tmp$Maladie[grep("tabac",tmp$FR)]
F- Le chevalier de M´ er´ e
– # Fonction auxiliaire
quatrejets <- function() {
unsixouplus <- 0
jeu <- sample(1:6,4,replace=TRUE)
nbsix = sum(jeu == 6)
if(nbsix >= 1) unsixouplus <- 1
return(unsixouplus)
}
– # Fonction auxiliaire
vingtquatrejets <- function() {
undoublesixouplus <- 0
de1 <- sample(1:6,24,replace=TRUE)
de2 <- sample(1:6,24,replace=TRUE)
nbdoublesix <- sum(de1[which(de1 == de2)] == 6)
if(nbdoublesix >= 1) undoublesixouplus <- 1
return(undoublesixouplus)
}
– # Estimation de la probabilit´ e d’un ´ ev´ enement
meresix <- function(nsim = 2000) {
aumoinsunsix <- 0
aumoinsundoublesix <- 0
for(j in 1:nsim) {
aumoinsunsix <- aumoinsunsix + quatrejets()
aumoinsundoublesix <- aumoinsundoublesix + vingtquatrejets()
}
# ************* Affichage des r´ esultats *******************
cat("Fr´ equence des six =",aumoinsunsix/nsim,"\n")
cat("Fr´ equence des doubles six =",aumoinsundoublesix/nsim,"\n")
\}
