conditions  Reg logistique

Nombre d’observation doit être egale aumoins a 10*nbre de paramètres

tester l’hypothèse de linearite sur chaque variable explicative (a ne pas confondre avec le raintest de la rglm)

analyse de surdispersion qui risque de conduire a sous-estimer des erreurs standart des paramètres en evaluant le ratio deviance resi/ddl. si le ratio est trop sup a 1(2), il faudra plustot appliquer la valeur quasibinomial au paramètre family de la fonction glm

il est aussi a noter qu’en reg logi on interprete pas les coefficients des param mais plutot leurs valeurs exponentielle ils sont appeles odds ratio ou rapport de cote si odds ratio = 1 absence d’effet si odds ratio sup a 1 augmentation du phenomène si odds ratio inf a 1 diminution du phénomène étudié la library(forstmodel) nous permet aussi de deceler la significativité la variables graphiquement
utiliser la fonction dropl(model, test=“chisq”) la library MASS et le summary de la fonction stepAIC(model) est aussi une alternative

tester la multicolinearité du modèle

significativité du model

inspecter l’influense des var independante

evaluer la qualité du modèle

diagnostic des residus et des valeurs a berrantes

la qualité du modèle se vois à la valeur du passage du Null deviance (nbre de residu non expliqué sans intervention de variable explicative) et du Residual deviance (nbre de residu non expliqué avec intervention de quelques variable explicative)

NB en reg logi les coefficient ne sont pas interpreté

nous pouvons finir avec la matrice de confusion et out les elements qui vont avec

1)linearité entre y et chaque x 2)absence de multicol 3)normalité des residus 4)homocedas 5)indepen des resi 6)significativité du model (auto)

passons a un exemple pratique avecle titanic

  1. importer la BD
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
titanic1=read.csv("/home/nekui-tiefang/dataset/data3/titanic1.csv")
titanic2=read.csv("/home/nekui-tiefang/dataset/data3/titanic2.csv")

description de la bd sibsp: nbre frere et soeur + nbre de conjoint parch: nbre enfant ou nbre de parent à bord du navire pour chaque passager. fare: prix payer cabin: numero de la cabine embarked: porte d’embarquement

  1. passons au data cleaning
titanic=bind_rows(titanic1,titanic2)
colnames(titanic)
##  [1] "PassengerId" "Survived"    "Pclass"      "Name"        "Sex"        
##  [6] "Age"         "SibSp"       "Parch"       "Ticket"      "Fare"       
## [11] "Cabin"       "Embarked"
remove(titanic1,titanic2)
titanic= titanic[c( "Pclass", "Sex", "Age", "SibSp", "Fare", "Embarked", "Parch", "Survived")]
names(titanic)
## [1] "Pclass"   "Sex"      "Age"      "SibSp"    "Fare"     "Embarked" "Parch"   
## [8] "Survived"
summary(titanic)
##      Pclass          Sex                 Age            SibSp       
##  Min.   :1.000   Length:1309        Min.   : 0.17   Min.   :0.0000  
##  1st Qu.:2.000   Class :character   1st Qu.:21.00   1st Qu.:0.0000  
##  Median :3.000   Mode  :character   Median :28.00   Median :0.0000  
##  Mean   :2.295                      Mean   :29.88   Mean   :0.4989  
##  3rd Qu.:3.000                      3rd Qu.:39.00   3rd Qu.:1.0000  
##  Max.   :3.000                      Max.   :80.00   Max.   :8.0000  
##                                     NA's   :263                     
##       Fare           Embarked             Parch          Survived     
##  Min.   :  0.000   Length:1309        Min.   :0.000   Min.   :0.0000  
##  1st Qu.:  7.896   Class :character   1st Qu.:0.000   1st Qu.:0.0000  
##  Median : 14.454   Mode  :character   Median :0.000   Median :0.0000  
##  Mean   : 33.295                      Mean   :0.385   Mean   :0.3838  
##  3rd Qu.: 31.275                      3rd Qu.:0.000   3rd Qu.:1.0000  
##  Max.   :512.329                      Max.   :9.000   Max.   :1.0000  
##  NA's   :1                                            NA's   :418
sum(is.na(titanic)) #somme le nbre de valeur manquantes
## [1] 682
colMeans(is.na(titanic)) #pourcentage de valeurs manquante dans chaque colonne
##       Pclass          Sex          Age        SibSp         Fare     Embarked 
## 0.0000000000 0.0000000000 0.2009167303 0.0000000000 0.0007639419 0.0000000000 
##        Parch     Survived 
## 0.0000000000 0.3193277311
boxplot(titanic$Age)

mean(titanic$Age,na.rm = T)
## [1] 29.88114
median(titanic$Age,na.rm = T)
## [1] 28
titanic[is.na(titanic$Age),]$Age=median(titanic$Age,na.rm = T)
summary(titanic)
##      Pclass          Sex                 Age            SibSp       
##  Min.   :1.000   Length:1309        Min.   : 0.17   Min.   :0.0000  
##  1st Qu.:2.000   Class :character   1st Qu.:22.00   1st Qu.:0.0000  
##  Median :3.000   Mode  :character   Median :28.00   Median :0.0000  
##  Mean   :2.295                      Mean   :29.50   Mean   :0.4989  
##  3rd Qu.:3.000                      3rd Qu.:35.00   3rd Qu.:1.0000  
##  Max.   :3.000                      Max.   :80.00   Max.   :8.0000  
##                                                                     
##       Fare           Embarked             Parch          Survived     
##  Min.   :  0.000   Length:1309        Min.   :0.000   Min.   :0.0000  
##  1st Qu.:  7.896   Class :character   1st Qu.:0.000   1st Qu.:0.0000  
##  Median : 14.454   Mode  :character   Median :0.000   Median :0.0000  
##  Mean   : 33.295                      Mean   :0.385   Mean   :0.3838  
##  3rd Qu.: 31.275                      3rd Qu.:0.000   3rd Qu.:1.0000  
##  Max.   :512.329                      Max.   :9.000   Max.   :1.0000  
##  NA's   :1                                            NA's   :418

nous travaillerons avec la mediane parceque……

titanic=titanic[!is.na(titanic$Survived),]#delete all rows has survived don't have a value
titanic=titanic[!is.na(titanic$Embarked),]#replace value missed by the titanic=titanic[-c(62,830),]
str(titanic)
## 'data.frame':    891 obs. of  8 variables:
##  $ Pclass  : int  3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : chr  "male" "female" "female" "female" ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: chr  "S" "C" "S" "S" ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: int  0 1 1 1 0 0 0 0 1 1 ...
sum(is.na(titanic)) #somme le nbre de valeur manquantes
## [1] 0
colMeans(is.na(titanic)) #pourcentage de valeurs manquante dans chaque colonne
##   Pclass      Sex      Age    SibSp     Fare Embarked    Parch Survived 
##        0        0        0        0        0        0        0        0
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
str(titanic)
## 'data.frame':    891 obs. of  8 variables:
##  $ Pclass  : int  3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : chr  "male" "female" "female" "female" ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: chr  "S" "C" "S" "S" ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: int  0 1 1 1 0 0 0 0 1 1 ...
titanic$Survived=factor(titanic$Survived)
titanic$Pclass=factor(titanic$Pclass)
titanic$Sex=factor(titanic$Sex)
titanic$Embarked=factor(titanic$Embarked)
str(titanic)
## 'data.frame':    891 obs. of  8 variables:
##  $ Pclass  : Factor w/ 3 levels "1","2","3": 3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: Factor w/ 2 levels "0","1": 1 2 2 2 1 1 1 1 2 2 ...

Garder uniquement les variables qui nous sont utiles pour l’analyse. Notons que seul les variables ayant uniquement un porcentage vraimnent significatif seront traiter. La var Fare n’ayant pas un pourcentage de valeurs manquante ne sera pas traité a dessin

library(dplyr)
str(titanic)
## 'data.frame':    891 obs. of  8 variables:
##  $ Pclass  : Factor w/ 3 levels "1","2","3": 3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: Factor w/ 2 levels "0","1": 1 2 2 2 1 1 1 1 2 2 ...
sum(is.na(titanic)) #somme le nbre de valeur manquantes
## [1] 0
colMeans(is.na(titanic)) #pourcentage de valeurs manquante dans chaque colonne
##   Pclass      Sex      Age    SibSp     Fare Embarked    Parch Survived 
##        0        0        0        0        0        0        0        0
summary(titanic)
##  Pclass      Sex           Age            SibSp            Fare        Embarked
##  1:216   female:314   Min.   : 0.42   Min.   :0.000   Min.   :  0.00    :  2   
##  2:184   male  :577   1st Qu.:22.00   1st Qu.:0.000   1st Qu.:  7.91   C:168   
##  3:491                Median :28.00   Median :0.000   Median : 14.45   Q: 77   
##                       Mean   :29.36   Mean   :0.523   Mean   : 32.20   S:644   
##                       3rd Qu.:35.00   3rd Qu.:1.000   3rd Qu.: 31.00           
##                       Max.   :80.00   Max.   :8.000   Max.   :512.33           
##      Parch        Survived
##  Min.   :0.0000   0:549   
##  1st Qu.:0.0000   1:342   
##  Median :0.0000           
##  Mean   :0.3816           
##  3rd Qu.:0.0000           
##  Max.   :6.0000

Gerons la variable Embarked

