130 likes | 337 Vues
Dades del Titanic http://ssi.umh.ac.be/titanic.html. Relaci ó entre variables categòriques. En el desastre del Titànic, les dones tenien més possibilitats de salvar-se que els homes ?. Associació entre Gènere & Sobreviuen Classe & Sobreviuen Gènere & Classe.
E N D
Dades del Titanichttp://ssi.umh.ac.be/titanic.html Relació entre variables categòriques Albert Satorra ECP2010
En el desastre del Titànic, les dones tenien més possibilitats de salvar-se que els homes ? Albert Satorra ECP2010
Associació entreGènere & SobreviuenClasse & Sobreviuen Gènere & Classe ... Albert Satorra ECP2010
data=data=read.table("http://www.econ.upf.edu/~satorra/dades/Titanic.txt", header=T) dim(data) [1] 2200 4 taula=ftable(data) sobreviu no yes classe adult home 1st adult female 4 140 male 118 56 child female 0 1 male 0 5 2nd adult female 13 80 male 154 14 child female 0 13 male 0 11 3rd adult female 89 76 male 387 75 child female 17 14 male 35 13 crew adult female 3 20 male 670 192 child female 0 0 male 0 0 dim(table(data)) [1] 4 2 2 2 Genere-sobreviu | adult taula=ftable(data[,c(2,3,4)]) taula sobreviu no yes adult home adult female 109 316 male 1329 337 child female 17 28 male 35 29 round(prop.table(taula,1),2) sobreviu no yes adult home adult female 0.26 0.74 male 0.80 0.20 child female 0.38 0.62 male 0.55 0.45 Albert Satorra ECP2010
Genere-sobreviu | adult class round(prop.table(taula,1),2) sobreviu no yes classe adult home 1st adult female 0.03 0.97 male 0.68 0.32 child female 0.00 1.00 male 0.00 1.00 2nd adult female 0.14 0.86 male 0.92 0.08 child female 0.00 1.00 male 0.00 1.00 3rd adult female 0.54 0.46 male 0.84 0.16 child female 0.55 0.45 male 0.73 0.27 crew adult female 0.13 0.87 male 0.78 0.22 child female NaN NaN male NaN NaN Genere-sobreviu | class taula=ftable(data[,c(1,3,4)]) round(prop.table(taula,1),3) sobreviu no yes classe home 1st female 0.028 0.972 male 0.659 0.341 2nd female 0.123 0.877 male 0.860 0.140 3rd female 0.541 0.459 male 0.827 0.173 crew female 0.130 0.870 male 0.777 0.223 Albert Satorra ECP2010
Taula de contingènciaFreqüències marginals (fila/ columna) • > ftable(table(data[,c(3,4)])) • no yes • female 126 344 • male 1364 366 • apply( ftable(table(data[,c(3,4)])), 1, sum) Marginal fila: • [1] 470 1730 • apply( ftable(table(data[,c(3,4)])), 2, sum) Marginal columna: • [1] 1490 710 • > Albert Satorra ECP2010
Associació Gènere & Sobreviuen round(100*ftable(table(data[,c(3,4)]))/apply(ftable(table(data[,c(3,4)])),1,sum),1) no yes female 26.8 73.2 male 78.8 21.2 Albert Satorra ECP2010
Taula de contingència dim(table(data)) [1] 4 2 2 2 apply(table(data), c(1,3), sum) female male 1st 145 179 2nd 106 179 3rd 196 510 crew 23 862 Albert Satorra ECP2010
Distribucions marginalsfila/columna > apply(apply(table(data), c(1,3), sum),1,sum) 1st 2nd 3rd crew 324 285 706 885 > apply(apply(table(data), c(1,3), sum),2,sum) female male 470 1730 > Albert Satorra ECP2010
Taula de Freqüències condicionades (fila) round(100*ftable(table(data[,c(1,3)]))/apply(ftable(table(data[,c(1,3)])),1,sum),1) female male 1st 44.8 55.2 2nd 37.2 62.8 3rd 27.8 72.2 crew 2.6 97.4 A 1ra classe, hi ha quasi tants homes com dones.A 3ra classe, els homes dupliquen les dones. Albert Satorra ECP2010
Associació Classe & Sobreviuen > round(100*ftable(table(data[,c(1,4)]))/apply(ftable(table(data[,c(1,4)])),1,sum),1) no yes 1st 37.7 62.3 2nd 58.6 41.4 3rd 74.8 25.2 crew 76.0 24.0 Albert Satorra ECP2010
> round(prop.table(ftable(data[,c(1,4)]),1),3) sobreviu no yes classe 1st 0.377 0.623 2nd 0.586 0.414 3rd 0.748 0.252 crew 0.760 0.240 > round(prop.table(ftable(data[,c(3,1,4)]),1),3) sobreviu no yes home classe female 1st 0.028 0.972 2nd 0.123 0.877 3rd 0.541 0.459 crew 0.130 0.870 male 1st 0.659 0.341 2nd 0.860 0.140 3rd 0.827 0.173 crew 0.777 0.223 > Albert Satorra ECP2010