Mediation: Causal Mediation Analysis

Description Usage Arguments Details Value Examples

View source: R/regression-mediation.R

Description

Einfache Mediation und Moderationsanalyse mit Sobel-Test Mediation ist gegeben wenn alle Modelle signifikant (1) und (4)

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Mediation(
  y_x,
  y_xm,
  m_x,
  y_inter_xm = NULL,
  data = NULL,
  caption = "",
  note = "",
  output = which_output(),
  include.parameter = TRUE,
  include.p = TRUE,
  include.sobl = TRUE,
  z.transform = TRUE,
  treat = model_info(m_x)$x[1],
  mediator = model_info(m_x)$y,
  type = "long2",
  ...
)

Sobel_Test(y_x, y_xm, m_x, treat, mediator, digits = 2)

Arguments

y_x

y~x formula oder lm-Objekt

y_xm

y~x+m formula oder lm-Objekt

m_x

m~x formula oder lm-Objekt

y_inter_xm

m~x*m formula oder lm-Objekt

data

Daten bei der Verwendendung von Formeln

caption, note, output

an Output

include.parameter, include.sobl

was soll Ausgegeben werden

z.transform

Transformation bei der Verwendendung von Formeln

treat, mediator

Einfluss und Mediatorals string

type, include.p, ...

fuer Regression APA_Tabelle()

digits

Nachkommastellen

y_x, y_xm, m_x

in Sobel-Test lm-Objekte

Details

(1) Y~X (2) Y~X+M (wenn hier M signifikant ist => partielle Mediation) (4) M~X

Moderation ist gegeben wenn die Interaktion (X:M) signifikant ist

(3) Y~ X + M + X:M

Ein Beispiel mit Laavan findet sich unter https://paolotoffanin.wordpress.com/2017/05/06/multiple-mediator-analysis-with-lavaan/

Value

list(param, sobel, methode)

data.frame

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#' 
## https://paolotoffanin.wordpress.com/2017/05/06/multiple-mediator-analysis-with-lavaan/
## simpleMediation
#Projekt("html", "Test")
set.seed(1234)
Motivation <- rnorm(100)
Lerndauer <- 0.5 * Motivation + rnorm(100)
Note <- 0.7 * Lerndauer + rnorm(100)
dat <- data.frame(Note = Note,
                  Lerndauer = Lerndauer,
                  Motivation = Motivation)

dat <- stp25aggregate::Label(dat,
                             Note = "Note (Ziel-Variable)" ,
                             Lerndauer = "Lerndauer (Mediator)",
                             Motivation = "Motivation (Einfluss-Variable)")
Tabelle2(dat, Note, Lerndauer, Motivation)
Mediation(
  Note ~ Motivation,
  Note ~ Motivation + Lerndauer,
  Lerndauer ~ Motivation,
  Note ~ Motivation * Lerndauer,
  dat,
  digits = 2,
  caption = "Einfache Mediation und Moderationsanalyse mit Sobel-Test"
)

model <- ' # direct effect
Note ~ c*Motivation
# mediator
Lerndauer ~ a*Motivation
Note ~ b*Lerndauer
# indirect effect (a*b)
indir := a*b
# total effect
total := c + (a*b)
'

#xyplot(Note ~ value |
#         variable,
#       melt2(dat, Motivation, Lerndauer, by =  ~ Note))


fit <-  lavaan::sem(model, data = dat)
APA2(fit)
#End()
#' 

# Daten -------------------------------------------------------------------


set.seed(1234)
n <- 2 * 10

Motivation <- rnorm(n)
Lerndauer <- 0.5 * Motivation + rnorm(n)
Note <- 0.7 * Lerndauer + rnorm(n)

t0 <- data.frame(
  id = 1:n,
  sex = gl(2, n / 2, labels = c("m", "f")),
  time = 0,
  Note = Note,
  Lerndauer = Lerndauer,
  Motivation = Motivation
)

t1 <- rnorm(n, 0.1, 0.1)
t1 <- data.frame(
  id = 1:n,
  sex = gl(2, n / 2, labels = c("m", "f")),
  time = 1,
  Note = Note * .1 + t1,
  Lerndauer = Lerndauer * .1 + t1,
  Motivation = Motivation * .1 + t1
)

t2 <- rnorm(n, 0.2, 0.5)
t2 <- data.frame(
  id = 1:n,
  sex = gl(2, n / 2, labels = c("m", "f")),
  time = 2,
  Note = Note * .15 + t2  ,
  Lerndauer = Lerndauer * .15 + t2,
  Motivation = Motivation * .15 + t2
)
dat <- rbind(t0, t1, t2)





#model1 <- lm(Note ~ Motivation +time, dat)
#model2 <- lm(Note ~ Motivation + Lerndauer+time, dat)
#model3 <- lm(Lerndauer ~ Motivation+time, dat)


model1 <- lmerTest::lmer(Note ~ Motivation +time+ (1 | id), dat)
model2 <- lmerTest::lmer(Note ~ Motivation + Lerndauer +time+ (1 | id), dat)
model3 <- lmerTest::lmer(Lerndauer ~ Motivation +time+ (1 | id), dat)


Sobel_Test(model1, model2, model3,
           treat="Motivation",
           mediator="Lerndauer" )

stp4/stp25stat documentation built on Sept. 17, 2021, 2:03 p.m.