mediation_analysis
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
mediation_analysis [2024/10/30 11:55] – [Mediation Analysis] hkimscil | mediation_analysis [2024/11/03 22:37] (current) – [What about this output] hkimscil | ||
---|---|---|---|
Line 414: | Line 414: | ||
</ | </ | ||
- | 위에서 a, b는 [[:beta coefficients]]라고 가정하고, | + | 위에서 a, b는 [[: |
* a는 (2) attitudes의 measurement 한 unit이 증가할 때 intention이 2 증가한다는 것을 의미합니다. | * a는 (2) attitudes의 measurement 한 unit이 증가할 때 intention이 2 증가한다는 것을 의미합니다. | ||
* b는 (1.5)는 attitudes의 점수가 하나 증가할 때 마다 behavior가 2*1.5 증가함을 (3) 의미합니다. 즉, attitudes가 한 단위 증가할 때마다 beahvior는 3 증가합니다. 독립변인 attitudes의 intention을 매개로 한 영향력을 말할 때 이 3을 사용합니다. 따라서 ab (mediation effects) = a * b 로 생각할 수 있습니다. | * b는 (1.5)는 attitudes의 점수가 하나 증가할 때 마다 behavior가 2*1.5 증가함을 (3) 의미합니다. 즉, attitudes가 한 단위 증가할 때마다 beahvior는 3 증가합니다. 독립변인 attitudes의 intention을 매개로 한 영향력을 말할 때 이 3을 사용합니다. 따라서 ab (mediation effects) = a * b 로 생각할 수 있습니다. | ||
Line 626: | Line 626: | ||
ab <- summary(lm.ba.02)$r.square | ab <- summary(lm.ba.02)$r.square | ||
bc <- summary(lm.ba.05)$r.square | bc <- summary(lm.ba.05)$r.square | ||
+ | abc | ||
+ | ab | ||
+ | bc | ||
abbc <- ab + bc | abbc <- ab + bc | ||
- | a <- abc - bc | + | abbc |
+ | # b는 아래처럼 구할 수도 있고 | ||
b <- abbc - abc | b <- abbc - abc | ||
+ | b | ||
+ | # 위에서 구한 summary(lm.ba.021)$r.squared 값이기도 하다 | ||
+ | summary(lm.ba.021)$r.squared | ||
+ | # a 또한 마찬가지 | ||
+ | a <- abc - bc | ||
+ | a | ||
+ | # 혹은 | ||
+ | summary(lm.ba.022)$r.squared | ||
+ | |||
+ | # 아래 c 도 마찬가지이다 | ||
c <- abc - ab | c <- abc - ab | ||
+ | c | ||
+ | summary(lm.temp)$r.squared | ||
</ | </ | ||
< | < | ||
Line 635: | Line 651: | ||
> ab <- summary(lm.ba.02)$r.square | > ab <- summary(lm.ba.02)$r.square | ||
> bc <- summary(lm.ba.05)$r.square | > bc <- summary(lm.ba.05)$r.square | ||
+ | > abc | ||
+ | [1] 0.1989125 | ||
+ | > ab | ||
+ | [1] 0.1982297 | ||
+ | > bc | ||
+ | [1] 0.06197255 | ||
> abbc <- ab + bc | > abbc <- ab + bc | ||
- | > a <- abc - bc | + | > abbc |
+ | [1] 0.2602023 | ||
+ | > # b는 아래처럼 구할 수도 있고 | ||
> b <- abbc - abc | > b <- abbc - abc | ||
- | > c <- abc - ab | ||
- | > | ||
- | > a | ||
- | [1] 0.1369399 | ||
> b | > b | ||
[1] 0.0612898 | [1] 0.0612898 | ||
+ | > # 위에서 구한 summary(lm.ba.021)$r.squared 값이기도 하다 | ||
+ | > summary(lm.ba.021)$r.squared | ||
+ | [1] 0.06197255 | ||
+ | > # a 또한 마찬가지 | ||
+ | > a <- abc - bc | ||
+ | > a | ||
+ | [1] 0.1369399 | ||
+ | > # 혹은 | ||
+ | > summary(lm.ba.022)$r.squared | ||
+ | [1] 0.1369399 | ||
+ | > | ||
+ | > # 아래 c 도 마찬가지이다 | ||
+ | > c <- abc - ab | ||
> c | > c | ||
[1] 0.0006827583 | [1] 0.0006827583 | ||
- | > abc | + | > summary(lm.temp)$r.squared |
- | [1] 0.1989125 | + | [1] 0.0006827583 |
> | > | ||
</ | </ | ||
+ | {{: | ||
===== Another modeling ===== | ===== Another modeling ===== | ||
성재학생이 다른 아이디어를 가지고 있다. 이를 분석에서 구현보고자 한다. | 성재학생이 다른 아이디어를 가지고 있다. 이를 분석에서 구현보고자 한다. | ||
Line 828: | Line 861: | ||
그 외의 지수는? | 그 외의 지수는? | ||
어떤 모델이 지금의 현상을 가장 잘 설명하는다고 판단하는가? | 어떤 모델이 지금의 현상을 가장 잘 설명하는다고 판단하는가? | ||
+ | |||
+ | * Model fit | ||
+ | * Chi-square Test: p-value less than p-critical value (.05 for example) indicates that model does not fit well enough. p-value more than critical value means the model fits the data relatively well. The test is sensitive to the sample size and normality of the data. | ||
+ | * CFI (Comparative Fit Index): greater than .90 indicates good fit to the data. It is less sensitive to the sample size and normality of the data than chi-square test. | ||
+ | * TLI (Tucker-Lewis Index): greater than .95 (sometimes .90) indicates good fit. It is less sensitive to the sample size. | ||
+ | * RMSEA (Root Mean Square Error of Approximation): | ||
+ | * SRMR (Standard Root Mean square Residual): less than or equal to .08 indicates good fit to the data. | ||
+ | |||
+ | | $\chi^2$ | ||
+ | | $p \ge .05$ | $p \ge .90$ | $p \ge .95$ | $p \le .08$ | $p \le .08$ | | ||
+ | |||
+ | Then what is SEM (Structural Equation Modeling) | ||
+ | * Relationships within and among variables and constructs | ||
+ | |||
Line 940: | Line 987: | ||
</ | </ | ||
+ | ====== e.g. with a categorical variable ====== | ||
+ | < | ||
+ | # regression with job placement data | ||
+ | |||
+ | df <- read.csv(" | ||
+ | head(df) | ||
+ | |||
+ | df<- within(df, { | ||
+ | norms.cat <- NA # need to initialize variable | ||
+ | norms.cat[norms < tmp[2]] <- " | ||
+ | norms.cat[norms >= tmp[2] & norms < tmp[3]] <- " | ||
+ | norms.cat[norms >= tmp[3]] <- " | ||
+ | } ) | ||
+ | head(df) | ||
+ | |||
+ | med.m.01 <- ' | ||
+ | # mediator | ||
+ | intention ~ a*attitude | ||
+ | behavior ~ b*intention | ||
+ | | ||
+ | # direct effect c | ||
+ | behavior ~ c*attitude | ||
+ | | ||
+ | # indirect effect | ||
+ | ab := a*b | ||
+ | | ||
+ | # total effect | ||
+ | tot := c + ab | ||
+ | ' | ||
+ | fit <- sem(med.m.01, | ||
+ | | ||
+ | se = " | ||
+ | summary(fit, | ||
+ | standardized = T, | ||
+ | ci = T) | ||
+ | |||
+ | ### | ||
+ | mod.m.02 <- ' | ||
+ | # mediator | ||
+ | intention ~ c(ag1, | ||
+ | behavior ~ c(bg1, | ||
+ | | ||
+ | # direct effect | ||
+ | behavior ~ c(cg1, | ||
+ | | ||
+ | # indirect effect | ||
+ | abg1 := ag1*bg1 # for group 1 | ||
+ | abg2 := ag2*bg2 | ||
+ | abg3 := ag3*bg3 | ||
+ | |||
+ | # tot effect | ||
+ | totalg1 := cg1 + (ag1*bg1) | ||
+ | totalg2 := cg2 + (ag2*bg2) | ||
+ | totalg3 := cg3 + (ag3*bg3) | ||
+ | ' | ||
+ | |||
+ | fit.by.norms.cat <- sem(mod.m.02, | ||
+ | group = " | ||
+ | se = " | ||
+ | meanstructure = T) | ||
+ | summary(fit.by.norms.cat, | ||
+ | fit.measures = T, | ||
+ | standardized = T, | ||
+ | ci = T) | ||
+ | |||
+ | all.constraints <- ' | ||
+ | ag1 == ag2 == ag3 | ||
+ | bg1 == bg2 == bg3 | ||
+ | cg1 == cg2 == cg3 | ||
+ | ' | ||
+ | |||
+ | lavTestWald(fit.by.norms.cat, | ||
+ | constraints = all.constraints) | ||
+ | |||
+ | lavTestWald(fit.by.norms.cat, | ||
+ | constraints = " | ||
+ | lavTestWald(fit.by.norms.cat, | ||
+ | constraints = " | ||
+ | lavTestWald(fit.by.norms.cat, | ||
+ | constraints = " | ||
+ | |||
+ | # or | ||
+ | full.mod.mediation <- ' | ||
+ | # mediator | ||
+ | intention ~ a*attitude | ||
+ | behavior ~ b*intention + w*norms.cat | ||
+ | | ||
+ | # define moderator | ||
+ | Z := w*b | ||
+ | | ||
+ | # direct effect | ||
+ | behavior ~ c*attitude | ||
+ | | ||
+ | # indirect effect | ||
+ | ab := a*b | ||
+ | |||
+ | # tot effect | ||
+ | total := c + (a*b) | ||
+ | ' | ||
+ | |||
+ | full.mod <- sem (full.mod.mediation, | ||
+ | se = " | ||
+ | | ||
+ | summary(full.mod, | ||
+ | stand = T, ci = T) | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
====== e.gs ====== | ====== e.gs ====== | ||
< | < |
mediation_analysis.1730256943.txt.gz · Last modified: 2024/10/30 11:55 by hkimscil