Setup

#this is to check to see if package are installed and if not to install them or just load them if they are installed!
if(!require(pacman)) {install.packages(c("pacman", "remotes"))}

if(!require(papaja)) {remotes::install_github("crsh/papaja")}

pacman::p_load(here, tinylabels, apaTables, tidyverse, gtsummary, car, GGally, MASS, rcompanion, moments, utils, sjPlot, interactions, kableExtra, report, papaja, bookdown)

p_load_gh("crsh/papaja@devel")


#get relative path
path =  here("RESSOURCES") #this is really important ! you juste need to put the name of YOUR folder and here() will find the relative path for you !
setwd(path) #set working directory

# load data
base  <- read.csv("data.csv")


session = utils::sessionInfo() # get session informations

#opts_chunk$set(echo = F, message=F, warning=F) # set echo F for all
options(scipen = 666, warn=-1, contrasts=c("contr.sum","contr.poly"), knitr.kable.NA = '')  #remove scientific notation # remove warnings #set contrasts to sum ! 
set.seed(666) #set random seed

`%notin%` <- Negate(`%in%`)

# panderOptions('knitr.auto.asis', FALSE) #remove auto styling

\(~\) \(~\)

Introduction

Blabla citation in parentesis (James 1890) blbabla, or citation in text James (1890)

\(~\) \(~\)

Clean up

\(~\) \(~\)

base$Priming = as.factor(base$Priming); base$Product = as.factor(base$Product); 

\(~\) \(~\)

Demographics

\(~\) \(~\)

base[c("Age", "Gender", "Profession")] %>%  tbl_summary(statistic = list(all_continuous() ~ "{mean} ({sd})", all_categorical() ~ "{n} / {N} ({p}%)"),)  %>% modify_caption("**Table 1. Demographics **") %>%bold_labels()
**Table 1. Demographics **
Characteristic N = 2961
Age 22 (4)
Gender
Autre/NA 2 / 296 (0.7%)
Femme 239 / 296 (81%)
Homme 55 / 296 (19%)
Profession
Actif.ve 3 / 296 (1.0%)
Etudiant.e 291 / 296 (98%)
Les deux 2 / 296 (0.7%)

1 Mean (SD); n / N (%)

\(~\) \(~\)

Inspections

\(~\) \(~\)

base %>% 
  keep(is.numeric) %>%
  gather() %>%
  ggplot(aes(value)) +
  facet_wrap(~key, scales = "free") + 
  geom_histogram()

#or GGally

\(~\) \(~\)

ggplot(base, aes(x=Priming, y=Age)) +
  geom_violin(trim=FALSE, fill='#A4A4A4', color="darkred")+
  geom_boxplot(width=0.1) + theme_minimal()

\(~\) \(~\)

Statistics

\(~\) \(~\)

Reccomendation

base_recco = filter(base, id %notin% c("13594")) #remove huge outliers, see appendix

final_recco = lm(Reccomend ~Priming*Product + Behav_enviro + Product:Behav_enviro,  data = base_recco)

