User Tools

Site Tools


r:path_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
Next revisionBoth sides next revision
r:path_analysis [2022/11/15 22:17] – [Lavaan in R: explanation] hkimscilr:path_analysis [2023/05/29 23:45] hkimscil
Line 1: Line 1:
 ====== Path Analysis ====== ====== Path Analysis ======
 +{{:r:pasted:20230529-234519.png}}
 ====== Introduction ====== ====== Introduction ======
 {{youtube>UGIVPtFKwc0}} {{youtube>UGIVPtFKwc0}}
Line 114: Line 115:
 # my own  # my own 
 # pbt model  # pbt model 
-specmod5 <- "+specmod5 <- '
     # Directional relations (path)     # Directional relations (path)
-    intention ~ attitude + norms + control +    intention ~ a*attitude + b*norms + c*control 
-    behavior ~ intention + norms+    behavior ~ d*intention 
     # Covariances      # Covariances 
     attitude ~~ norms + control     attitude ~~ norms + control
     norms ~~ control         norms ~~ control    
-"+    ad := a*d 
 +    bd := b*d 
 +    cd := c*d 
 +'
 fitmod5 <- sem(specmod5, data=df) fitmod5 <- sem(specmod5, data=df)
 summary(fitmod5, fit.measures=TRUE, rsquare=TRUE) summary(fitmod5, fit.measures=TRUE, rsquare=TRUE)
Line 747: Line 751:
 CODING  CODING 
 <code> <code>
-processdata <- read.csv("http://commres.net/wiki/_media/r/path_analysis_datan_binw.csv")+processdata<-read.csv("http://commres.net/wiki/_media/r/path_analysis_datan_binw.csv",  
 +                       header=TRUE, sep=",", fileEncoding="UTF-8-BOM")
 str(processdata) str(processdata)
 library(lavaan) library(lavaan)
Line 910: Line 915:
 see [[https://www.rensvandeschoot.com/tutorials/lme4/|lme4 tutorial]] see [[https://www.rensvandeschoot.com/tutorials/lme4/|lme4 tutorial]]
  
 +===== Exercise =====
 +Using mtcars in R
 +<code>
 +?mtcars
 +mtcars
 +str(mtcars)
 +df <- mtcars
 +</code>
 +
 +<code>
 +# model specfication
 +model <-'
 +  mpg ~ hp + gear + cyl + disp + carb + am + wt
 +  hp ~ cyl + disp + carb
 +'
 +# model fit
 +fit <- cfa(model, data = mtcars)
 +summary(fit, fit.measures = TRUE, standardized=T, rsquare=T)
 +semPaths(fit, 'std', layout = 'circle')
 +</code>
  
r/path_analysis.txt · Last modified: 2023/11/27 16:57 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki