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
r:path_analysis [2024/10/30 12:27] hkimscilr:path_analysis [2024/11/04 10:28] (current) – [Introduction] hkimscil
Line 16: Line 16:
     * The number of unique (non-redundent) source of information     * The number of unique (non-redundent) source of information
     * $p(p+1)/2$     * $p(p+1)/2$
-    * The number of parameters (paths) specified in model +  * The number of parameters (paths) specified in model 
-  * Just-identified (df = 0) +    * Just-identified (df = 0) 
-    * Model can be estimated, but cannot be assessed +      * Model can be estimated, but cannot be assessed 
-  * Over-identified (df > 0) +    * Over-identified (df > 0) 
-    * Model can be estimated and assessed +      * Model can be estimated and assessed 
-  * Under-identified (df < 0) +    * Under-identified (df < 0) 
-    * Model cannot be either estimated or assessed+      * Model cannot be either estimated or assessed
  
   * Exogenous and    * Exogenous and 
Line 555: Line 555:
  
 ===== Lavaan in R: explanation ===== ===== Lavaan in R: explanation =====
- 
 {{youtube>QP-v6RwsZjY?start=251}} {{youtube>QP-v6RwsZjY?start=251}}
 Path analysis in R with Lavaan (introduction) Path analysis in R with Lavaan (introduction)
Line 660: Line 659:
   * Note: Modification indices represent the expected decrease in model chi-square after freeing a given parameter (Schumacker & Lomax, 2004). The EPC is an estimate of the model parameter itself. A MI value of 3.84 or greater may be considered "significant" (at the .05) level. Warning: This is totally an empirically based approach to model specification. Consult your theory when using these!     * Note: Modification indices represent the expected decrease in model chi-square after freeing a given parameter (Schumacker & Lomax, 2004). The EPC is an estimate of the model parameter itself. A MI value of 3.84 or greater may be considered "significant" (at the .05) level. Warning: This is totally an empirically based approach to model specification. Consult your theory when using these!  
  
------------------------------ +output 
-  * Specification of model using auto.var argument... +
-<code> +
-# model specification +
- +
-model<-' +
-  # equation where interest is predicted by ses & mastery and  +
-  # performance goals +
-  interest ~ mastery + perfgoal + ses +
- +
-  # equation where achieve is predicted by interest and anxiety +
-  achieve~anxiety+interest+mastery +
- +
-  #equation where anxiety is predicted by mastery and performance goals +
-  anxiety~perfgoal+mastery +
- +
-  # estimtating the variances of the exogenous variables (ses, mastery,performance) +
-  mastery~~mastery +
-  perfgoal~~perfgoal +
-  ses~~ses +
- +
-  # estimtating the covariances of the exogenous variables (ses, mastery,performance) +
-  mastery~~perfgoal+ses +
-  perfgoal~~ses +
- +
-  # The auto.var argument when fitting the model can be used so that  +
-  # you do not have to directly request estimation of residual variances +
- +
-  # Estimating the covariance of residuals for interest and anxiety +
-  interest~~anxiety' +
- +
-  fit<-lavaan(model, data=processdata, auto.var=TRUE) +
-  summary(fit, fit.measures=TRUE, standardized=TRUE, rsquare=TRUE) +
-</code> +
  
 <code> <code>
-> ###################################################### +> # install.packages("lavaan")
-> ## data file: PlannedBehavior.csv +
-> ###################################################### +
-> ###################################################### +
-install.packages("readr"+
-‘C:/Users/Hyo/AppData/Local/R/win-library/4.3’의 위치에 패키지(들)을 설치합니다. +
-(왜냐하면 ‘lib’가 지정되지 않았기 때문입니다) +
-URL 'https://cran.rstudio.com/bin/windows/contrib/4.3/readr_2.1.5.zip'을 시도합니다 +
-Content type 'application/zip' length 1188732 bytes (1.1 MB) +
-downloaded 1.1 MB +
- +
-패키지 ‘readr’를 성공적으로 압축해제하였고 MD5 sums 이 확인되었습니다 +
- +
-다운로드된 바이너리 패키지들은 다음의 위치에 있습니다 +
- C:\Users\Hyo\AppData\Local\Temp\RtmpIBHzlS\downloaded_packages +
-> library(readr) +
-경고메시지(들):  +
-패키지 ‘readr’는 R 버전 4.3.3에서 작성되었습니다  +
-> df <- read.csv("http://commres.net/wiki/_media/r/plannedbehavior.csv"+
-> head(df) +
-  attitude norms control intention behavior +
-1     2.31  2.31    2.03      2.50     2.62 +
-2     4.66  4.01    3.63      3.99     3.64 +
-3     3.85  3.56    4.20      4.35     3.83 +
-4     4.24  2.25    2.84      1.51     2.25 +
-5     2.91  3.31    2.40      1.45     2.00 +
-6     2.99  2.51    2.95      2.59     2.20 +
-> str(df) +
-'data.frame': 199 obs. of  5 variables: +
- $ attitude : num  2.31 4.66 3.85 4.24 2.91 2.99 3.96 3.01 4.77 3.67 ... +
- $ norms    : num  2.31 4.01 3.56 2.25 3.31 2.51 4.65 2.98 3.09 3.63 ... +
- $ control  : num  2.03 3.63 4.2 2.84 2.4 2.95 3.77 1.9 3.83 5 ... +
- $ intention: num  2.5 3.99 4.35 1.51 1.45 2.59 4.08 2.58 4.87 3.09 ... +
- $ behavior : num  2.62 3.64 3.83 2.25 2 2.2 4.41 4.15 4.35 3.95 ... +
-> # specifying path analysis model  +
-> # by using lavann package +
-> install.packages("lavann"+
-‘C:/Users/Hyo/AppData/Local/R/win-library/4.3’의 위치에 패키지(들)을 설치합니다. +
-(왜냐하면 ‘lib’가 지정되지 않았기 때문입니다) +
-Warning in install.packages : +
-  package ‘lavann’ is not available for this version of R +
- +
-A version of this package for your version of R might be available elsewhere, +
-see the ideas at +
-https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages +
-> # specifying path analysis model  +
-> # by using lavann package +
-> # install.packages("lavann"+
-> library(lavaan+
-This is lavaan 0.6-16 +
-lavaan is FREE software! Please report any bugs. +
-> specmod <- " +
-+     # path c +
-+     # identifying path c (primeby putting c* +
-+     behavior ~ c*attitude +
-+  +
-+     # path a +
-+     intention ~ a*attitude +
-+  +
-+     # path b  +
-+     behavior ~ b*intention +
-+      +
-+     # indirect effect (a*b): Sobel test (Delta Method) +
-+     # 간접효과 a path x b path 를 구해서 얻음 +
-+     # sobel test 라 부름 +
-+     ab := a*b +
-+ " +
-> # Fit/estimate the model +
-> fitmod <- sem(specmod, data=df) +
-> # summarize the model +
-> summary(fitmod, fit.measures=TRUE, rsquare=T) +
-lavaan 0.6.16 ended normally after 1 iteration +
- +
-  Estimator                                         ML +
-  Optimization method                           NLMINB +
-  Number of model parameters                         5 +
- +
-  Number of observations                           199 +
- +
-Model Test User Model: +
-                                                       +
-  Test statistic                                 0.000 +
-  Degrees of freedom                                 0 +
- +
-Model Test Baseline Model: +
- +
-  Test statistic                               103.700 +
-  Degrees of freedom                                 3 +
-  P-value                                        0.000 +
- +
-User Model versus Baseline Model: +
- +
-  Comparative Fit Index (CFI)                    1.000 +
-  Tucker-Lewis Index (TLI)                       1.000 +
- +
-Loglikelihood and Information Criteria: +
- +
-  Loglikelihood user model (H0)               -481.884 +
-  Loglikelihood unrestricted model (H1)       -481.884 +
-                                                       +
-  Akaike (AIC)                                 973.767 +
-  Bayesian (BIC)                               990.234 +
-  Sample-size adjusted Bayesian (SABIC)        974.393 +
- +
-Root Mean Square Error of Approximation: +
- +
-  RMSEA                                          0.000 +
-  90 Percent confidence interval - lower         0.000 +
-  90 Percent confidence interval - upper         0.000 +
-  P-value H_0: RMSEA <= 0.050                       NA +
-  P-value H_0: RMSEA >= 0.080                       NA +
- +
-Standardized Root Mean Square Residual: +
- +
-  SRMR                                           0.000 +
- +
-Parameter Estimates: +
- +
-  Standard errors                             Standard +
-  Information                                 Expected +
-  Information saturated (h1) model          Structured +
- +
-Regressions: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-  behavior ~                                           +
-    attitude   (c)    0.029    0.071    0.412    0.680 +
-  intention ~                                          +
-    attitude   (a)    0.484    0.058    8.333    0.000 +
-  behavior ~                                           +
-    intention  (b)    0.438    0.075    5.832    0.000 +
- +
-Variances: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-   .behavior          0.698    0.070    9.975    0.000 +
-   .intention         0.623    0.062    9.975    0.000 +
- +
-R-Square: +
-                   Estimate +
-    behavior          0.199 +
-    intention         0.259 +
- +
-Defined Parameters: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-    ab                0.212    0.044    4.778    0.000 +
- +
-> ########################################## +
-> # boot strapping instead of sobel test  +
-> ########################################## +
-> set.seed(101) +
-> fitmod2 <- sem(specmod, data=df,  +
-+                se="bootstrap",  +
-+                bootstrap=100) +
-> summary(fitmod2, fit.measures=TRUE, rsquare=TRUE) +
-lavaan 0.6.16 ended normally after 1 iteration +
- +
-  Estimator                                         ML +
-  Optimization method                           NLMINB +
-  Number of model parameters                         5 +
- +
-  Number of observations                           199 +
- +
-Model Test User Model: +
-                                                       +
-  Test statistic                                 0.000 +
-  Degrees of freedom                                 0 +
- +
-Model Test Baseline Model: +
- +
-  Test statistic                               103.700 +
-  Degrees of freedom                                 3 +
-  P-value                                        0.000 +
- +
-User Model versus Baseline Model: +
- +
-  Comparative Fit Index (CFI)                    1.000 +
-  Tucker-Lewis Index (TLI)                       1.000 +
- +
-Loglikelihood and Information Criteria: +
- +
-  Loglikelihood user model (H0)               -481.884 +
-  Loglikelihood unrestricted model (H1)       -481.884 +
-                                                       +
-  Akaike (AIC)                                 973.767 +
-  Bayesian (BIC)                               990.234 +
-  Sample-size adjusted Bayesian (SABIC)        974.393 +
- +
-Root Mean Square Error of Approximation: +
- +
-  RMSEA                                          0.000 +
-  90 Percent confidence interval - lower         0.000 +
-  90 Percent confidence interval - upper         0.000 +
-  P-value H_0: RMSEA <= 0.050                       NA +
-  P-value H_0: RMSEA >= 0.080                       NA +
- +
-Standardized Root Mean Square Residual: +
- +
-  SRMR                                           0.000 +
- +
-Parameter Estimates: +
- +
-  Standard errors                            Bootstrap +
-  Number of requested bootstrap draws              100 +
-  Number of successful bootstrap draws             100 +
- +
-Regressions: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-  behavior ~                                           +
-    attitude   (c)    0.029    0.074    0.397    0.692 +
-  intention ~                                          +
-    attitude   (a)    0.484    0.060    8.131    0.000 +
-  behavior ~                                           +
-    intention  (b)    0.438    0.081    5.422    0.000 +
- +
-Variances: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-   .behavior          0.698    0.050   14.099    0.000 +
-   .intention         0.623    0.057   10.982    0.000 +
- +
-R-Square: +
-                   Estimate +
-    behavior          0.199 +
-    intention         0.259 +
- +
-Defined Parameters: +
-                   Estimate  Std.Err  z-value  P(>|z|) +
-    ab                0.212    0.046    4.639    0.000 +
- +
-> parameterEstimates(fitmod2,  +
-+                    ci=TRUE, level=.95,  +
-+                    boot.ci.type="perc"+
-        lhs op       rhs label   est    se      z pvalue ci.lower ci.upper +
-1  behavior  ~  attitude     c 0.029 0.074  0.397  0.692   -0.119    0.198 +
-2 intention  ~  attitude     a 0.484 0.060  8.131  0.000    0.329    0.580 +
-3  behavior  ~ intention     b 0.438 0.081  5.422  0.000    0.268    0.616 +
-4  behavior ~~  behavior       0.698 0.050 14.099  0.000    0.583    0.781 +
-5 intention ~~ intention       0.623 0.057 10.982  0.000    0.496    0.726 +
-6  attitude ~~  attitude       0.928 0.000     NA     NA    0.928    0.928 +
-7        ab :=       a*b    ab 0.212 0.046  4.639  0.000    0.115    0.313 +
->  +
->  +
->  +
-> ############################# +
-> # poking 둘러보기 +
-> # 모델 =  +
-> #          a  Intention +
-> # Attitude               Behavior +
-> # +
-> lm.ba.01 <- lm(behavior~attitude+intention, data=df) # all +
-> lm.ba.02 <- lm(behavior~intention, data=df)  # b path +
-> lm.ba.03 <- lm(intention~attitude, data=df)  # a path +
-> lm.ba.04 <- lm(attitude~intention, data=df)  # reverse a path  +
-> lm.ba.05 <- lm(behavior~attitude, data=df)   # c prime path +
->  +
-> summary(lm.ba.05)  +
- +
-Call: +
-lm(formula = behavior ~ attitude, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--1.96792 -0.62906  0.08816  0.66248  1.81281  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  2.33552    0.22214  10.514  < 2e-16 *** +
-attitude     0.24126    0.06688   3.608 0.000392 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.9087 on 197 degrees of freedom +
-Multiple R-squared:  0.06197, Adjusted R-squared:  0.05721  +
-F-statistic: 13.02 on 1 and 197 DF,  p-value: 0.0003917 +
- +
-> summary(lm.ba.01) +
- +
-Call: +
-lm(formula = behavior ~ attitude + intention, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--2.01916 -0.57280  0.06326  0.63735  1.73810  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  1.69617    0.23358   7.262 8.79e-12 *** +
-attitude     0.02941    0.07196   0.409    0.683     +
-intention    0.43767    0.07561   5.788 2.78e-08 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8419 on 196 degrees of freedom +
-Multiple R-squared:  0.1989, Adjusted R-squared:  0.1907  +
-F-statistic: 24.33 on 2 and 196 DF,  p-value: 3.636e-10 +
- +
-> names(lm.ba.03) +
- [1] "coefficients"  "residuals"     "effects"       "rank"          +
- [5] "fitted.values" "assign"        "qr"            "df.residual"   +
- [9] "xlevels"       "call"          "terms"         "model"         +
-> reg.int <- lm.ba.03$fitted.values - mean(df$intention) +
-> res.int <- summary(lm.ba.03)$residuals +
-> # just checking  +
-> sum(reg.int^2) + sum(res.int^2) +
-[1] 167.2277 +
-> var(df$intention)*(length(df$intention)-1) +
-[1] 167.2277 +
-> # the intention part contributed by attitudes  +
-> # is it explaing behavior too?  +
-> lm.ba.021 <- lm(behavior~reg.int, data=df)  +
-> summary(lm.ba.021) +
- +
-Call: +
-lm(formula = behavior ~ reg.int, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--1.96792 -0.62906  0.08816  0.66248  1.81281  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.06441  48.165  < 2e-16 *** +
-reg.int      0.49843    0.13816   3.608 0.000392 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.9087 on 197 degrees of freedom +
-Multiple R-squared:  0.06197, Adjusted R-squared:  0.05721  +
-F-statistic: 13.02 on 1 and 197 DF,  p-value: 0.0003917 +
- +
-> int.all <- res.int + reg.int  +
-> lm.temp <- lm(behavior~int.all, data=df) +
-> summary(lm.temp) +
- +
-Call: +
-lm(formula = behavior ~ int.all, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--2.03770 -0.55555  0.06686  0.63565  1.75678  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.05955  52.097  < 2e-16 *** +
-int.all      0.45338    0.06496   6.979 4.43e-11 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8401 on 197 degrees of freedom +
-Multiple R-squared:  0.1982, Adjusted R-squared:  0.1942  +
-F-statistic: 48.71 on 1 and 197 DF,  p-value: 4.427e-11 +
- +
-> summary(lm.ba.02) +
- +
-Call: +
-lm(formula = behavior ~ intention, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--2.03770 -0.55555  0.06686  0.63565  1.75678  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  1.74252    0.20377   8.552 3.37e-15 *** +
-intention    0.45338    0.06496   6.979 4.43e-11 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8401 on 197 degrees of freedom +
-Multiple R-squared:  0.1982, Adjusted R-squared:  0.1942  +
-F-statistic: 48.71 on 1 and 197 DF,  p-value: 4.427e-11 +
- +
-> summary(lm.ba.021) +
- +
-Call: +
-lm(formula = behavior ~ reg.int, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--1.96792 -0.62906  0.08816  0.66248  1.81281  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.06441  48.165  < 2e-16 *** +
-reg.int      0.49843    0.13816   3.608 0.000392 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.9087 on 197 degrees of freedom +
-Multiple R-squared:  0.06197, Adjusted R-squared:  0.05721  +
-F-statistic: 13.02 on 1 and 197 DF,  p-value: 0.0003917 +
- +
-> summary(lm.ba.022) +
-h(simpleError(msg, call))에서 다음과 같은 에러가 발생했습니다: +
-  함수 'summary'를 위한 메소드 선택시 인수 'object'를 평가하는데 오류가 발생했습니다: 객체 'lm.ba.022'를 찾을 수 없습니다 +
-> # the pure intention part excluding  +
-> # what attitude contributes +
-> lm.ba.022 <- lm(behavior~res.int, data=df) +
-> summary(lm.ba.022) +
- +
-Call: +
-lm(formula = behavior ~ res.int, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--1.94981 -0.57202  0.03753  0.66449  1.93134  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.06179  50.213  < 2e-16 *** +
-res.int      0.43767    0.07828   5.591 7.47e-08 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8716 on 197 degrees of freedom +
-Multiple R-squared:  0.1369, Adjusted R-squared:  0.1326  +
-F-statistic: 31.26 on 1 and 197 DF,  p-value: 7.466e-08 +
- +
-> summary(lm.ba.022) +
- +
-Call: +
-lm(formula = behavior ~ res.int, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--1.94981 -0.57202  0.03753  0.66449  1.93134  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.06179  50.213  < 2e-16 *** +
-res.int      0.43767    0.07828   5.591 7.47e-08 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8716 on 197 degrees of freedom +
-Multiple R-squared:  0.1369, Adjusted R-squared:  0.1326  +
-F-statistic: 31.26 on 1 and 197 DF,  p-value: 7.466e-08 +
- +
-> # intention - behavior part +
-> summary(lm.ba.02)$r.squared +
-[1] 0.1982297 +
-> # K - attitudes 가 intention을 설명해 주는 부분 (regression error) +
-> summary(lm.ba.021)$r.squared +
-[1] 0.06197255 +
-> # J - attitudes 가 설명하지 못하는 부분 (residual error)  +
-> summary(lm.ba.022)$r.squared +
-[1] 0.1369399 +
-> # 위에서 intention은 K와 J로 이루어져 있다. 이를 확인하는 것 +
-> summary(lm.ba.021)$r.squared + summary(lm.ba.022)$r.squared +
-[1] 0.1989125 +
->  +
-> # lm.ba.04 <- lm(attitude~intention, data=df)  # reverse a path  +
-> res.temp <- lm.ba.04$residuals +
-> lm.temp <- lm(behavior~res.temp, data=df) +
-> summary(lm.temp) +
- +
-Call: +
-lm(formula = behavior ~ res.temp, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--2.11381 -0.61542  0.07249  0.69545  1.90977  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  3.10251    0.06649  46.664   <2e-16 *** +
-res.temp     0.02941    0.08017   0.367    0.714     +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.9379 on 197 degrees of freedom +
-Multiple R-squared:  0.0006828, Adjusted R-squared:  -0.00439  +
-F-statistic: 0.1346 on 1 and 197 DF,  p-value: 0.7141 +
- +
-> summary(lm.ba.01) +
- +
-Call: +
-lm(formula = behavior ~ attitude + intention, data = df) +
- +
-Residuals: +
-     Min       1Q   Median       3Q      Max  +
--2.01916 -0.57280  0.06326  0.63735  1.73810  +
- +
-Coefficients: +
-            Estimate Std. Error t value Pr(>|t|)     +
-(Intercept)  1.69617    0.23358   7.262 8.79e-12 *** +
-attitude     0.02941    0.07196   0.409    0.683     +
-intention    0.43767    0.07561   5.788 2.78e-08 *** +
---- +
-Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +
- +
-Residual standard error: 0.8419 on 196 degrees of freedom +
-Multiple R-squared:  0.1989, Adjusted R-squared:  0.1907  +
-F-statistic: 24.33 on 2 and 196 DF,  p-value: 3.636e-10 +
- +
->  +
->  +
-> abc <- summary(lm.ba.01)$r.square +
-> ab <- summary(lm.ba.02)$r.square +
-> bc <- summary(lm.ba.05)$r.square +
-> abc +
-[1] 0.1989125 +
-> abbc <- ab + bc  +
-> ab +
-[1] 0.1982297 +
-> bc +
-[1] 0.06197255 +
-> a <- abc - bc +
-> abbc <- ab + bc  +
-> abbc +
-[1] 0.2602023 +
-> b <- abbc - abc +
-> b +
-[1] 0.0612898 +
-> a +
-[1] 0.1369399 +
-> c +
-function (...)  .Primitive("c"+
-> c <- abc - ab +
-> c +
-[1] 0.0006827583 +
-> install.packages("lavaan")str(processdata) +
-에러: 예상하지 못한 기호(symbol)입니다. in "install.packages("lavaan")str"+
  
 > # processdata<-read.csv("path analysis dataN BinW.csv", header=TRUE, sep=",") > # processdata<-read.csv("path analysis dataN BinW.csv", header=TRUE, sep=",")
 > 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") +                        header=TRUE, sep=",", fileEncoding="UTF-8-BOM")
 +
 > str(processdata) > str(processdata)
 'data.frame': 140 obs. of  9 variables: 'data.frame': 140 obs. of  9 variables:
Line 1234: Line 680:
  $ pgoal_MS: int  0 0 1 1 0 1 0 1 0 0 ...  $ pgoal_MS: int  0 0 1 1 0 1 0 1 0 0 ...
 > library(lavaan) > library(lavaan)
 +
 > # model specification > # model specification
 > model <- ' > model <- '
Line 1268: Line 715:
 +   # for interest and anxiety +   # for interest and anxiety
 +   interest ~~ anxiety ' +   interest ~~ anxiety '
 +
 > fit<-lavaan(model, data=processdata) > fit<-lavaan(model, data=processdata)
 > summary(fit, fit.measures=TRUE) > summary(fit, fit.measures=TRUE)
Line 1447: Line 895:
     achieve           0.387     achieve           0.387
  
-+>  
 +> parameterEstimates(fit) 
 +        lhs op      rhs    est    se      z pvalue ci.lower ci.upper 
 +1  interest  ~  mastery  0.708 0.088  8.066  0.000    0.536    0.880 
 +2  interest  ~ perfgoal -0.035 0.040 -0.879  0.380   -0.114    0.043 
 +3  interest  ~      ses  0.520 0.242  2.154  0.031    0.047    0.994 
 +4   achieve  ~  anxiety -0.040 0.054 -0.747  0.455   -0.146    0.066 
 +5   achieve  ~ interest  0.211 0.060  3.527  0.000    0.094    0.328 
 +6   achieve  ~  mastery  0.345 0.079  4.358  0.000    0.190    0.500 
 +7   anxiety  ~ perfgoal  0.025 0.045  0.556  0.578   -0.063    0.113 
 +8   anxiety  ~  mastery -0.387 0.097 -4.009  0.000   -0.576   -0.198 
 +9   mastery ~~  mastery  1.944 0.232  8.367  0.000    1.488    2.399 
 +10 perfgoal ~~ perfgoal  8.936 1.068  8.367  0.000    6.842   11.029 
 +11      ses ~~      ses  0.249 0.030  8.367  0.000    0.191    0.308 
 +12  mastery ~~ perfgoal -0.935 0.361 -2.590  0.010   -1.642   -0.227 
 +13  mastery ~~      ses  0.170 0.061  2.805  0.005    0.051    0.288 
 +14 perfgoal ~~      ses -0.226 0.128 -1.768  0.077   -0.476    0.024 
 +15 interest ~~ interest  1.895 0.227  8.367  0.000    1.451    2.339 
 +16  anxiety ~~  anxiety  2.410 0.288  8.367  0.000    1.845    2.974 
 +17  achieve ~~  achieve  0.988 0.118  8.367  0.000    0.757    1.220 
 +18 interest ~~  anxiety  0.059 0.181  0.329  0.742   -0.295    0.414 
 +> fitMeasures(fit) 
 +                 npar                  fmin                 chisq  
 +               18.000                 0.104                29.231  
 +                   df                pvalue        baseline.chisq  
 +                3.000                 0.000               202.409  
 +          baseline.df       baseline.pvalue                   cfi  
 +               15.000                 0.000                 0.860  
 +                  tli                  nnfi                   rfi  
 +                0.300                 0.300                 0.278  
 +                  nfi                  pnfi                   ifi  
 +                0.856                 0.171                 0.868  
 +                  rni                  logl     unrestricted.logl  
 +                0.860             -1391.274             -1376.659  
 +                  aic                   bic                ntotal  
 +             2818.548              2871.498               140.000  
 +                 bic2                 rmsea        rmsea.ci.lower  
 +             2814.548                 0.250                 0.172  
 +       rmsea.ci.upper        rmsea.ci.level          rmsea.pvalue  
 +                0.336                 0.900                 0.000  
 +       rmsea.close.h0 rmsea.notclose.pvalue     rmsea.notclose.h0  
 +                0.050                 1.000                 0.080  
 +                  rmr            rmr_nomean                  srmr  
 +                0.122                 0.122                 0.074  
 +         srmr_bentler   srmr_bentler_nomean                  crmr  
 +                0.074                 0.074                 0.088  
 +          crmr_nomean            srmr_mplus     srmr_mplus_nomean  
 +                0.088                 0.074                 0.074  
 +                cn_05                 cn_01                   gfi  
 +               38.428                55.335                 0.941  
 +                 agfi                  pgfi                   mfi  
 +                0.587                 0.134                 0.911  
 +                 ecvi  
 +                0.466  
 +> modificationIndices(fit) 
 +        lhs op      rhs     mi    epc sepc.lv sepc.all sepc.nox 
 +19 interest ~~  achieve 25.396 -2.899  -2.899   -2.118   -2.118 
 +23  achieve ~~  anxiety  6.669  6.803   6.803    4.408    4.408 
 +24  achieve ~~  mastery 22.476 -1.743  -1.743   -1.257   -1.257 
 +25  achieve ~~ perfgoal  2.763 -0.406  -0.406   -0.137   -0.137 
 +26  achieve ~~      ses 20.541  0.186   0.186    0.376    0.376 
 +27  anxiety ~~  mastery  0.921  0.765   0.765    0.354    0.354 
 +28  anxiety ~~ perfgoal  0.921 -3.576  -3.576   -0.771   -0.771 
 +29  anxiety ~~      ses  0.921 -0.061  -0.061   -0.078   -0.078 
 +30 interest  ~  achieve 25.396 -2.933  -2.933   -2.106   -2.106 
 +32  achieve  ~ perfgoal  4.551 -0.062  -0.062   -0.146   -0.146 
 +33  achieve  ~      ses 22.431  0.837   0.837    0.329    0.329 
 +34  anxiety  ~ interest  0.921 -0.502  -0.502   -0.538   -0.538 
 +35  anxiety  ~  achieve  1.119  1.922   1.922    1.478    1.478 
 +36  anxiety  ~      ses  0.921 -0.261  -0.261   -0.079   -0.079 
 +37  mastery  ~ interest  0.923 12.889  12.889   16.348   16.348 
 +38  mastery  ~  achieve 22.801 -1.774  -1.774   -1.616   -1.616 
 +39  mastery  ~  anxiety  0.921  0.318   0.318    0.376    0.376 
 +43 perfgoal  ~  achieve  2.745 -0.410  -0.410   -0.174   -0.174 
 +44 perfgoal  ~  anxiety  0.921 -1.484  -1.484   -0.820   -0.820 
 +47      ses  ~ interest  0.923 -1.021  -1.021   -3.618   -3.618 
 +48      ses  ~  achieve 20.964  0.190   0.190    0.484    0.484 
 +49      ses  ~  anxiety  0.921 -0.025  -0.025   -0.083   -0.083 
 +>  
 +
 </code> </code>
  
  
 +
 +-----------------------------
 +  * Specification of model using auto.var argument...
 +<code>
 +# model specification
 +
 +model<-'
 +  # equation where interest is predicted by ses & mastery and 
 +  # performance goals
 +  interest ~ mastery + perfgoal + ses
 +
 +  # equation where achieve is predicted by interest and anxiety
 +  achieve~anxiety+interest+mastery
 +
 +  #equation where anxiety is predicted by mastery and performance goals
 +  anxiety~perfgoal+mastery
 +
 +  # estimtating the variances of the exogenous variables (ses, mastery,performance)
 +  mastery~~mastery
 +  perfgoal~~perfgoal
 +  ses~~ses
 +
 +  # estimtating the covariances of the exogenous variables (ses, mastery,performance)
 +  mastery~~perfgoal+ses
 +  perfgoal~~ses
 +
 +  # The auto.var argument when fitting the model can be used so that 
 +  # you do not have to directly request estimation of residual variances
 +
 +  # Estimating the covariance of residuals for interest and anxiety
 +  interest~~anxiety'
 +
 +  fit<-lavaan(model, data=processdata, auto.var=TRUE)
 +  summary(fit, fit.measures=TRUE, standardized=TRUE, rsquare=TRUE)
 +</code>
  
   * There are a couple of ways you can obtain path diagrams (although they can be somewhat tricky to implement.    * There are a couple of ways you can obtain path diagrams (although they can be somewhat tricky to implement. 
r/path_analysis.1730258849.txt.gz · Last modified: 2024/10/30 12:27 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki