User Tools

Site Tools


mediation_analysis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
mediation_analysis [2024/10/31 08:47] – [Poking the above] hkimscilmediation_analysis [2024/11/03 22:37] (current) – [What about this output] hkimscil
Line 684: Line 684:
 </code> </code>
  
-{{:pasted:20241031-084730.png}}+{{:pasted:20241031-085240.png}}
 ===== Another modeling ===== ===== Another modeling =====
 성재학생이 다른 아이디어를 가지고 있다. 이를 분석에서 구현보고자 한다.  성재학생이 다른 아이디어를 가지고 있다. 이를 분석에서 구현보고자 한다. 
Line 861: 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): equal to or less than .08 (sometimes .10 is used) indicates good fit to the data. 
 +    * SRMR (Standard Root Mean square Residual): less than or equal to .08 indicates good fit to the data.
 +
 +| $\chi^2$  | $\text{CFI}$  | $\text{TLI}$  | $\text{RMSEA}$  | $\text{SRMR}$   |
 +| $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 973: Line 987:
  
 </code> </code>
 +====== e.g. with a categorical variable ======
 +<code>
 +# regression with job placement data 
 +
 +df <- read.csv("http://commres.net/wiki/_media/r/plannedbehavior.csv")
 +head(df)
 +
 +df<- within(df, {   
 +  norms.cat <- NA # need to initialize variable
 +  norms.cat[norms < tmp[2]] <- "Low"
 +  norms.cat[norms >= tmp[2] & norms < tmp[3]] <- "Middle"
 +  norms.cat[norms >= tmp[3]] <- "High"
 +} )
 +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, data = df,
 +           meanstructure = T, 
 +           se = "boot", bootstrap = 500)
 +summary(fit, fit.measures = T,
 +        standardized = T, 
 +        ci = T)
 +
 +###
 +mod.m.02 <- '
 +    # mediator
 +    intention ~ c(ag1,ag2,ag3)*attitude
 +    behavior ~ c(bg1,bg2,bg3)*intention
 +    
 +    # direct effect
 +    behavior ~ c(cg1,cg2,cg3)*attitude
 +    
 +    # 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, data = df,
 +                        group = "norms.cat",
 +                        se = "boot", bootstrap = 500,
 +                        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 = "ag1==ag2==ag3")
 +lavTestWald(fit.by.norms.cat, 
 +            constraints = "bg1==bg2==bg3")
 +lavTestWald(fit.by.norms.cat, 
 +            constraints = "cg1==cg2==cg3")
 +
 +# 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, data = df,
 +                 se = "boot", bootstrap = 500, 
 +                 meanstructure = T)
 +summary(full.mod, fit.measures = T,
 +        stand = T, ci = T)
 +
 +</code>
 +
 +
 ====== e.gs ====== ====== e.gs ======
 <code> <code>
mediation_analysis.1730332051.txt.gz · Last modified: 2024/10/31 08:47 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki