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 13:01] – 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 110: | Line 111: | ||
</ | </ | ||
+ | ---- | ||
+ | < | ||
+ | # my own | ||
+ | # pbt model | ||
+ | specmod5 <- ' | ||
+ | # Directional relations (path) | ||
+ | intention ~ a*attitude + b*norms + c*control | ||
+ | behavior ~ d*intention | ||
+ | # Covariances | ||
+ | attitude ~~ norms + control | ||
+ | norms ~~ control | ||
+ | ad := a*d | ||
+ | bd := b*d | ||
+ | cd := c*d | ||
+ | ' | ||
+ | fitmod5 <- sem(specmod5, | ||
+ | summary(fitmod5, | ||
+ | </ | ||
====== Output ====== | ====== Output ====== | ||
< | < | ||
Line 439: | Line 458: | ||
</ | </ | ||
+ | ===== specmod5 ===== | ||
+ | < | ||
+ | > specmod5 <- " | ||
+ | + # Directional relations (path) | ||
+ | + | ||
+ | + | ||
+ | + # Covariances | ||
+ | + | ||
+ | + norms ~~ control | ||
+ | + " | ||
+ | > fitmod5 <- sem(specmod5, | ||
+ | > summary(fitmod5, | ||
+ | lavaan 0.6-12 ended normally after 18 iterations | ||
+ | Estimator | ||
+ | Optimization method | ||
+ | Number of model parameters | ||
+ | |||
+ | Number of observations | ||
+ | |||
+ | Model Test User Model: | ||
+ | | ||
+ | Test statistic | ||
+ | Degrees of freedom | ||
+ | P-value (Chi-square) | ||
+ | |||
+ | Model Test Baseline Model: | ||
+ | |||
+ | Test statistic | ||
+ | Degrees of freedom | ||
+ | P-value | ||
+ | |||
+ | User Model versus Baseline Model: | ||
+ | |||
+ | Comparative Fit Index (CFI) 1.000 | ||
+ | Tucker-Lewis Index (TLI) 1.006 | ||
+ | |||
+ | Loglikelihood and Information Criteria: | ||
+ | |||
+ | Loglikelihood user model (H0) -1258.396 | ||
+ | Loglikelihood unrestricted model (H1) -1257.506 | ||
+ | | ||
+ | Akaike (AIC) 2542.792 | ||
+ | Bayesian (BIC) 2585.605 | ||
+ | Sample-size adjusted Bayesian (BIC) | ||
+ | |||
+ | Root Mean Square Error of Approximation: | ||
+ | |||
+ | RMSEA 0.000 | ||
+ | 90 Percent confidence interval - lower 0.000 | ||
+ | 90 Percent confidence interval - upper 0.136 | ||
+ | P-value RMSEA <= 0.05 0.569 | ||
+ | |||
+ | Standardized Root Mean Square Residual: | ||
+ | |||
+ | SRMR 0.018 | ||
+ | |||
+ | Parameter Estimates: | ||
+ | |||
+ | Standard errors | ||
+ | Information | ||
+ | Information saturated (h1) model Structured | ||
+ | |||
+ | Regressions: | ||
+ | | ||
+ | intention ~ | ||
+ | attitude | ||
+ | norms | ||
+ | control | ||
+ | behavior ~ | ||
+ | intention | ||
+ | norms | ||
+ | |||
+ | Covariances: | ||
+ | | ||
+ | attitude ~~ | ||
+ | norms | ||
+ | control | ||
+ | norms ~~ | ||
+ | control | ||
+ | |||
+ | Variances: | ||
+ | | ||
+ | | ||
+ | | ||
+ | attitude | ||
+ | norms | ||
+ | control | ||
+ | |||
+ | R-Square: | ||
+ | | ||
+ | intention | ||
+ | behavior | ||
+ | |||
+ | </ | ||
===== Lavaan in R: explanation ===== | ===== Lavaan in R: explanation ===== | ||
Line 460: | Line 573: | ||
< | < | ||
- | processdata< | + | # processdata< |
+ | processdata< | ||
+ | | ||
</ | </ | ||
Line 518: | 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 576: | Line 691: | ||
interest~~anxiety' | interest~~anxiety' | ||
- | fit< | + | fit< |
- | summary(fit, | + | summary(fit, |
</ | </ | ||
Line 636: | Line 751: | ||
CODING | CODING | ||
< | < | ||
- | processdata <- read.csv(" | + | processdata< |
+ | | ||
str(processdata) | str(processdata) | ||
library(lavaan) | library(lavaan) | ||
Line 656: | 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 799: | 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.1668484916.txt.gz · Last modified: 2022/11/15 13:01 by hkimscil