|||
library(tidyverse)
library(agricolae)
library(semPlot)
library(lavaanPlot)
data(haynes)
X <- haynes %>% dplyr::select(FL, MI, ME)
Y <- haynes$WI
# correlation analysis ---------------------------------------
corr.x <- correlation(X, X)
corr.y <- correlation(Y, X)
# Path Analysis -----------------------------------------------
result <- path.analysis(corr.x$correlation, corr.y$correlation)
## Direct effect path coefficients
DEffect <- diag(result$Coeff)
## Indirect effect path coefficients
diag(result$Coeff) <- 0
IEffect <- rowSums(result$Coeff)
# print results of path analysis -----------------------------------------------
result1 <- result$Coeff %>% as.data.frame %>%
mutate(
'总间接作用' = IEffect,
'直接作用' = DEffect,
'总作用' = corr.y$correlation %>% as.numeric()
)
rownames(result1) <- DEffect %>% names
cat("\n\nDirect and indirect effect:\n========================\n" )
print(result1)
sprintf("\nResidual Effect^2 = %2.3f\n========================\n",
result$Residual) %>% cat
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-23 05:34
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社