--- title: "Statistiques descriptives de l'expérience" author: "Adrien Coiffard" date: "09/05/2022" output: html_document --- ```{r setup, include=FALSE} rm(list = ls()) library(tidyverse) library(cowplot) #knitr::opts_knit$set(root.dir = '/tmp') knitr::opts_chunk$set(echo = FALSE) ## par défaut echo = FALSE ``` ## Import des données On souhaite comparer les caractéristiques socio demographiques de deux échantillons de sujets. Pour cela on importe tout d'abord les données au format .csv . ```{r, echo=TRUE} df <- read.csv("data_StatsDesc.csv") ``` ## Statistiques de base (ensemble de l'échantillon) ```{r} attach(df) #create new summary function mySummary <- function(vector){ results <- c(summary(vector), 'Std. Dev' = sd(vector, na.rm=T)) results <- round(results, 2) return(results) } my_ppt_theme <- theme_bw() + theme(axis.text.x = element_text(size=12), axis.text.y = element_text(size=12), axis.title.x = element_text(size=14), axis.title.y = element_text(size=14), legend.text = element_text(size=12), legend.title = element_text(size=14), text = element_text(size=16), plot.title = element_text(hjust = 0.5), plot.margin = unit(c(0.5,0.1,0.2,0.2), "cm")) theme_set(my_ppt_theme) ``` Réalisons tout d'abord une série de statistiques descriptives sur l'ensemble de l'échantillon. *Question : Was it easy to accomplish the exercice ? (From 0: not at all, to 10: very easy)* ```{r easybid} mySummary(easyBid) ``` *Questions : Are you a person who is generally risk-taking or do you try to avoid taking risks as much as* *possible? (From 0: avoid taking risks as much as possible, to 10: very comfortable with the idea* *of taking risks)* ```{r risk} mySummary(risk) ``` ## Graphiques (par traitements) ```{r} detach(df) ``` Maintenant regardons graphiquement s'il y a des différences entre les deux traitements (lignes discontinues verticales = moyennes par traitements).
*Question : Was it easy to accomplish the exercice ? From 0: not at all, to 10: very easy* ```{r} # Treatment 1 p1 <- df %>% filter(treatment==0) %>% ggplot(aes(x=as.factor(easyBid)))+ geom_bar(aes(y = ..count..),fill="darkblue", width = 0.5) + geom_vline(aes(xintercept=mean(easyBid)),size=0.9, color="darkblue",linetype = "dashed")+ scale_y_continuous(breaks=seq(0,40,10),limits = c(0,40))+ labs(title="Treatment 1", x="", y = "Nb of Subjects") # Treatment 2 p2 <- df %>% filter(treatment==1) %>% ggplot(aes(x=as.factor(easyBid)))+ geom_bar(aes(y = ..count..),fill="orange2", width = 0.5) + geom_vline(aes(xintercept=mean(easyBid)),size=0.9, color="orange2",linetype = "dashed")+ scale_y_continuous(breaks=seq(0,40,10),limits = c(0,40))+ labs(title="Treatment 2", x="", y = "") plot_grid(p1, p2, ncol=2) # ggplot(df, aes(x=as.factor(easyBid), fill=as.factor(treatment)))+ # geom_bar(aes(y = (..count..)/sum(..count..)), position="dodge") + # ylab('Percent of participants, %') + # scale_y_continuous(labels=scales::percent) ``` Ils semblerait que les sujets aient éprouvé un niveau de difficulté semblable dans les deux traitements. On peut tester cette hypothèse en réalisant un Kruskal–Wallis test : ```{r} kruskal.test(easyBid ~ treatment, data = df) ```
*Question : Are you a person who is generally risk-taking or do you try to avoid taking risks as much as* *possible? (From 0 "avoid taking risks as much as possible", to 10 "very comfortable with the idea* *of taking risks")* ```{r} # Treatment 1 p1 <- df %>% filter(treatment==0) %>% ggplot(aes(x=as.factor(risk)))+ geom_bar(aes(y = ..count..),fill="darkblue", width = 0.5) + geom_vline(aes(xintercept=mean(risk)),size=0.9, color="darkblue",linetype = "dashed")+ scale_y_continuous(breaks=seq(0,40,10),limits = c(0,40))+ labs(title="Treatment 1", x="", y = "Nb of Subjects") # Treatment 2 p2 <- df %>% filter(treatment==1) %>% ggplot(aes(x=as.factor(risk)))+ geom_bar(aes(y = ..count..),fill="orange2", width = 0.5) + geom_vline(aes(xintercept=mean(risk)),size=0.9, color="orange2",linetype = "dashed")+ scale_y_continuous(breaks=seq(0,40,10),limits = c(0,40))+ labs(title="Treatment 2", x="", y = "") plot_grid(p1, p2, ncol=2) ``` Ils semblerait qu'il n'y ait pas non plus de différence significative entre les deux traitements sur l'aversion au risque. On peut à nouveau tester cette hypothèse en réalisant un Kruskal–Wallis test : ```{r} kruskal.test(risk ~ treatment, data = df) ```