Essa é uma simulação de uma base de dados onde 2 x 2 condições entre participantes são simuladas como variáveis independentes e uma variável dependente é simulada.
As condições idenpendentes são busy (busy baixo = -1 e busy alto = +1) e lazer (lazer baixo = -1 e lazer alto = +1) e a variável dependentes é felicidade, em uma escala de 1 - 7.
Usarei uma codificação padrão para um design experimental 2 x 2 entre participantes. Funciona com códigos 0 e 1 também.
busy <- c(rep(-1,100),rep(1,100))
lazer <- c(rep(-1,50),rep(1,50),rep(-1,50),rep(1,50))
felicidade <- sample(1:7, 200, replace=TRUE)
Nota-se que existem 50 pessoas em cada célula, numa alocação perfeita.
table(busy,lazer)
## lazer
## busy -1 1
## -1 50 50
## 1 50 50
A correlação entre busy e lazer é perfeitamente nula.
cor.test(lazer, busy, method="pearson")
##
## Pearson's product-moment correlation
##
## data: lazer and busy
## t = 0, df = 198, p-value = 1
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.138741 0.138741
## sample estimates:
## cor
## 0
Consequentemente, a regressão também é nula.
summary(lm(lazer~busy))
##
## Call:
## lm(formula = lazer ~ busy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1 -1 0 1 1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.570e-17 7.107e-02 0 1
## busy -3.140e-17 7.107e-02 0 1
##
## Residual standard error: 1.005 on 198 degrees of freedom
## Multiple R-squared: 9.49e-32, Adjusted R-squared: -0.005051
## F-statistic: 1.879e-29 on 1 and 198 DF, p-value: 1
require(mediation)
esta <- lm(lazer~busy)
estc_b <- lm(felicidade~busy + lazer)
mediacao<-mediate(esta, estc_b, treat = "busy", mediator = "lazer",
boot = TRUE, sims = 5000)
summary(mediacao)
##
## Causal Mediation Analysis
##
## Nonparametric Bootstrap Confidence Intervals with the Percentile Method
##
## Estimate 95% CI Lower 95% CI Upper p-value
## ACME 0.0000 -0.0209 0.02 1.00
## ADE 0.1000 -0.1809 0.38 0.47
## Total Effect 0.1000 -0.1800 0.38 0.46
## Prop. Mediated 0.0000 -0.5297 0.68 1.00
##
## Sample Size Used: 200
##
##
## Simulations: 5000