#### installer les packages ####
install.packages(c("lavaan","lme4","remotes",
"tidyverse","haven","lmerTest"))
remotes::install_github("patc3/gentleman")
#### charger les packages ####
library(tidyverse)
library(gentleman)
library(lavaan)
library(lme4)
library(lmerTest)
#### charger les données ####
df <- haven::read_spss("simulated_employee_data.sav")
df <- as.data.frame(df)
#### calculer des moyennes et alpha de Cronbach ####
COMPOSITES<-list(
HRP=c("PRH1","PRH2","PRH3","PRH4","PRH5",
"PRH6","PRH7","PRH8","PRH9","PRH10",
"PRH11","PRH12","PRH13","PRH14"),
commit=c("Commit1","Commit2","Commit3R"),
fair=c("fair1","fair2R","fair3","fair4","fair5","fair6R"),
diffHR=c("ideal1","ideal2","ideal3"),
attrib=c("attrineed1","attrineed2","attrineed3",
"attrirew1","attrirew2","attrirew3",
"attripriv1","attripriv2","attripriv3"),
ITL=c("TOI1","TOI2","TOI3","TOI4")
)
df <- add_composites(df, map=COMPOSITES)
#### préparation des données ####
df$CoNu <- as.factor(df$CoNu)
df$secteur <- as.factor(df$secteur)
dfz <- standardize(df)
#### analyses factorielles confirmatoires ####
cfa<-list()
##### HRP ####
cfa_HRP<-"
fHRP =~ PRH1 + PRH2 + PRH3 + PRH4 + PRH5 + PRH6 + PRH7 + PRH8 + PRH9 + PRH10 + PRH11 + PRH12 + PRH13 + PRH14
"
cfa$HRP<-cfa(model=cfa_HRP,data=df)
summary(cfa$HRP, fit=TRUE, stand=TRUE, rsqu=TRUE)
##### engagement organisationnel ####
cfa_commit<-"
fcommit =~ Commit1 + Commit2 + Commit3R
"
cfa$commit<-cfa(model=cfa_commit,data=df)
summary(cfa$commit, fit=TRUE, stand=TRUE, rsqu=TRUE)
##### perception de justice ####
cfa_fair<-"
ffair =~ fair1 + fair2R + fair3 + fair4 + fair5 + fair6R
"
cfa$fair<-cfa(model=cfa_fair,data=df)
summary(cfa$fair, fit=TRUE, stand=TRUE, rsqu=TRUE)
##### différenciation RH ####
cfa_diffHR<-"
fdiffHR =~ ideal1 + ideal2 + ideal3
"
cfa$diffHR<-cfa(model=cfa_diffHR,data=df)
summary(cfa$diffHR, fit=TRUE, stand=TRUE, rsqu=TRUE)
##### attributions ####
cfa_attrib<-"
fattrib =~ attrineed1 + attrineed2 + attrineed3 + attrirew1 + attrirew2 + attrirew3 + attripriv1 + attripriv2 + attripriv3
"
cfa$attrib<-cfa(model=cfa_attrib,data=df)
summary(cfa$attrib, fit=TRUE, stand=TRUE, rsqu=TRUE)
##### ITL ####
cfa_ITL<-"
fITL =~ TOI1 + TOI2 + TOI3 + TOI4
"
cfa$ITL<-cfa(model=cfa_ITL,data=df)
summary(cfa$ITL, fit=TRUE, stand=TRUE, rsqu=TRUE)
#### modèles multiniveaux ####
mlm<-list()
##### modèle 1 ####
mlm$model1 <- lmer(fair ~ HRP + diffHR + HRP:diffHR + secteur + (1|CoNu),
data=dfz,
REML=TRUE)
summary(mlm$model1)
###### décomposer les interactions ####
decompose_interaction(
model=mlm$model1,
df=dfz,
x2="HRP",
x1="diffHR",
at_x1=c(-1,0,1),
at_x2=c(-1,0,1)
)
##### modèle 2 ####
###### justice ####
mlm$model2_justice <- lmer(fair ~ attrib + diffHR + attrib:diffHR + secteur + (1|CoNu),
data=dfz,
REML=TRUE)
summary(mlm$model2_justice)
decompose_interaction(
model=mlm$model2_justice,
df=dfz,
x1="attrib",
x2="diffHR",
at_x1=c(-1,0,1),
at_x2=c(-1,0,1)
)
###### engagement ####
mlm$model2_commit <- lmer(commit ~ attrib + diffHR + attrib:diffHR + secteur + (1|CoNu),
data=dfz,
REML=TRUE)
summary(mlm$model2_commit)
decompose_interaction(
model=mlm$model2_commit,
df=dfz,
x1="attrib",
x2="diffHR",
at_x1=c(-1,0,1),
at_x2=c(-1,0,1)
)
###### intention de quitter ####
mlm$model2_ITL <- lmer(ITL ~ attrib + diffHR + attrib:diffHR + secteur + (1|CoNu),
data=dfz,
REML=TRUE)
summary(mlm$model2_ITL)
decompose_interaction(
model=mlm$model2_ITL,
df=dfz,
x1="attrib",
x2="diffHR",
at_x1=c(-1,0,1),
at_x2=c(-1,0,1)
)
PARTAGEZ VOS IMPRESSIONS & POSEZ VOS QUESTIONS ICI !