#titanic$Embarked= fct_recode(titanic$Embarked, "NA's"="")
str(titanic)
## 'data.frame':    891 obs. of  8 variables:
##  $ Pclass  : Factor w/ 3 levels "1","2","3": 3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: Factor w/ 2 levels "0","1": 1 2 2 2 1 1 1 1 2 2 ...
filter(titanic, Embarked == "")
##   Pclass    Sex Age SibSp Fare Embarked Parch Survived
## 1      1 female  38     0   80              0        1
## 2      1 female  62     0   80              0        1
which(titanic$Embarked == "")
## [1]  62 830
titanic= titanic[-c(62,830), ]
summary(titanic)
##  Pclass      Sex           Age            SibSp             Fare        
##  1:214   female:312   Min.   : 0.42   Min.   :0.0000   Min.   :  0.000  
##  2:184   male  :577   1st Qu.:22.00   1st Qu.:0.0000   1st Qu.:  7.896  
##  3:491                Median :28.00   Median :0.0000   Median : 14.454  
##                       Mean   :29.32   Mean   :0.5242   Mean   : 32.097  
##                       3rd Qu.:35.00   3rd Qu.:1.0000   3rd Qu.: 31.000  
##                       Max.   :80.00   Max.   :8.0000   Max.   :512.329  
##  Embarked     Parch        Survived
##   :  0    Min.   :0.0000   0:549   
##  C:168    1st Qu.:0.0000   1:340   
##  Q: 77    Median :0.0000           
##  S:644    Mean   :0.3825           
##           3rd Qu.:0.0000           
##           Max.   :6.0000
str(titanic)
## 'data.frame':    889 obs. of  8 variables:
##  $ Pclass  : Factor w/ 3 levels "1","2","3": 3 1 3 1 3 3 1 3 3 2 ...
##  $ Sex     : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
##  $ Age     : num  22 38 26 35 35 28 54 2 27 14 ...
##  $ SibSp   : int  1 1 0 1 0 0 0 3 0 1 ...
##  $ Fare    : num  7.25 71.28 7.92 53.1 8.05 ...
##  $ Embarked: Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...
##  $ Parch   : int  0 0 0 0 0 0 0 1 2 0 ...
##  $ Survived: Factor w/ 2 levels "0","1": 1 2 2 2 1 1 1 1 2 2 ...

Voilà que le cleaning data est finish

3)Nous pouvons a present si l’on veux passer à la data visualisation

hist(titanic$Age, main = "âge passagers", 
  xlab = "âge", ylab = "Effectif",col = "red")

hist(titanic$SibSp, main = "nombre de frere et soeurs", 
  xlab = "frere et soeurs", ylab = "Effectif")

hist(titanic$Fare, main = "prix payé par passgers", 
  xlab = "prix payé en euro", ylab = "Effectif",col = "red")

hist(titanic$Parch, main = "nombre enfants", 
  xlab = "nombre enfants", ylab = "Effectif",col = "blue")

#var quali

table(titanic$Sex)
## 
## female   male 
##    312    577
plot(titanic$Sex, main = "genre", ylab = "Effectif") #plus facile a interpreter en quali

table(titanic$Pclass)
## 
##   1   2   3 
## 214 184 491
plot(titanic$Pclass, main = "pclass", ylab = "Effectif") #plus facile a interpreter en quali

table(titanic$Embarked)
## 
##       C   Q   S 
##   0 168  77 644
plot(titanic$Embarked, main = "embarked", ylab = "Effectif") #plus facile a interpreter en quali

table(titanic$Survived)
## 
##   0   1 
## 549 340
plot(titanic$Survived, main = "survived", ylab = "Effectif") #plus facile a interpreter en quali

#bivarié

plot(titanic$Age, titanic$Fare)

plot(titanic$Sex, titanic$Survived)

plot(titanic$Survived,titanic$Age )

Ainsi de suite……………………………………………………..

4)modelisation des données syndage des données

set.seed(1000)
tirage=sample(2,nrow(titanic),replace = TRUE,prob = c(0.8,0.2))
titTrain=titanic[tirage==1,]
titTest=titanic[tirage==2,]

nous entrainerons le modèle avec la bd titTrain

library(caret)
## Loading required package: lattice
## 
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
## 
##     lift
#titrain=trainControl(method = "cv",number = 10,savePredictions = T)
model1=glm(Survived~.,family = binomial(),data = titTrain)
#model11=train(Survived~., family=binomial(), methods="glm",data = titant1, trainControl=titrain)
summary(model1)
## 
## Call:
## glm(formula = Survived ~ ., family = binomial(), data = titTrain)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.5822  -0.5996  -0.4118   0.6227   2.4629  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  4.147532   0.538073   7.708 1.28e-14 ***
## Pclass2     -0.745244   0.337133  -2.211   0.0271 *  
## Pclass3     -2.174654   0.340626  -6.384 1.72e-10 ***
## Sexmale     -2.711133   0.225905 -12.001  < 2e-16 ***
## Age         -0.036623   0.008623  -4.247 2.16e-05 ***
## SibSp       -0.276330   0.126532  -2.184   0.0290 *  
## Fare         0.001849   0.003227   0.573   0.5665    
## EmbarkedQ   -0.218349   0.415826  -0.525   0.5995    
## EmbarkedS   -0.648612   0.267885  -2.421   0.0155 *  
## Parch       -0.066040   0.129603  -0.510   0.6104    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 956.65  on 718  degrees of freedom
## Residual deviance: 628.25  on 709  degrees of freedom
## AIC: 648.25
## 
## Number of Fisher Scoring iterations: 5

linearité des var signif

