From 3809419992d22303b1a92805911f1d63c9d746e0 Mon Sep 17 00:00:00 2001 From: 16fd6933414ad4ae0fb1412e7effdbc7 <16fd6933414ad4ae0fb1412e7effdbc7@app-learninglab.inria.fr> Date: Tue, 16 Jun 2020 17:33:07 +0000 Subject: [PATCH] Replace exercice_en.Rmd --- module3/exo3/exercice_en.Rmd | 545 +++++++++++++++++++++++++++++++++-- 1 file changed, 523 insertions(+), 22 deletions(-) diff --git a/module3/exo3/exercice_en.Rmd b/module3/exo3/exercice_en.Rmd index 13b258d..4987c82 100644 --- a/module3/exo3/exercice_en.Rmd +++ b/module3/exo3/exercice_en.Rmd @@ -1,33 +1,534 @@ ---- -title: "Your title" -author: "Your name" -date: "Today's date" -output: html_document ---- + + -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -``` +
-## Some explanations + + + -This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, seemodule3_Practical_session_Subject6_smoking <- read.csv("~/R/module3_Practical_session_Subject6_smoking.csv")
+module3_Practical_session_Subject6_smoking$Smoker <- as.factor(module3_Practical_session_Subject6_smoking$Smoker)
+module3_Practical_session_Subject6_smoking$Status <- as.factor(module3_Practical_session_Subject6_smoking$Status)
+module3_Practical_session_Subject6_smoking$AgeG <- as.factor(module3_Practical_session_Subject6_smoking$AgeG)
+sapply(module3_Practical_session_Subject6_smoking, class)
+## Smoker Status Age AgeG
+## "factor" "factor" "numeric" "factor"
+tabulate(module3_Practical_session_Subject6_smoking$Smoker)
+## [1] 732 582
+module3_Practical_session_Subject6_smoking.tab <- table(module3_Practical_session_Subject6_smoking$Status, module3_Practical_session_Subject6_smoking$Smoker)
+TAB=table(module3_Practical_session_Subject6_smoking$Status, module3_Practical_session_Subject6_smoking$Smoker)
+barplot(TAB, beside=T, legend=T)
+chisq.test(TAB, correct=T)
+##
+## Pearson's Chi-squared test with Yates' continuity correction
+##
+## data: TAB
+## X-squared = 8.7515, df = 1, p-value = 0.003093
+fisher.test(TAB)
+##
+## Fisher's Exact Test for Count Data
+##
+## data: TAB
+## p-value = 0.002989
+## alternative hypothesis: true odds ratio is not equal to 1
+## 95 percent confidence interval:
+## 0.5307485 0.8822128
+## sample estimates:
+## odds ratio
+## 0.6850392
+TAB1=table(module3_Practical_session_Subject6_smoking$Status, module3_Practical_session_Subject6_smoking$Smoker, module3_Practical_session_Subject6_smoking$AgeG)
+prop.table(TAB1)
+## , , = 18-34
+##
+##
+## No Yes
+## Alive 0.168188737 0.138508371
+## Dead 0.004566210 0.005327245
+##
+## , , = 35-54
+##
+##
+## No Yes
+## Alive 0.130898021 0.143835616
+## Dead 0.014459665 0.029680365
+##
+## , , = 55-64
+##
+##
+## No Yes
+## Alive 0.061643836 0.049467275
+## Dead 0.030441400 0.038812785
+##
+## , , = Over 64
+##
+##
+## No Yes
+## Alive 0.021308980 0.005327245
+## Dead 0.125570776 0.031963470
+Death <- module3_Practical_session_Subject6_smoking$Status
+Deathcode<-ifelse(Death == "Alive", 1, 0)
+logistic <- glm(Deathcode ~ module3_Practical_session_Subject6_smoking$Age, binomial)
+summary(logistic)
+##
+## Call:
+## glm(formula = Deathcode ~ module3_Practical_session_Subject6_smoking$Age,
+## family = binomial)
+##
+## Deviance Residuals:
+## Min 1Q Median 3Q Max
+## -2.8803 -0.4551 0.2848 0.5897 2.3335
+##
+## Coefficients:
+## Estimate Std. Error z value
+## (Intercept) 6.104537 0.321414 18.99
+## module3_Practical_session_Subject6_smoking$Age -0.097651 0.005555 -17.58
+## Pr(>|z|)
+## (Intercept) <2e-16 ***
+## module3_Practical_session_Subject6_smoking$Age <2e-16 ***
+## ---
+## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+##
+## (Dispersion parameter for binomial family taken to be 1)
+##
+## Null deviance: 1560.3 on 1313 degrees of freedom
+## Residual deviance: 1004.8 on 1312 degrees of freedom
+## AIC: 1008.8
+##
+## Number of Fisher Scoring iterations: 5
+plot(module3_Practical_session_Subject6_smoking$Age, jitter(Deathcode, 0.5), xlab = "module3_Practical_session_Subject6_smoking$Age", ylab = "DeathCode (0 - Dead, 1 - Alive")
+plot(module3_Practical_session_Subject6_smoking$Age,fitted.values(logistic))
+