r:path_analysis
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
r:path_analysis [2022/11/15 22:12] – [Lavaan in R: explanation] hkimscil | r:path_analysis [2023/11/27 16:57] (current) – [Lavaan in R: explanation] hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Path Analysis ====== | ====== Path Analysis ====== | ||
+ | {{: | ||
====== Introduction ====== | ====== Introduction ====== | ||
{{youtube> | {{youtube> | ||
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 | + | 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, | fitmod5 <- sem(specmod5, | ||
summary(fitmod5, | summary(fitmod5, | ||
Line 570: | Line 574: | ||
< | < | ||
# processdata< | # processdata< | ||
- | processdata< | + | processdata< |
+ | header=TRUE, | ||
</ | </ | ||
Line 628: | Line 633: | ||
* Step 2: Use ' | * Step 2: Use ' | ||
< | < | ||
- | fit< | + | fit< |
</ | </ | ||
* The ' | * The ' | ||
< | < | ||
- | summary(fit, | + | summary(fit, |
</ | </ | ||
* To obtain standardized estimates, use the ' | * To obtain standardized estimates, use the ' | ||
< | < | ||
- | summary(fit, | + | summary(fit, |
</ | </ | ||
Line 686: | Line 691: | ||
interest~~anxiety' | interest~~anxiety' | ||
- | fit< | + | fit< |
- | summary(fit, | + | summary(fit, |
</ | </ | ||
Line 746: | Line 751: | ||
CODING | CODING | ||
< | < | ||
- | processdata <- read.csv(" | + | processdata< |
+ | | ||
str(processdata) | str(processdata) | ||
library(lavaan) | library(lavaan) | ||
Line 766: | Line 772: | ||
interest~~anxiety | interest~~anxiety | ||
' | ' | ||
- | fit <- lavaan(model. data=processdata) | + | fit <- lavaan(model, data=processdata) |
- | fit <- sem(model. data=processdata) | + | fit <- sem(model, data=processdata) |
summary(fit, | summary(fit, | ||
Line 909: | Line 915: | ||
see [[https:// | see [[https:// | ||
+ | ===== Exercise ===== | ||
+ | Using mtcars in R | ||
+ | < | ||
+ | ?mtcars | ||
+ | mtcars | ||
+ | str(mtcars) | ||
+ | df <- mtcars | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | # model specfication | ||
+ | model <-' | ||
+ | mpg ~ hp + gear + cyl + disp + carb + am + wt | ||
+ | hp ~ cyl + disp + carb | ||
+ | ' | ||
+ | # model fit | ||
+ | fit <- cfa(model, data = mtcars) | ||
+ | summary(fit, | ||
+ | semPaths(fit, | ||
+ | </ | ||
r/path_analysis.1668517922.txt.gz · Last modified: 2022/11/15 22:12 by hkimscil