622
Le logiciel R
Solutions des exercices du chapitre 9
9.1- L’instruction table(x)/length(x).
9.2- L’instruction table(x,y).
9.3- La commande margin.table().
9.4- La commande prop.table().
9.5- L’instruction names(which.max(table(matable))).
9.6- L’instruction diff(range(x)).
9.7- L’instruction IQR(x).
9.8- L’instruction var(x) * (length(x)-1)/length(x).
9.9- L’instruction sqrt(var(x) * (length(x)-1)/length(x))/mean(x).
9.10- L’instruction mean(abs(x-mean(x))).
9.11- Le package moments.
9.12- Il faut tout d’abord calculer le χ
2 avec l’instruction suivante :
khi2 <- summary(table(matable))$statistic
Le Φ
2 de Cram´ er s’obtient alors par l’instruction khi2/N.
9.13- Voici le code permettant de calculer le rapport de corr´ elation η
2
Y|X :
eta2 <- function(x,gpe) {
moyennes <- tapply(x,gpe,mean)
effectifs <- tapply(x,gpe,length)
varinter <- (sum(effectifs * (moyennes - mean(x))^2))
vartot <- (var(x) * (length(x) - 1))
res <- varinter/vartot
return(res)
}
9.14- La fonction barplot() permet d’obtenir un diagramme de Pareto.
9.15- Un diagramme empil´ e s’obtient au moyen de la fonction barplot() en
fournissant un objet de type matrix comme premier argument.
9.16- La fonction pie() permet d’obtenir un diagramme circulaire.
9.17- La fonction boxplot() permet d’obtenir un diagramme en boˆ ıte `
a moustaches.
9.18- La fonction hist() permet d’obtenir un histogramme.
Le logiciel R
Solutions des exercices du chapitre 9
9.1- L’instruction table(x)/length(x).
9.2- L’instruction table(x,y).
9.3- La commande margin.table().
9.4- La commande prop.table().
9.5- L’instruction names(which.max(table(matable))).
9.6- L’instruction diff(range(x)).
9.7- L’instruction IQR(x).
9.8- L’instruction var(x) * (length(x)-1)/length(x).
9.9- L’instruction sqrt(var(x) * (length(x)-1)/length(x))/mean(x).
9.10- L’instruction mean(abs(x-mean(x))).
9.11- Le package moments.
9.12- Il faut tout d’abord calculer le χ
2 avec l’instruction suivante :
khi2 <- summary(table(matable))$statistic
Le Φ
2 de Cram´ er s’obtient alors par l’instruction khi2/N.
9.13- Voici le code permettant de calculer le rapport de corr´ elation η
2
Y|X :
eta2 <- function(x,gpe) {
moyennes <- tapply(x,gpe,mean)
effectifs <- tapply(x,gpe,length)
varinter <- (sum(effectifs * (moyennes - mean(x))^2))
vartot <- (var(x) * (length(x) - 1))
res <- varinter/vartot
return(res)
}
9.14- La fonction barplot() permet d’obtenir un diagramme de Pareto.
9.15- Un diagramme empil´ e s’obtient au moyen de la fonction barplot() en
fournissant un objet de type matrix comme premier argument.
9.16- La fonction pie() permet d’obtenir un diagramme circulaire.
9.17- La fonction boxplot() permet d’obtenir un diagramme en boˆ ıte `
a moustaches.
9.18- La fonction hist() permet d’obtenir un histogramme.