apa_lm <- papaja::apa_print(anova(final_recco))
papaja::apa_table(apa_lm$table,  caption = "Anova table for Reccomendation.", label =NULL)
(#tab:Report_Regression)
Anova table for Reccomendation.
Effect \(F\) \(\mathit{df}_1\) \(\mathit{df}_2\) \(\mathit{MSE}\) \(p\) \(\hat{\eta}^2_G\)
Priming 0.76 1 289 2.44 .383 .003
Product 32.23 1 289 2.44 < .001 .100
Behav enviro 33.11 1 289 2.44 < .001 .103
Priming \(\times\) Product 0.06 1 289 2.44 .808 .000
Product \(\times\) Behav enviro 5.30 1 289 2.44 .022 .018
sjPlot::plot_model(final_recco)

\(~\) \(~\)

interactions::interact_plot(final_recco, pred = Behav_enviro, modx = Product, interval = TRUE)


\(~\) \(~\)

Conclusions

\(~\) \(~\)

Example for reporting :

Product (\(F(1, 289) = 32.23\), \(\mathit{MSE} = 2.44\), \(p < .001\), \(\hat{\eta}^2_G = .100\)) and Behav_enviro (\(F(1, 289) = 33.11\), \(\mathit{MSE} = 2.44\), \(p < .001\), \(\hat{\eta}^2_G = .103\)) affected reccomendation. However, the effect of Behav_enviro differed by Product, \(F(1, 289) = 5.30\), \(\mathit{MSE} = 2.44\), \(p = .022\), \(\hat{\eta}^2_G = .018\).

\(~\) \(~\)

Appendix

\(~\) \(~\)

Visual check normality

plotNormalHistogram(base$Reccomend, main = "Reccomendation", sub = paste("skewness =", round(skewness(base$Reccomend, na.rm = TRUE),2)))

\(~\) \(~\)

Diagnostics Plots for GLM Reccomendation with outliers

\(~\) \(~\)

Diagnostics Plots for GLM Reccomendation with outliers

\(~\) \(~\)

Model selection for Reccomendation

Stepwise Model Path Analysis of Deviance Table
Initial Model:
Reccomend ~ Priming * Product * Decision_mode + Age + Priming *
Product * Behav_enviro
Final Model:
Reccomend ~ Priming + Product + Behav_enviro + Product:Behav_enviro
Step Df Deviance Resid. Df Resid. Dev AIC
282 698.9267 280.4583
  • Priming:Product:Behav_enviro
1 0.1006993 283 699.0274 278.5008
  • Priming:Behav_enviro
1 0.4823183 284 699.5097 276.7043
  • Age
1 0.8370115 285 700.3467 275.0570
  • Priming:Product:Decision_mode
1 4.7384372 286 705.0851 275.0462
  • Priming:Decision_mode
1 0.0761253 287 705.1613 273.0781
  • Priming:Product
1 0.1041078 288 705.2654 271.1216
  • Product:Decision_mode
1 0.8932071 289 706.1586 269.4950
  • Decision_mode
1 0.2413509 290 706.3999 267.5958
\(~\) \(~\)

Packages

\(~\) \(~\)

report::report_packages()
  - papaja (version 0.1.0.9997; Aust et al., 2020)
  - GGally (version 2.1.1; Barret Schloerke et al., 2021)
  - tinylabels (version 0.2.1; Barth, 2021)
  - apaTables (version 2.0.8; David Stanley, 2021)
  - ggplot2 (version 3.3.3; Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.)
  - stringr (version 1.4.0; Hadley Wickham, 2019)
  - forcats (version 0.5.1; Hadley Wickham, 2021)
  - tidyr (version 1.1.3; Hadley Wickham, 2021)
  - readr (version 1.4.0; Hadley Wickham and Jim Hester, 2020)
  - dplyr (version 1.0.6; Hadley Wickham et al., 2021)
  - kableExtra (version 1.3.4; Hao Zhu, 2021)
  - car (version 3.0.10; John Fox and Sanford Weisberg, 2019)
  - carData (version 3.0.4; John Fox, Sanford Weisberg and Brad Price, 2020)
  - here (version 1.0.1; Kirill Müller, 2020)
  - tibble (version 3.1.2; Kirill Müller and Hadley Wickham, 2021)
  - purrr (version 0.3.4; Lionel Henry and Hadley Wickham, 2020)
  - interactions (version 1.1.3; Long JA, 2019)
  - sjPlot (version 2.8.8; Lüdecke D, 2021)
  - moments (version 0.14; Lukasz Komsta and Frederick Novomestky, 2015)
  - report (version 0.3.5; Makowski et al., 2020)
  - R (version 4.0.1; R Core Team, 2020)
  - pacman (version 0.5.1; Rinker et al., 2017)
  - rcompanion (version 2.4.1; Salvatore Mangiafico, 2021)
  - gtsummary (version 1.5.0; Sjoberg DD, Whiting K, Curry M, Lavery JA, Larmarange Reproducible summary tables with the gtsummary package. The R Journal 2021;13:570–80. https://doi.org/10.32614/RJ-2021-053.)
  - MASS (version 7.3.51.6; Venables et al., 2002)
  - tidyverse (version 1.3.1; Wickham et al., 2019)
  - bookdown (version 0.22; Yihui Xie, 2021)

\(~\) \(~\)

References

\(~\) \(~\)

\(~\) \(~\)

James, William. 1890. “The Perception of Reality.” Principles of Psychology 2: 283–324.