<jupyter_start><jupyter_text>TD4<jupyter_code>sigmoid <- function(x) {
  return (exp(x)/(1+exp(x)))
}
df <- read.table("titanic.csv", sep=";", header=TRUE, dec=",", na.strings = "")
df$pclass <- factor(df$pclass)
df$survived <- factor(df$survived)
df <- df[complete.cases(df),]
surv.null <- glm(survived ~ 1, family = binomial, data = df)
surv.null
surv.all<-glm(survived~pclass+sex+age+sibsp+parch+embarked,family=binomial,data=df)
summary(surv.all)
1-pchisq(q=surv.all$null.deviance-surv.all$deviance,df=surv.all$df.null-surv.all$df.residual)
install.packages('car')
library('car')
Anova(surv.all,type="II",test="Wald")
surv.back <- step(surv.all, direction = 'backward')
formula(surv.back)
surv.forw <- step(surv.null, scope = list(lower=surv.null, upper=surv.all),
direction = 'forward')
formula(surv.forw)
surv.step <- step(surv.null, scope = list(lower=surv.null, upper=surv.all),
direction = 'both')
formula(surv.step)
df$pclass<-relevel(df$pclass,ref='3')
df$sex<-relevel(df$sex,ref='male')
df$survived <- relevel(df$survived, ref="0")
surv.mix<-glm(survived~pclass+sex+age+embarked+ sibsp,family=binomial,data=df)
summary(surv.mix)<jupyter_output><empty_output><jupyter_text>Leonardo<jupyter_code>sigmoid(4.318413-2.070791-2.633189-20*0.038360-0.668673)<jupyter_output><empty_output><jupyter_text>Rose<jupyter_code>sigmoid(-0.385566+2.070791+2.633189-28*0.038360-0.668673-0.332367)
newdata = data.frame(pclass = '3',age=20,sex='male')
lin = predict(surv.mix, newdata)
exp(lin)/(1+exp(lin))
newdata = data.frame(pclass = '1',age=28,sex='female')
lin = predict(surv.mix, newdata)
exp(lin)/(1+exp(lin))
newdata = data.frame(pclass = c('3','1'),age=c(20,28),sex=c('male','female'))
lin = predict(surv.mix, newdata)
exp(lin)/(1+exp(lin))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21287408243929984, 'fraction_numerical': 0.05759457933370977, 'mean_word_length': 8.277486910994764, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '50969', 'license': 'MIT', 'n_tokens_mistral': 862, 'n_tokens_neox': 777, 'n_words': 80, 'path': 'cours/reg_log_stid/TP/corrections/td4_reglog_2020.ipynb', 'repo_name': 'tvayer/tvayer.github.io', 'size': '1771'}