SurvivedPredic=predict.glm(model1,type = "response")
par(mfrow=c(3,3))
ggplot(titTrain, aes(x=titTrain$Pclass,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(titTrain, aes(x=titTrain$Sex,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(titTrain, aes(x=titTrain$Age,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!

ggplot(titTrain, aes(x=titTrain$SibSp,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!

ggplot(titTrain, aes(x=titTrain$Fare,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!

ggplot(titTrain, aes(x=titTrain$Embarked,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(titTrain, aes(x=titTrain$Parch,y=SurvivedPredic))+geom_point()+geom_smooth(method = "glm", method.args=list(family ="binomial" ))
## `geom_smooth()` using formula = 'y ~ x'
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!

““”

a=predict(model1, type = “response”) b=colnames(titTrain[1:7]) logit=log(a/(1-a)) c=titTrain[1:7]%>%mutate(logit)%>%gather(key=“b”,value=“predictor.value”,-logit) ggplot(c,aes(logit ,predictor.value))+geom_point(size=0.5,alpha=0.5)+geom_smooth(method = “glm”)+facet_wrap(~b,scales = “free_y”)

significativité des varibles (odds ratio)

library(questionr)
options(scipen = 999)
o=round(odds.ratio(model1),3)
## Waiting for profiling to be done...
o
##                 OR  2.5 %  97.5 %                   p    
## (Intercept) 63.278 22.400 185.813 <0.0000000000000002 ***
## Pclass2      0.475  0.245   0.921               0.027 *  
## Pclass3      0.114  0.058   0.222 <0.0000000000000002 ***
## Sexmale      0.066  0.042   0.102 <0.0000000000000002 ***
## Age          0.964  0.948   0.980 <0.0000000000000002 ***
## SibSp        0.759  0.585   0.961               0.029 *  
## Fare         1.002  0.996   1.009               0.567    
## EmbarkedQ    0.804  0.354   1.810               0.600    
## EmbarkedS    0.523  0.309   0.885               0.015 *  
## Parch        0.936  0.721   1.204               0.610    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#z=round(exp(coef(model1)),3)
library(forestmodel)
forest_model(model1)

#cool
library(MASS)
summary(stepAIC(model1))
## Start:  AIC=648.25
## Survived ~ Pclass + Sex + Age + SibSp + Fare + Embarked + Parch
## 
##            Df Deviance    AIC
## - Parch     1   628.51 646.51
## - Fare      1   628.60 646.60
## <none>          628.25 648.25
## - Embarked  2   634.73 650.73
## - SibSp     1   633.60 651.60
## - Age       1   647.62 665.62
## - Pclass    2   677.52 693.52
## - Sex       1   808.55 826.55
## 
## Step:  AIC=646.51
## Survived ~ Pclass + Sex + Age + SibSp + Fare + Embarked
## 
##            Df Deviance    AIC
## - Fare      1   628.77 644.77
## <none>          628.51 646.51
## - Embarked  2   635.16 649.16
## - SibSp     1   634.95 650.95
## - Age       1   647.79 663.79
## - Pclass    2   680.24 694.24
## - Sex       1   814.49 830.49
## 
## Step:  AIC=644.77
## Survived ~ Pclass + Sex + Age + SibSp + Embarked
## 
##            Df Deviance    AIC
## <none>          628.77 644.77
## - Embarked  2   636.05 648.05
## - SibSp     1   634.96 648.96
## - Age       1   648.52 662.52
## - Pclass    2   710.37 722.37
## - Sex       1   819.29 833.29
## 
## Call:
## glm(formula = Survived ~ Pclass + Sex + Age + SibSp + Embarked, 
##     family = binomial(), data = titTrain)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.5612  -0.5999  -0.4122   0.6184   2.4739  
## 
## Coefficients:
##             Estimate Std. Error z value             Pr(>|z|)    
## (Intercept)  4.26732    0.46613   9.155 < 0.0000000000000002 ***
## Pclass2     -0.82890    0.30559  -2.712              0.00668 ** 
## Pclass3     -2.28816    0.28437  -8.046 0.000000000000000853 ***
## Sexmale     -2.69674    0.21935 -12.294 < 0.0000000000000002 ***
## Age         -0.03682    0.00859  -4.286 0.000018196416578272 ***
## SibSp       -0.27780    0.11942  -2.326              0.02001 *  
## EmbarkedQ   -0.21762    0.41211  -0.528              0.59746    
## EmbarkedS   -0.67439    0.26369  -2.558              0.01054 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 956.65  on 718  degrees of freedom
## Residual deviance: 628.77  on 711  degrees of freedom
## AIC: 644.77
## 
## Number of Fisher Scoring iterations: 5
# Plus AIC est sup a l'AIC standard mieux c'est
# Il nous renvoi directement nous renvoi les var signif

d’ou le modèle final

model2=glm(formula = Survived ~ Pclass + Sex + Age + SibSp, family = binomial(), 
    data = titTrain)
summary(model2)
## 
## Call:
## glm(formula = Survived ~ Pclass + Sex + Age + SibSp, family = binomial(), 
##     data = titTrain)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.6803  -0.5591  -0.4102   0.6118   2.4193  
## 
## Coefficients:
##              Estimate Std. Error z value             Pr(>|z|)    
## (Intercept)  3.954135   0.439095   9.005 < 0.0000000000000002 ***
## Pclass2     -1.057830   0.293021  -3.610             0.000306 ***
## Pclass3     -2.384327   0.272057  -8.764 < 0.0000000000000002 ***
## Sexmale     -2.751328   0.217245 -12.665 < 0.0000000000000002 ***
## Age         -0.037920   0.008555  -4.432           0.00000932 ***
## SibSp       -0.314122   0.119482  -2.629             0.008563 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 956.65  on 718  degrees of freedom
## Residual deviance: 636.05  on 713  degrees of freedom
## AIC: 648.05
## 
## Number of Fisher Scoring iterations: 5

modèle retenu avec un AIC min qui vaut 628.46 il ya bien evlution dans le model plus AIC diminue mieux c’est

analyse de surdispersion

ratio=616.54/715
ratio
## [1] 0.8622937

nous pouvons dire qu’il n’y a pas surdispertion dans notre model puisque ratio inf a 1

multicolinarite

library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
vif(model2)
##            GVIF Df GVIF^(1/(2*Df))
## Pclass 1.325180  2        1.072923
## Sex    1.149060  1        1.071942
## Age    1.296665  1        1.138712
## SibSp  1.127112  1        1.061655

super pas de multicolinéarite

forestmodel::forest_model(model2)
## Resized limits to included dashed line in forest panel

comme le montre l’image généré, Pclass 1 et sex female sont des sous variables pas significatives et sont present du fait de la significativité d’autres variable

essayons d’estimer la qualité du modèle avec la bd titTrain

#predictionTestModel11=predict(model11, titantTest)
#titantTest$predicTestmodel11=predictionTestModel11
#predictionTestModel11
#a=fitted.values(model1)
PredictionModel=predict.glm(model2,type = "response",newdata = titTrain)
PredictionModel
##           1           2           3           4           5           6 
## 0.088678199 0.900164558 0.641961571 0.909932762 0.075249134 0.095930678 
##           7           8           9          10          11          12 
## 0.300509692 0.099775111 0.633199667 0.886079260 0.751009916 0.852554259 
##          13          15          16          17          18          19 
## 0.125656592 0.738643053 0.692260024 0.074893108 0.285613859 0.520030951 
##          20          21          23          24          25          26 
## 0.624348812 0.234652796 0.731256666 0.535203451 0.580318929 0.453813778 
##          27          29          30          31          32          33 
## 0.095930678 0.624348812 0.095930678 0.422140537 0.929448863 0.624348812 
##          35          36          37          38          39          40 
## 0.456839085 0.330936176 0.095930678 0.121549235 0.564391605 0.673664479 
##          42          43          44          45          46          47 
## 0.826115586 0.095930678 0.921898300 0.700426130 0.095930678 0.071930798 
##          48          49          50          51          52          53 
## 0.624348812 0.053579352 0.639484231 0.062770248 0.121549235 0.855935599 
##          54          55          56          57          58          60 
## 0.814950494 0.220631248 0.535203451 0.890901748 0.094298868 0.040339490 
##          61          63          64          66          68          70 
## 0.117558085 0.306249168 0.093166912 0.071930798 0.129882223 0.057557881 
##          71          72          73          74          75          77 
## 0.255695539 0.352625099 0.342686933 0.077160913 0.083557824 0.095930678 
##          78          79          80          81          82          83 
## 0.095930678 0.528345224 0.606400856 0.117558085 0.092691969 0.624348812 
##          85          86          87          88          89          90 
## 0.904794070 0.348891257 0.108867440 0.095930678 0.894693934 0.109915908 
##          91          94          95          96          97          98 
## 0.092691969 0.077160913 0.031713083 0.095930678 0.183995083 0.581916794 
##          99         100         101         102         103         104 
## 0.832998038 0.188708451 0.624348812 0.095930678 0.600245213 0.080699547 
##         105         106         108         109         110         111 
## 0.038686754 0.095930678 0.095930678 0.067705593 0.548330281 0.359063261 
##         113         114         115         116         117         119 
## 0.117558085 0.621821398 0.716093911 0.121549235 0.020737040 0.572663625 
##         120         121         122         123         124         125 
## 0.559092782 0.217620657 0.095930678 0.197571169 0.840761597 0.300509692 
##         129         130         131         132         133         134 
## 0.548330281 0.052753980 0.080699547 0.125656592 0.371321265 0.814950494 
##         135         137         138         140         141         142 
## 0.309379246 0.962081325 0.374173380 0.572663625 0.624348812 0.676025936 
##         143         144         145         146         147         149 
## 0.585551755 0.129882223 0.368749966 0.291187269 0.099270169 0.224592233 
##         150         152         153         154         155         157 
## 0.190361587 0.942987032 0.036051852 0.061961383 0.095930678 0.723739603 
##         158         159         160         163         164         166 
## 0.089551770 0.095930678 0.008524475 0.102712705 0.138696292 0.179049448 
##         170         171         172         173         174         176 
## 0.095930678 0.247812784 0.069805081 0.771670111 0.121549235 0.101725094 
##         177         178         183         184         185         186 
## 0.039709517 0.886767171 0.058453775 0.372574724 0.805044678 0.535203451 
##         187         188         189         190         191         192 
## 0.548330281 0.376696851 0.046866968 0.072652542 0.843283619 0.359967966 
##         193         194         195         196         198         199 
## 0.630696577 0.429741644 0.907682097 0.852554259 0.058736614 0.624348812 
##         201         202         203         204         205         206 
## 0.095930678 0.008524475 0.077930729 0.051814525 0.134228139 0.816672995 
##         207         209         210         211         212         213 
## 0.062439591 0.723739603 0.422140537 0.109915908 0.827656090 0.117558085 
##         214         215         216         217         219         222 
## 0.270394336 0.071930798 0.921614936 0.633199667 0.939385723 0.293413468 
##         223         224         225         226         227         228 
## 0.042474868 0.095930678 0.365336971 0.117558085 0.359967966 0.123588258 
##         231         232         233         234         235         236 
## 0.909932762 0.092691969 0.109847299 0.530890876 0.317539374 0.624348812 
##         237         239         240         242         244         245 
## 0.137332552 0.359967966 0.248545879 0.548330281 0.117558085 0.089551770 
##         246         249         250         251         252         254 
## 0.250881694 0.374173380 0.098249868 0.095930678 0.538922750 0.067029440 
##         255         256         257         258         259         260 
## 0.503772087 0.615414104 0.947468245 0.943562866 0.932575132 0.731118792 
##         261         262         263         264         265         267 
## 0.095930678 0.072307840 0.252909695 0.422140537 0.624348812 0.045445673 
##         268         270         271         272         273         275 
## 0.079904750 0.932575132 0.535203451 0.106260539 0.792750632 0.624348812 
##         276         277         278         279         280         281 
## 0.777482467 0.465905186 0.285613859 0.062770248 0.482129327 0.025423751 
##         282         283         284         286         287         289 
## 0.095930678 0.143288564 0.129882223 0.080699547 0.089551770 0.190361587 
##         290         291         292         293         295         297 
## 0.676025936 0.951117377 0.948803652 0.227911357 0.109915908 0.111784611 
##         298         300         301         302         303         304 
## 0.972459562 0.886767171 0.624348812 0.053579352 0.129882223 0.862302338 
##         305         306         307         310         311         312 
## 0.095930678 0.701363308 0.947468245 0.943562866 0.954525188 0.933598825 
##         313         314         315         316         317         318 
## 0.831495562 0.095930678 0.141887108 0.641961571 0.841856111 0.129802969 
##         319         320         321         322         325         328 
## 0.941509257 0.893139105 0.117558085 0.099270169 0.008524475 0.822179744 
##         329         330         332         333         334         336 
## 0.520030951 0.966020090 0.372255632 0.440741693 0.081924331 0.095930678 
##         337         338         340         341         342         343 
## 0.447446231 0.916782761 0.376696851 0.439058158 0.891067397 0.285613859 
##         344         345         346         347         348         349 
## 0.309379246 0.227911357 0.879343229 0.798911639 0.548330281 0.166671564 
##         350         351         352         353         355         357 
## 0.058736614 0.113681027 0.535203451 0.112601188 0.095930678 0.957705990 
##         358         360         361         363         365         367 
## 0.810819805 0.624348812 0.046866968 0.465905186 0.071930798 0.796541162 
##         369         370         371         372         373         374 
## 0.624348812 0.954525188 0.485175719 0.101725094 0.129882223 0.591112662 
##         375         376         377         379         380         382 
## 0.625669362 0.929448863 0.676025936 0.125656592 0.129882223 0.822282275 
##         383         384         385         386         387         388 
## 0.083557824 0.909932762 0.095930678 0.368749966 0.057864282 0.822179744 
##         389         390         391         394         396         398 
## 0.095930678 0.904794070 0.383094506 0.940913782 0.117558085 0.168073564 
##         400         401         403         404         405         406 
## 0.862302338 0.065350907 0.612863850 0.071930798 0.692409441 0.188708451 
##         407         408         409         410         411         412 
## 0.042474868 0.429741644 0.121549235 0.393096051 0.095930678 0.095930678 
##         413         414         415         416         417         420 
## 0.915958025 0.285613859 0.054681335 0.624348812 0.784638341 0.766849710 
##         421         422         423         424         425         426 
## 0.095930678 0.121549235 0.092691969 0.548330281 0.101725094 0.095930678 
##         427         428         429         430         432         433 
## 0.820600900 0.898057504 0.095930678 0.083557824 0.548330281 0.728997928 
##         434         435         436         437         438         440 
## 0.138696292 0.267505903 0.957267925 0.536247496 0.795431561 0.262978890 
##         441         442         444         445         446         447 
## 0.705947911 0.125656592 0.862302338 0.095930678 0.740991131 0.917082022 
##         448         449         451         452         453         454 
## 0.478395306 0.679606546 0.177370642 0.071930798 0.516296037 0.275001371 
##         455         456         457         459         460         461 
## 0.095930678 0.092691969 0.220631248 0.731118792 0.095930678 0.350383906 
##         462         463         464         465         467         468 
## 0.077930729 0.359063261 0.157734481 0.095930678 0.285613859 0.284812870 
##         469         470         471         472         474         475 
## 0.095930678 0.713639023 0.095930678 0.067705593 0.883308967 0.676025936 
##         476         477         479         480         482         483 
## 0.535203451 0.188708451 0.117558085 0.816672995 0.285613859 0.044044139 
##         484         485         486         487         488         490 
## 0.305943991 0.485175719 0.393096051 0.909932762 0.269619920 0.137415677 
##         491         492         493         494         495         496 
## 0.071930798 0.121549235 0.292599563 0.183995083 0.121549235 0.095930678 
##         497         498         499         500         501         502 
## 0.830944352 0.095930678 0.936553754 0.109915908 0.138696292 0.684274923 
##         504         505         506         507         509         510 
## 0.541595764 0.966020090 0.551349631 0.838206776 0.095930678 0.102712705 
##         512         513         514         515         516         518 
## 0.095930678 0.459510715 0.830944352 0.109915908 0.359063261 0.095930678 
##         519         521         522         524         525         526 
## 0.771546494 0.943562866 0.117558085 0.907682097 0.095930678 0.061961383 
##         527         529         531         532         533         534 
## 0.731118792 0.065350907 0.924585297 0.095930678 0.105242816 0.624348812 
##         535         536         537         540         542         544 
## 0.606400856 0.932821763 0.376696851 0.957705990 0.493010759 0.200594268 
##         545         547         548         549         550         551 
## 0.267505903 0.865495397 0.285613859 0.060256211 0.384023482 0.636028266 
##         552         553         554         555         556         557 
## 0.293413468 0.095930678 0.117558085 0.676025936 0.240812226 0.860548689 
##         558         559         561         562         563         565 
## 0.535203451 0.896704667 0.095930678 0.063072574 0.285613859 0.624348812 
##         566         567         568         569         571         573 
## 0.061812541 0.129882223 0.615414104 0.095930678 0.099207465 0.459510715 
##         575         576         577         579         580         581 
## 0.143288564 0.129882223 0.832998038 0.548330281 0.083557824 0.836741977 
##         582         583         584         586         588         589 
## 0.896704667 0.129802969 0.459510715 0.963440696 0.199964971 0.117558085 
##         590         591         592         593         594         595 
## 0.095930678 0.075249134 0.841332325 0.049090211 0.624348812 0.171905248 
##         596         598         599         600         601         602 
## 0.054127699 0.045668623 0.095930678 0.275001371 0.795431561 0.095930678 
##         603         604         605         606         607         608 
## 0.535203451 0.054681335 0.468941892 0.054127699 0.089551770 0.544622746 
##         609         611         612         613         614         616 
## 0.851693259 0.444432231 0.095930678 0.548330281 0.095930678 0.841856111 
##         618         619         620         621         622         623 
## 0.567035590 0.892485212 0.301336226 0.074503667 0.330936176 0.095001375 
##         625         626         628         630         631         632 
## 0.121549235 0.247812784 0.959215566 0.095930678 0.138144065 0.042474868 
##         633         634         635         636         637         638 
## 0.497341853 0.535203451 0.571056463 0.862302338 0.083557824 0.206744054 
##         639         641         642         643         644         645 
## 0.503772087 0.125656592 0.954525188 0.634507316 0.095930678 0.713639023 
##         648         649         650         651         654         655 
## 0.284812870 0.095930678 0.667666101 0.095930678 0.624348812 0.708321898 
##         656         657         659         660         661         662 
## 0.198874097 0.095930678 0.325813193 0.269619920 0.210579608 0.063072574 
##         665         666         667         668         669         671 
## 0.095001375 0.154895984 0.309379246 0.095930678 0.056674892 0.743718157 
##         672         673         674         675         676         677 
## 0.428779059 0.075200336 0.262978890 0.285613859 0.134228139 0.108074642 
##         679         681         682         683         684         685 
## 0.407364089 0.624348812 0.544622746 0.125656592 0.036158717 0.079853194 
##         687         688         689         691         692         694 
## 0.048851412 0.129882223 0.134228139 0.428779059 0.805044678 0.106260539 
##         696         697         698         699         700         701 
## 0.138612517 0.054681335 0.624348812 0.275001371 0.058736614 0.950614589 
##         702         703         704         706         707         708 
## 0.468941892 0.708321898 0.106260539 0.208514579 0.766724271 0.403757661 
##         709         710         711         712         715         716 
## 0.957705990 0.071930798 0.954525188 0.535203451 0.138612517 0.129882223 
##         718         719         720         722         723         724 
## 0.866743297 0.095930678 0.080699547 0.105242816 0.241531262 0.147918325 
##         725         726         728         730         732         734 
## 0.466262730 0.125656592 0.624348812 0.576320463 0.168171668 0.325813193 
##         735         736         737         738         740         741 
## 0.325813193 0.094298868 0.362513195 0.468941892 0.095930678 0.535203451 
##         742         743         745         746         749         751 
## 0.383094506 0.926189111 0.086507812 0.146076275 0.541952455 0.919123940 
##         753         754         755         757         758         759 
## 0.080699547 0.113681027 0.681793141 0.095930678 0.368749966 0.077930729 
##         760         761         762         763         765         767 
## 0.937190236 0.095930678 0.060868497 0.125656592 0.143288564 0.535203451 
##         768         769         770         774         775         776 
## 0.601866497 0.071930798 0.083557824 0.095930678 0.630533179 0.134228139 
##         777         778         779         781         783         784 
## 0.095930678 0.799024307 0.095930678 0.745896971 0.525758977 0.071930798 
##         785         786         787         788         789         790 
## 0.106260539 0.106260539 0.708321898 0.060576053 0.177473016 0.367835875 
##         791         792         794         796         797         798 
## 0.095930678 0.386572349 0.535203451 0.208514579 0.890519280 0.597314590 
##         799         801         802         803         804         806 
## 0.089551770 0.241531262 0.803239243 0.615754107 0.231929593 0.086507812 
##         807         808         809         810         811         812 
## 0.431416930 0.708321898 0.208514579 0.915958025 0.102712705 0.065350907 
##         813         814         815         816         818         819 
## 0.234652796 0.521437128 0.088017903 0.535203451 0.206744054 0.056674892 
##         820         821         822         823         824         825 
## 0.075642153 0.841332325 0.099270169 0.440741693 0.633199667 0.074893108 
##         826         828         829         831         832         833 
## 0.095930678 0.526738517 0.095930678 0.665273880 0.450012798 0.095930678 
##         834         835         836         837         838         839 
## 0.113681027 0.134228139 0.896704667 0.121549235 0.095930678 0.083557824 
##         840         841         842         843         844         845 
## 0.535203451 0.125656592 0.386572349 0.943562866 0.076579168 0.138696292 
##         846         847         848         849         850         851 
## 0.058736614 0.008524475 0.075249134 0.285613859 0.929448863 0.069805081 
##         852         853         854         855         856         857 
## 0.018206566 0.713900910 0.966020090 0.713757618 0.708321898 0.873648959 
##         858         859         860         861         863         864 
## 0.324950746 0.659199296 0.095930678 0.033424091 0.894161897 0.118686855 
##         866         867         868         869         870         871 
## 0.786451319 0.826115586 0.506821396 0.095930678 0.161471134 0.102712705 
##         873         874         875         876         878         879 
## 0.487864221 0.049090211 0.820600900 0.731256666 0.129882223 0.095930678 
##         880         881         882         883         885         886 
## 0.861835157 0.875261747 0.080699547 0.676025936 0.106260539 0.522716492 
##         887         888         889         890         891 
## 0.293413468 0.962081325 0.548330281 0.554010222 0.083557824

matrice de confusion

PredictionModelBin=ifelse(PredictionModel>0.5,1,0)
PredictionModelBin
##   1   2   3   4   5   6   7   8   9  10  11  12  13  15  16  17  18  19  20  21 
##   0   1   1   1   0   0   0   0   1   1   1   1   0   1   1   0   0   1   1   0 
##  23  24  25  26  27  29  30  31  32  33  35  36  37  38  39  40  42  43  44  45 
##   1   1   1   0   0   1   0   0   1   1   0   0   0   0   1   1   1   0   1   1 
##  46  47  48  49  50  51  52  53  54  55  56  57  58  60  61  63  64  66  68  70 
##   0   0   1   0   1   0   0   1   1   0   1   1   0   0   0   0   0   0   0   0 
##  71  72  73  74  75  77  78  79  80  81  82  83  85  86  87  88  89  90  91  94 
##   0   0   0   0   0   0   0   1   1   0   0   1   1   0   0   0   1   0   0   0 
##  95  96  97  98  99 100 101 102 103 104 105 106 108 109 110 111 113 114 115 116 
##   0   0   0   1   1   0   1   0   1   0   0   0   0   0   1   0   0   1   1   0 
## 117 119 120 121 122 123 124 125 129 130 131 132 133 134 135 137 138 140 141 142 
##   0   1   1   0   0   0   1   0   1   0   0   0   0   1   0   1   0   1   1   1 
## 143 144 145 146 147 149 150 152 153 154 155 157 158 159 160 163 164 166 170 171 
##   1   0   0   0   0   0   0   1   0   0   0   1   0   0   0   0   0   0   0   0 
## 172 173 174 176 177 178 183 184 185 186 187 188 189 190 191 192 193 194 195 196 
##   0   1   0   0   0   1   0   0   1   1   1   0   0   0   1   0   1   0   1   1 
## 198 199 201 202 203 204 205 206 207 209 210 211 212 213 214 215 216 217 219 222 
##   0   1   0   0   0   0   0   1   0   1   0   0   1   0   0   0   1   1   1   0 
## 223 224 225 226 227 228 231 232 233 234 235 236 237 239 240 242 244 245 246 249 
##   0   0   0   0   0   0   1   0   0   1   0   1   0   0   0   1   0   0   0   0 
## 250 251 252 254 255 256 257 258 259 260 261 262 263 264 265 267 268 270 271 272 
##   0   0   1   0   1   1   1   1   1   1   0   0   0   0   1   0   0   1   1   0 
## 273 275 276 277 278 279 280 281 282 283 284 286 287 289 290 291 292 293 295 297 
##   1   1   1   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0 
## 298 300 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317 318 319 320 
##   1   1   1   0   0   1   0   1   1   1   1   1   1   0   0   1   1   0   1   1 
## 321 322 325 328 329 330 332 333 334 336 337 338 340 341 342 343 344 345 346 347 
##   0   0   0   1   1   1   0   0   0   0   0   1   0   0   1   0   0   0   1   1 
## 348 349 350 351 352 353 355 357 358 360 361 363 365 367 369 370 371 372 373 374 
##   1   0   0   0   1   0   0   1   1   1   0   0   0   1   1   1   0   0   0   1 
## 375 376 377 379 380 382 383 384 385 386 387 388 389 390 391 394 396 398 400 401 
##   1   1   1   0   0   1   0   1   0   0   0   1   0   1   0   1   0   0   1   0 
## 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 420 421 422 423 424 
##   1   0   1   0   0   0   0   0   0   0   1   0   0   1   1   1   0   0   0   1 
## 425 426 427 428 429 430 432 433 434 435 436 437 438 440 441 442 444 445 446 447 
##   0   0   1   1   0   0   1   1   0   0   1   1   1   0   1   0   1   0   1   1 
## 448 449 451 452 453 454 455 456 457 459 460 461 462 463 464 465 467 468 469 470 
##   0   1   0   0   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   1 
## 471 472 474 475 476 477 479 480 482 483 484 485 486 487 488 490 491 492 493 494 
##   0   0   1   1   1   0   0   1   0   0   0   0   0   1   0   0   0   0   0   0 
## 495 496 497 498 499 500 501 502 504 505 506 507 509 510 512 513 514 515 516 518 
##   0   0   1   0   1   0   0   1   1   1   1   1   0   0   0   0   1   0   0   0 
## 519 521 522 524 525 526 527 529 531 532 533 534 535 536 537 540 542 544 545 547 
##   1   1   0   1   0   0   1   0   1   0   0   1   1   1   0   1   0   0   0   1 
## 548 549 550 551 552 553 554 555 556 557 558 559 561 562 563 565 566 567 568 569 
##   0   0   0   1   0   0   0   1   0   1   1   1   0   0   0   1   0   0   1   0 
## 571 573 575 576 577 579 580 581 582 583 584 586 588 589 590 591 592 593 594 595 
##   0   0   0   0   1   1   0   1   1   0   0   1   0   0   0   0   1   0   1   0 
## 596 598 599 600 601 602 603 604 605 606 607 608 609 611 612 613 614 616 618 619 
##   0   0   0   0   1   0   1   0   0   0   0   1   1   0   0   1   0   1   1   1 
## 620 621 622 623 625 626 628 630 631 632 633 634 635 636 637 638 639 641 642 643 
##   0   0   0   0   0   0   1   0   0   0   0   1   1   1   0   0   1   0   1   1 
## 644 645 648 649 650 651 654 655 656 657 659 660 661 662 665 666 667 668 669 671 
##   0   1   0   0   1   0   1   1   0   0   0   0   0   0   0   0   0   0   0   1 
## 672 673 674 675 676 677 679 681 682 683 684 685 687 688 689 691 692 694 696 697 
##   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   1   0   0   0 
## 698 699 700 701 702 703 704 706 707 708 709 710 711 712 715 716 718 719 720 722 
##   1   0   0   1   0   1   0   0   1   0   1   0   1   1   0   0   1   0   0   0 
## 723 724 725 726 728 730 732 734 735 736 737 738 740 741 742 743 745 746 749 751 
##   0   0   0   0   1   1   0   0   0   0   0   0   0   1   0   1   0   0   1   1 
## 753 754 755 757 758 759 760 761 762 763 765 767 768 769 770 774 775 776 777 778 
##   0   0   1   0   0   0   1   0   0   0   0   1   1   0   0   0   1   0   0   1 
## 779 781 783 784 785 786 787 788 789 790 791 792 794 796 797 798 799 801 802 803 
##   0   1   1   0   0   0   1   0   0   0   0   0   1   0   1   1   0   0   1   1 
## 804 806 807 808 809 810 811 812 813 814 815 816 818 819 820 821 822 823 824 825 
##   0   0   0   1   0   1   0   0   0   1   0   1   0   0   0   1   0   0   1   0 
## 826 828 829 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 
##   0   1   0   1   0   0   0   0   1   0   0   0   1   0   0   1   0   0   0   0 
## 848 849 850 851 852 853 854 855 856 857 858 859 860 861 863 864 866 867 868 869 
##   0   0   1   0   0   1   1   1   1   1   0   1   0   0   1   0   1   1   1   0 
## 870 871 873 874 875 876 878 879 880 881 882 883 885 886 887 888 889 890 891 
##   0   0   0   0   1   1   0   0   1   1   0   1   0   1   0   1   1   1   0
moment=data.frame(titTrain,PredictionModelBin)
table=table(predicted=PredictionModelBin,Actual=titTrain$Survived)
table 
##          Actual
## predicted   0   1
##         0 372  79
##         1  72 196
sum(diag(table))/sum(table)
## [1] 0.7899861

on en conclu que le model c’est trompé de 20.9%

essayons d’estimer la qualité du modèle par la matrice de confusion titTrain

#predictionTestModel11=predict(model11, titantTest)
#titantTest$predicTestmodel11=predictionTestModel11
#predictionTestModel11
#a=fitted.values(model1)
PredictionModel21=predict.glm(model2, type = "response", newdata = titTrain)
PredictionModel21
##           1           2           3           4           5           6 
## 0.088678199 0.900164558 0.641961571 0.909932762 0.075249134 0.095930678 
##           7           8           9          10          11          12 
## 0.300509692 0.099775111 0.633199667 0.886079260 0.751009916 0.852554259 
##          13          15          16          17          18          19 
## 0.125656592 0.738643053 0.692260024 0.074893108 0.285613859 0.520030951 
##          20          21          23          24          25          26 
## 0.624348812 0.234652796 0.731256666 0.535203451 0.580318929 0.453813778 
##          27          29          30          31          32          33 
## 0.095930678 0.624348812 0.095930678 0.422140537 0.929448863 0.624348812 
##          35          36          37          38          39          40 
## 0.456839085 0.330936176 0.095930678 0.121549235 0.564391605 0.673664479 
##          42          43          44          45          46          47 
## 0.826115586 0.095930678 0.921898300 0.700426130 0.095930678 0.071930798 
##          48          49          50          51          52          53 
## 0.624348812 0.053579352 0.639484231 0.062770248 0.121549235 0.855935599 
##          54          55          56          57          58          60 
## 0.814950494 0.220631248 0.535203451 0.890901748 0.094298868 0.040339490 
##          61          63          64          66          68          70 
## 0.117558085 0.306249168 0.093166912 0.071930798 0.129882223 0.057557881 
##          71          72          73          74          75          77 
## 0.255695539 0.352625099 0.342686933 0.077160913 0.083557824 0.095930678 
##          78          79          80          81          82          83 
## 0.095930678 0.528345224 0.606400856 0.117558085 0.092691969 0.624348812 
##          85          86          87          88          89          90 
## 0.904794070 0.348891257 0.108867440 0.095930678 0.894693934 0.109915908 
##          91          94          95          96          97          98 
## 0.092691969 0.077160913 0.031713083 0.095930678 0.183995083 0.581916794 
##          99         100         101         102         103         104 
## 0.832998038 0.188708451 0.624348812 0.095930678 0.600245213 0.080699547 
##         105         106         108         109         110         111 
## 0.038686754 0.095930678 0.095930678 0.067705593 0.548330281 0.359063261 
##         113         114         115         116         117         119 
## 0.117558085 0.621821398 0.716093911 0.121549235 0.020737040 0.572663625 
##         120         121         122         123         124         125 
## 0.559092782 0.217620657 0.095930678 0.197571169 0.840761597 0.300509692 
##         129         130         131         132         133         134 
## 0.548330281 0.052753980 0.080699547 0.125656592 0.371321265 0.814950494 
##         135         137         138         140         141         142 
## 0.309379246 0.962081325 0.374173380 0.572663625 0.624348812 0.676025936 
##         143         144         145         146         147         149 
## 0.585551755 0.129882223 0.368749966 0.291187269 0.099270169 0.224592233 
##         150         152         153         154         155         157 
## 0.190361587 0.942987032 0.036051852 0.061961383 0.095930678 0.723739603 
##         158         159         160         163         164         166 
## 0.089551770 0.095930678 0.008524475 0.102712705 0.138696292 0.179049448 
##         170         171         172         173         174         176 
## 0.095930678 0.247812784 0.069805081 0.771670111 0.121549235 0.101725094 
##         177         178         183         184         185         186 
## 0.039709517 0.886767171 0.058453775 0.372574724 0.805044678 0.535203451 
##         187         188         189         190         191         192 
## 0.548330281 0.376696851 0.046866968 0.072652542 0.843283619 0.359967966 
##         193         194         195         196         198         199 
## 0.630696577 0.429741644 0.907682097 0.852554259 0.058736614 0.624348812 
##         201         202         203         204         205         206 
## 0.095930678 0.008524475 0.077930729 0.051814525 0.134228139 0.816672995 
##         207         209         210         211         212         213 
## 0.062439591 0.723739603 0.422140537 0.109915908 0.827656090 0.117558085 
##         214         215         216         217         219         222 
## 0.270394336 0.071930798 0.921614936 0.633199667 0.939385723 0.293413468 
##         223         224         225         226         227         228 
## 0.042474868 0.095930678 0.365336971 0.117558085 0.359967966 0.123588258 
##         231         232         233         234         235         236 
## 0.909932762 0.092691969 0.109847299 0.530890876 0.317539374 0.624348812 
##         237         239         240         242         244         245 
## 0.137332552 0.359967966 0.248545879 0.548330281 0.117558085 0.089551770 
##         246         249         250         251         252         254 
## 0.250881694 0.374173380 0.098249868 0.095930678 0.538922750 0.067029440 
##         255         256         257         258         259         260 
## 0.503772087 0.615414104 0.947468245 0.943562866 0.932575132 0.731118792 
##         261         262         263         264         265         267 
## 0.095930678 0.072307840 0.252909695 0.422140537 0.624348812 0.045445673 
##         268         270         271         272         273         275 
## 0.079904750 0.932575132 0.535203451 0.106260539 0.792750632 0.624348812 
##         276         277         278         279         280         281 
## 0.777482467 0.465905186 0.285613859 0.062770248 0.482129327 0.025423751 
##         282         283         284         286         287         289 
## 0.095930678 0.143288564 0.129882223 0.080699547 0.089551770 0.190361587 
##         290         291         292         293         295         297 
## 0.676025936 0.951117377 0.948803652 0.227911357 0.109915908 0.111784611 
##         298         300         301         302         303         304 
## 0.972459562 0.886767171 0.624348812 0.053579352 0.129882223 0.862302338 
##         305         306         307         310         311         312 
## 0.095930678 0.701363308 0.947468245 0.943562866 0.954525188 0.933598825 
##         313         314         315         316         317         318 
## 0.831495562 0.095930678 0.141887108 0.641961571 0.841856111 0.129802969 
##         319         320         321         322         325         328 
## 0.941509257 0.893139105 0.117558085 0.099270169 0.008524475 0.822179744 
##         329         330         332         333         334         336 
## 0.520030951 0.966020090 0.372255632 0.440741693 0.081924331 0.095930678 
##         337         338         340         341         342         343 
## 0.447446231 0.916782761 0.376696851 0.439058158 0.891067397 0.285613859 
##         344         345         346         347         348         349 
## 0.309379246 0.227911357 0.879343229 0.798911639 0.548330281 0.166671564 
##         350         351         352         353         355         357 
## 0.058736614 0.113681027 0.535203451 0.112601188 0.095930678 0.957705990 
##         358         360         361         363         365         367 
## 0.810819805 0.624348812 0.046866968 0.465905186 0.071930798 0.796541162 
##         369         370         371         372         373         374 
## 0.624348812 0.954525188 0.485175719 0.101725094 0.129882223 0.591112662 
##         375         376         377         379         380         382 
## 0.625669362 0.929448863 0.676025936 0.125656592 0.129882223 0.822282275 
##         383         384         385         386         387         388 
## 0.083557824 0.909932762 0.095930678 0.368749966 0.057864282 0.822179744 
##         389         390         391         394         396         398 
## 0.095930678 0.904794070 0.383094506 0.940913782 0.117558085 0.168073564 
##         400         401         403         404         405         406 
## 0.862302338 0.065350907 0.612863850 0.071930798 0.692409441 0.188708451 
##         407         408         409         410         411         412 
## 0.042474868 0.429741644 0.121549235 0.393096051 0.095930678 0.095930678 
##         413         414         415         416         417         420 
## 0.915958025 0.285613859 0.054681335 0.624348812 0.784638341 0.766849710 
##         421         422         423         424         425         426 
## 0.095930678 0.121549235 0.092691969 0.548330281 0.101725094 0.095930678 
##         427         428         429         430         432         433 
## 0.820600900 0.898057504 0.095930678 0.083557824 0.548330281 0.728997928 
##         434         435         436         437         438         440 
## 0.138696292 0.267505903 0.957267925 0.536247496 0.795431561 0.262978890 
##         441         442         444         445         446         447 
## 0.705947911 0.125656592 0.862302338 0.095930678 0.740991131 0.917082022 
##         448         449         451         452         453         454 
## 0.478395306 0.679606546 0.177370642 0.071930798 0.516296037 0.275001371 
##         455         456         457         459         460         461 
## 0.095930678 0.092691969 0.220631248 0.731118792 0.095930678 0.350383906 
##         462         463         464         465         467         468 
## 0.077930729 0.359063261 0.157734481 0.095930678 0.285613859 0.284812870 
##         469         470         471         472         474         475 
## 0.095930678 0.713639023 0.095930678 0.067705593 0.883308967 0.676025936 
##         476         477         479         480         482         483 
## 0.535203451 0.188708451 0.117558085 0.816672995 0.285613859 0.044044139 
##         484         485         486         487         488         490 
## 0.305943991 0.485175719 0.393096051 0.909932762 0.269619920 0.137415677 
##         491         492         493         494         495         496 
## 0.071930798 0.121549235 0.292599563 0.183995083 0.121549235 0.095930678 
##         497         498         499         500         501         502 
## 0.830944352 0.095930678 0.936553754 0.109915908 0.138696292 0.684274923 
##         504         505         506         507         509         510 
## 0.541595764 0.966020090 0.551349631 0.838206776 0.095930678 0.102712705 
##         512         513         514         515         516         518 
## 0.095930678 0.459510715 0.830944352 0.109915908 0.359063261 0.095930678 
##         519         521         522         524         525         526 
## 0.771546494 0.943562866 0.117558085 0.907682097 0.095930678 0.061961383 
##         527         529         531         532         533         534 
## 0.731118792 0.065350907 0.924585297 0.095930678 0.105242816 0.624348812 
##         535         536         537         540         542         544 
## 0.606400856 0.932821763 0.376696851 0.957705990 0.493010759 0.200594268 
##         545         547         548         549         550         551 
## 0.267505903 0.865495397 0.285613859 0.060256211 0.384023482 0.636028266 
##         552         553         554         555         556         557 
## 0.293413468 0.095930678 0.117558085 0.676025936 0.240812226 0.860548689 
##         558         559         561         562         563         565 
## 0.535203451 0.896704667 0.095930678 0.063072574 0.285613859 0.624348812 
##         566         567         568         569         571         573 
## 0.061812541 0.129882223 0.615414104 0.095930678 0.099207465 0.459510715 
##         575         576         577         579         580         581 
## 0.143288564 0.129882223 0.832998038 0.548330281 0.083557824 0.836741977 
##         582         583         584         586         588         589 
## 0.896704667 0.129802969 0.459510715 0.963440696 0.199964971 0.117558085 
##         590         591         592         593         594         595 
## 0.095930678 0.075249134 0.841332325 0.049090211 0.624348812 0.171905248 
##         596         598         599         600         601         602 
## 0.054127699 0.045668623 0.095930678 0.275001371 0.795431561 0.095930678 
##         603         604         605         606         607         608 
## 0.535203451 0.054681335 0.468941892 0.054127699 0.089551770 0.544622746 
##         609         611         612         613         614         616 
## 0.851693259 0.444432231 0.095930678 0.548330281 0.095930678 0.841856111 
##         618         619         620         621         622         623 
## 0.567035590 0.892485212 0.301336226 0.074503667 0.330936176 0.095001375 
##         625         626         628         630         631         632 
## 0.121549235 0.247812784 0.959215566 0.095930678 0.138144065 0.042474868 
##         633         634         635         636         637         638 
## 0.497341853 0.535203451 0.571056463 0.862302338 0.083557824 0.206744054 
##         639         641         642         643         644         645 
## 0.503772087 0.125656592 0.954525188 0.634507316 0.095930678 0.713639023 
##         648         649         650         651         654         655 
## 0.284812870 0.095930678 0.667666101 0.095930678 0.624348812 0.708321898 
##         656         657         659         660         661         662 
## 0.198874097 0.095930678 0.325813193 0.269619920 0.210579608 0.063072574 
##         665         666         667         668         669         671 
## 0.095001375 0.154895984 0.309379246 0.095930678 0.056674892 0.743718157 
##         672         673         674         675         676         677 
## 0.428779059 0.075200336 0.262978890 0.285613859 0.134228139 0.108074642 
##         679         681         682         683         684         685 
## 0.407364089 0.624348812 0.544622746 0.125656592 0.036158717 0.079853194 
##         687         688         689         691         692         694 
## 0.048851412 0.129882223 0.134228139 0.428779059 0.805044678 0.106260539 
##         696         697         698         699         700         701 
## 0.138612517 0.054681335 0.624348812 0.275001371 0.058736614 0.950614589 
##         702         703         704         706         707         708 
## 0.468941892 0.708321898 0.106260539 0.208514579 0.766724271 0.403757661 
##         709         710         711         712         715         716 
## 0.957705990 0.071930798 0.954525188 0.535203451 0.138612517 0.129882223 
##         718         719         720         722         723         724 
## 0.866743297 0.095930678 0.080699547 0.105242816 0.241531262 0.147918325 
##         725         726         728         730         732         734 
## 0.466262730 0.125656592 0.624348812 0.576320463 0.168171668 0.325813193 
##         735         736         737         738         740         741 
## 0.325813193 0.094298868 0.362513195 0.468941892 0.095930678 0.535203451 
##         742         743         745         746         749         751 
## 0.383094506 0.926189111 0.086507812 0.146076275 0.541952455 0.919123940 
##         753         754         755         757         758         759 
## 0.080699547 0.113681027 0.681793141 0.095930678 0.368749966 0.077930729 
##         760         761         762         763         765         767 
## 0.937190236 0.095930678 0.060868497 0.125656592 0.143288564 0.535203451 
##         768         769         770         774         775         776 
## 0.601866497 0.071930798 0.083557824 0.095930678 0.630533179 0.134228139 
##         777         778         779         781         783         784 
## 0.095930678 0.799024307 0.095930678 0.745896971 0.525758977 0.071930798 
##         785         786         787         788         789         790 
## 0.106260539 0.106260539 0.708321898 0.060576053 0.177473016 0.367835875 
##         791         792         794         796         797         798 
## 0.095930678 0.386572349 0.535203451 0.208514579 0.890519280 0.597314590 
##         799         801         802         803         804         806 
## 0.089551770 0.241531262 0.803239243 0.615754107 0.231929593 0.086507812 
##         807         808         809         810         811         812 
## 0.431416930 0.708321898 0.208514579 0.915958025 0.102712705 0.065350907 
##         813         814         815         816         818         819 
## 0.234652796 0.521437128 0.088017903 0.535203451 0.206744054 0.056674892 
##         820         821         822         823         824         825 
## 0.075642153 0.841332325 0.099270169 0.440741693 0.633199667 0.074893108 
##         826         828         829         831         832         833 
## 0.095930678 0.526738517 0.095930678 0.665273880 0.450012798 0.095930678 
##         834         835         836         837         838         839 
## 0.113681027 0.134228139 0.896704667 0.121549235 0.095930678 0.083557824 
##         840         841         842         843         844         845 
## 0.535203451 0.125656592 0.386572349 0.943562866 0.076579168 0.138696292 
##         846         847         848         849         850         851 
## 0.058736614 0.008524475 0.075249134 0.285613859 0.929448863 0.069805081 
##         852         853         854         855         856         857 
## 0.018206566 0.713900910 0.966020090 0.713757618 0.708321898 0.873648959 
##         858         859         860         861         863         864 
## 0.324950746 0.659199296 0.095930678 0.033424091 0.894161897 0.118686855 
##         866         867         868         869         870         871 
## 0.786451319 0.826115586 0.506821396 0.095930678 0.161471134 0.102712705 
##         873         874         875         876         878         879 
## 0.487864221 0.049090211 0.820600900 0.731256666 0.129882223 0.095930678 
##         880         881         882         883         885         886 
## 0.861835157 0.875261747 0.080699547 0.676025936 0.106260539 0.522716492 
##         887         888         889         890         891 
## 0.293413468 0.962081325 0.548330281 0.554010222 0.083557824
PredictionModelBin=ifelse(PredictionModel21>0.5,1,0)
PredictionModelBin
##   1   2   3   4   5   6   7   8   9  10  11  12  13  15  16  17  18  19  20  21 
##   0   1   1   1   0   0   0   0   1   1   1   1   0   1   1   0   0   1   1   0 
##  23  24  25  26  27  29  30  31  32  33  35  36  37  38  39  40  42  43  44  45 
##   1   1   1   0   0   1   0   0   1   1   0   0   0   0   1   1   1   0   1   1 
##  46  47  48  49  50  51  52  53  54  55  56  57  58  60  61  63  64  66  68  70 
##   0   0   1   0   1   0   0   1   1   0   1   1   0   0   0   0   0   0   0   0 
##  71  72  73  74  75  77  78  79  80  81  82  83  85  86  87  88  89  90  91  94 
##   0   0   0   0   0   0   0   1   1   0   0   1   1   0   0   0   1   0   0   0 
##  95  96  97  98  99 100 101 102 103 104 105 106 108 109 110 111 113 114 115 116 
##   0   0   0   1   1   0   1   0   1   0   0   0   0   0   1   0   0   1   1   0 
## 117 119 120 121 122 123 124 125 129 130 131 132 133 134 135 137 138 140 141 142 
##   0   1   1   0   0   0   1   0   1   0   0   0   0   1   0   1   0   1   1   1 
## 143 144 145 146 147 149 150 152 153 154 155 157 158 159 160 163 164 166 170 171 
##   1   0   0   0   0   0   0   1   0   0   0   1   0   0   0   0   0   0   0   0 
## 172 173 174 176 177 178 183 184 185 186 187 188 189 190 191 192 193 194 195 196 
##   0   1   0   0   0   1   0   0   1   1   1   0   0   0   1   0   1   0   1   1 
## 198 199 201 202 203 204 205 206 207 209 210 211 212 213 214 215 216 217 219 222 
##   0   1   0   0   0   0   0   1   0   1   0   0   1   0   0   0   1   1   1   0 
## 223 224 225 226 227 228 231 232 233 234 235 236 237 239 240 242 244 245 246 249 
##   0   0   0   0   0   0   1   0   0   1   0   1   0   0   0   1   0   0   0   0 
## 250 251 252 254 255 256 257 258 259 260 261 262 263 264 265 267 268 270 271 272 
##   0   0   1   0   1   1   1   1   1   1   0   0   0   0   1   0   0   1   1   0 
## 273 275 276 277 278 279 280 281 282 283 284 286 287 289 290 291 292 293 295 297 
##   1   1   1   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0 
## 298 300 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317 318 319 320 
##   1   1   1   0   0   1   0   1   1   1   1   1   1   0   0   1   1   0   1   1 
## 321 322 325 328 329 330 332 333 334 336 337 338 340 341 342 343 344 345 346 347 
##   0   0   0   1   1   1   0   0   0   0   0   1   0   0   1   0   0   0   1   1 
## 348 349 350 351 352 353 355 357 358 360 361 363 365 367 369 370 371 372 373 374 
##   1   0   0   0   1   0   0   1   1   1   0   0   0   1   1   1   0   0   0   1 
## 375 376 377 379 380 382 383 384 385 386 387 388 389 390 391 394 396 398 400 401 
##   1   1   1   0   0   1   0   1   0   0   0   1   0   1   0   1   0   0   1   0 
## 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 420 421 422 423 424 
##   1   0   1   0   0   0   0   0   0   0   1   0   0   1   1   1   0   0   0   1 
## 425 426 427 428 429 430 432 433 434 435 436 437 438 440 441 442 444 445 446 447 
##   0   0   1   1   0   0   1   1   0   0   1   1   1   0   1   0   1   0   1   1 
## 448 449 451 452 453 454 455 456 457 459 460 461 462 463 464 465 467 468 469 470 
##   0   1   0   0   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   1 
## 471 472 474 475 476 477 479 480 482 483 484 485 486 487 488 490 491 492 493 494 
##   0   0   1   1   1   0   0   1   0   0   0   0   0   1   0   0   0   0   0   0 
## 495 496 497 498 499 500 501 502 504 505 506 507 509 510 512 513 514 515 516 518 
##   0   0   1   0   1   0   0   1   1   1   1   1   0   0   0   0   1   0   0   0 
## 519 521 522 524 525 526 527 529 531 532 533 534 535 536 537 540 542 544 545 547 
##   1   1   0   1   0   0   1   0   1   0   0   1   1   1   0   1   0   0   0   1 
## 548 549 550 551 552 553 554 555 556 557 558 559 561 562 563 565 566 567 568 569 
##   0   0   0   1   0   0   0   1   0   1   1   1   0   0   0   1   0   0   1   0 
## 571 573 575 576 577 579 580 581 582 583 584 586 588 589 590 591 592 593 594 595 
##   0   0   0   0   1   1   0   1   1   0   0   1   0   0   0   0   1   0   1   0 
## 596 598 599 600 601 602 603 604 605 606 607 608 609 611 612 613 614 616 618 619 
##   0   0   0   0   1   0   1   0   0   0   0   1   1   0   0   1   0   1   1   1 
## 620 621 622 623 625 626 628 630 631 632 633 634 635 636 637 638 639 641 642 643 
##   0   0   0   0   0   0   1   0   0   0   0   1   1   1   0   0   1   0   1   1 
## 644 645 648 649 650 651 654 655 656 657 659 660 661 662 665 666 667 668 669 671 
##   0   1   0   0   1   0   1   1   0   0   0   0   0   0   0   0   0   0   0   1 
## 672 673 674 675 676 677 679 681 682 683 684 685 687 688 689 691 692 694 696 697 
##   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   1   0   0   0 
## 698 699 700 701 702 703 704 706 707 708 709 710 711 712 715 716 718 719 720 722 
##   1   0   0   1   0   1   0   0   1   0   1   0   1   1   0   0   1   0   0   0 
## 723 724 725 726 728 730 732 734 735 736 737 738 740 741 742 743 745 746 749 751 
##   0   0   0   0   1   1   0   0   0   0   0   0   0   1   0   1   0   0   1   1 
## 753 754 755 757 758 759 760 761 762 763 765 767 768 769 770 774 775 776 777 778 
##   0   0   1   0   0   0   1   0   0   0   0   1   1   0   0   0   1   0   0   1 
## 779 781 783 784 785 786 787 788 789 790 791 792 794 796 797 798 799 801 802 803 
##   0   1   1   0   0   0   1   0   0   0   0   0   1   0   1   1   0   0   1   1 
## 804 806 807 808 809 810 811 812 813 814 815 816 818 819 820 821 822 823 824 825 
##   0   0   0   1   0   1   0   0   0   1   0   1   0   0   0   1   0   0   1   0 
## 826 828 829 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 
##   0   1   0   1   0   0   0   0   1   0   0   0   1   0   0   1   0   0   0   0 
## 848 849 850 851 852 853 854 855 856 857 858 859 860 861 863 864 866 867 868 869 
##   0   0   1   0   0   1   1   1   1   1   0   1   0   0   1   0   1   1   1   0 
## 870 871 873 874 875 876 878 879 880 881 882 883 885 886 887 888 889 890 891 
##   0   0   0   0   1   1   0   0   1   1   0   1   0   1   0   1   1   1   0
table=table(predicted=PredictionModelBin,Actual=titTrain$Survived)
confusionMatrix( table) 
## Confusion Matrix and Statistics
## 
##          Actual
## predicted   0   1
##         0 372  79
##         1  72 196
##                                              
##                Accuracy : 0.79               
##                  95% CI : (0.7584, 0.8192)   
##     No Information Rate : 0.6175             
##     P-Value [Acc > NIR] : <0.0000000000000002
##                                              
##                   Kappa : 0.5532             
##                                              
##  Mcnemar's Test P-Value : 0.6254             
##                                              
##             Sensitivity : 0.8378             
##             Specificity : 0.7127             
##          Pos Pred Value : 0.8248             
##          Neg Pred Value : 0.7313             
##              Prevalence : 0.6175             
##          Detection Rate : 0.5174             
##    Detection Prevalence : 0.6273             
##       Balanced Accuracy : 0.7753             
##                                              
##        'Positive' Class : 0                  
## 

on en conclu que le model est bon a 79.06%

Matrice de confusion titTest

#predictionTestModel11=predict(model11, titantTest)
#titantTest$predicTestmodel11=predictionTestModel11
#predictionTestModel11
#a=fitted.values(model1)
PredictionModel22=predict.glm(model2,type = "response",newdata = titTest)
PredictionModel22
##         14         22         28         34         41         59         65 
## 0.04859027 0.24153126 0.38697684 0.08645240 0.43509013 0.91625998 0.53520345 
##         67         69         76         84         92         93        107 
## 0.85773767 0.41791984 0.10626054 0.53520345 0.12565659 0.29825238 0.68427492 
##        112        118        126        127        128        136        139 
## 0.66948266 0.21945856 0.12447898 0.09593068 0.10991591 0.32581319 0.14328856 
##        148        151        156        161        162        165        167 
## 0.64572136 0.14320248 0.32495075 0.05468133 0.79891164 0.07756308 0.94746824 
##        168        169        175        179        180        181        182 
## 0.38919130 0.53520345 0.28481287 0.27039434 0.07265254 0.11868686 0.28561386 
##        197        200        208        218        220        221        229 
## 0.09593068 0.87934323 0.10271270 0.14656705 0.27039434 0.14328856 0.36874997 
##        230        238        241        243        247        248        253 
## 0.39309605 0.93040614 0.54833028 0.27794003 0.65062966 0.87934323 0.24081223 
##        266        269        274        285        288        294        296 
## 0.22791136 0.85255426 0.45010845 0.53520345 0.11755808 0.65919930 0.53520345 
##        299        308        309        323        324        326        327 
## 0.53520345 0.95236468 0.21303214 0.85304747 0.85169326 0.93015130 0.02946515 
##        331        335        339        354        356        359        362 
## 0.46998738 0.92944886 0.05275398 0.07990475 0.09593068 0.62434881 0.21945856 
##        364        366        368        378        381        392        393 
## 0.07524913 0.08955177 0.62434881 0.54462275 0.91384367 0.12154924 0.05357935 
##        395        397        399        402        418        419        431 
## 0.65919930 0.59731459 0.32581319 0.10271270 0.90147706 0.27039434 0.53520345 
##        439        443        450        458        466        473        478 
## 0.17679809 0.07990475 0.31668854 0.92944886 0.06770559 0.79097692 0.06944011 
##        481        489        503        508        511        517        520 
## 0.04337996 0.08955177 0.62434881 0.53520345 0.09269197 0.83299804 0.08355782 
##        523        528        530        538        539        541        543 
## 0.09593068 0.53520345 0.20498467 0.94356287 0.09593068 0.93015130 0.47407359 
##        546        560        564        570        572        574        578 
## 0.22722072 0.47266899 0.09593068 0.08355782 0.78853766 0.62434881 0.89670467 
##        585        587        597        610        615        617        624 
## 0.09593068 0.16283794 0.86230234 0.91963041 0.07524913 0.05814444 0.12154924 
##        627        629        640        646        647        652        653 
## 0.11748534 0.10271270 0.07193080 0.28262582 0.12988222 0.90147706 0.12154924 
##        658        663        664        670        678        680        686 
## 0.51056012 0.35906326 0.07265254 0.92944886 0.70832190 0.45951072 0.24654132 
##        690        693        695        705        713        714        717 
## 0.96724306 0.09593068 0.25494851 0.07716091 0.28262582 0.09269197 0.92506035 
##        721        727        729        731        733        739        744 
## 0.93515938 0.69345905 0.24654132 0.94554854 0.28561386 0.09593068 0.08273741 
##        747        748        750        752        756        764        766 
## 0.10886744 0.85304747 0.08650781 0.19638537 0.45151489 0.90677634 0.84632907 
##        771        772        773        780        782        793        795 
## 0.10991591 0.04735006 0.67587229 0.91081087 0.95236468 0.11868686 0.10626054 
##        800        805        817        827        862        865        872 
## 0.52948741 0.09927017 0.66766610 0.09593068 0.27578541 0.31753937 0.86503735 
##        877        884 
## 0.12565659 0.28561386
PredictionModelBin2=ifelse(PredictionModel22>0.5,1,0)
PredictionModelBin2
##  14  22  28  34  41  59  65  67  69  76  84  92  93 107 112 118 126 127 128 136 
##   0   0   0   0   0   1   1   1   0   0   1   0   0   1   1   0   0   0   0   0 
## 139 148 151 156 161 162 165 167 168 169 175 179 180 181 182 197 200 208 218 220 
##   0   1   0   0   0   1   0   1   0   1   0   0   0   0   0   0   1   0   0   0 
## 221 229 230 238 241 243 247 248 253 266 269 274 285 288 294 296 299 308 309 323 
##   0   0   0   1   1   0   1   1   0   0   1   0   1   0   1   1   1   1   0   1 
## 324 326 327 331 335 339 354 356 359 362 364 366 368 378 381 392 393 395 397 399 
##   1   1   0   0   1   0   0   0   1   0   0   0   1   1   1   0   0   1   1   0 
## 402 418 419 431 439 443 450 458 466 473 478 481 489 503 508 511 517 520 523 528 
##   0   1   0   1   0   0   0   1   0   1   0   0   0   1   1   0   1   0   0   1 
## 530 538 539 541 543 546 560 564 570 572 574 578 585 587 597 610 615 617 624 627 
##   0   1   0   1   0   0   0   0   0   1   1   1   0   0   1   1   0   0   0   0 
## 629 640 646 647 652 653 658 663 664 670 678 680 686 690 693 695 705 713 714 717 
##   0   0   0   0   1   0   1   0   0   1   1   0   0   1   0   0   0   0   0   1 
## 721 727 729 731 733 739 744 747 748 750 752 756 764 766 771 772 773 780 782 793 
##   1   1   0   1   0   0   0   0   1   0   0   0   1   1   0   0   1   1   1   0 
## 795 800 805 817 827 862 865 872 877 884 
##   0   1   0   1   0   0   0   1   0   0
library(caret)
table=table(predicted=PredictionModelBin2,Actual=titTest$Survived)
confusionMatrix( table) 
## Confusion Matrix and Statistics
## 
##          Actual
## predicted  0  1
##         0 86 20
##         1 19 45
##                                        
##                Accuracy : 0.7706       
##                  95% CI : (0.7, 0.8315)
##     No Information Rate : 0.6176       
##     P-Value [Acc > NIR] : 0.00001576   
##                                        
##                   Kappa : 0.5129       
##                                        
##  Mcnemar's Test P-Value : 1            
##                                        
##             Sensitivity : 0.8190       
##             Specificity : 0.6923       
##          Pos Pred Value : 0.8113       
##          Neg Pred Value : 0.7031       
##              Prevalence : 0.6176       
##          Detection Rate : 0.5059       
##    Detection Prevalence : 0.6235       
##       Balanced Accuracy : 0.7557       
##                                        
##        'Positive' Class : 0            
## 

on en conclu que le model est bon a 79.41%

3)normalité des residus

shapiro.test(residuals.glm(model2))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals.glm(model2)
## W = 0.94297, p-value = 0.0000000000000005377
#plot(residuals.glm(model2))
hist(residuals.glm(model2),col="yellow",freq=F)
densite <- density(residuals.lm(model2)) # estimer la densité que line représente ces différentes  l'histogramme
lines(densite)

construction d’un individus pour prediction

 ff<- data.frame(Sex="male", Age=28 ,Pclass="1",SibSp=0) ## on construit un personnage
 predict(model2,ff,type = "response")  
##         1 
## 0.5352035