library(lavaan) 
## Warning: package 'lavaan' was built under R version 4.2.2
## This is lavaan 0.6-13
## lavaan is FREE software! Please report any bugs.
withdraw_data <- read.csv("estress.csv")
#Print the first 6 rows of the dataset
head(withdraw_data)
##   tenure estress affect withdraw sex age  ese
## 1   1.67     6.0   2.60     3.00   1  51 5.33
## 2   0.58     5.0   1.00     1.00   0  45 6.05
## 3   0.58     5.5   2.40     3.66   1  42 5.26
## 4   2.00     3.0   1.16     4.66   1  50 4.35
## 5   5.00     4.5   1.00     4.33   1  48 4.86
## 6   9.00     6.0   1.50     3.00   1  48 5.05
#Report means, SDs and correlation matrix for all variables in the model.
#means:
mean(withdraw_data$estress)
## [1] 4.620229
mean(withdraw_data$affect)
## [1] 1.598092
mean(withdraw_data$withdraw)
## [1] 2.321145
mean(withdraw_data$sex)
## [1] 0.6183206
mean(withdraw_data$age)
## [1] 43.79389
#SDs

sd(withdraw_data$estress)
## [1] 1.423614
sd(withdraw_data$affect)
## [1] 0.7237171
sd(withdraw_data$withdraw)
## [1] 1.24687
sd(withdraw_data$sex)
## [1] 0.4867283
sd(withdraw_data$age)
## [1] 10.3596
#correlation matrix for all variables in the model
(cor(withdraw_data[, c("withdraw","estress", "affect","sex", "age")]))
##             withdraw    estress      affect        sex         age
## withdraw  1.00000000 0.06407186  0.41658602 0.05002922 -0.03526418
## estress   0.06407186 1.00000000  0.34006259 0.13283301  0.06598494
## affect    0.41658602 0.34006259  1.00000000 0.04621758 -0.01779056
## sex       0.05002922 0.13283301  0.04621758 1.00000000  0.08311985
## age      -0.03526418 0.06598494 -0.01779056 0.08311985  1.00000000
#Compute the covariance matrices
(cov(withdraw_data[, c("estress", "affect", "withdraw", "sex", "age")]))
##             estress      affect    withdraw        sex         age
## estress  2.02667734  0.35036442  0.11373154 0.09204177   0.9731508
## affect   0.35036442  0.52376646  0.37591943 0.01628031  -0.1333833
## withdraw 0.11373154  0.37591943  1.55468527 0.03036208  -0.4555102
## sex      0.09204177  0.01628031  0.03036208 0.23690445   0.4191161
## age      0.97315083 -0.13338335 -0.45551022 0.41911614 107.3213419
################

Model<-'
withdraw~affect 
affect~estress'
fit<-sem(Model,withdraw_data) 
fit
## lavaan 0.6.13 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##   Number of observations                           262
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.167
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.141
######
summary(fit, header = FALSE, standardize = TRUE, ci = TRUE)
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   withdraw ~                                                            
##     affect            0.718    0.097    7.417    0.000    0.528    0.907
##   affect ~                                                              
##     estress           0.173    0.030    5.853    0.000    0.115    0.231
##    Std.lv  Std.all
##                   
##     0.718    0.417
##                   
##     0.173    0.340
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .withdraw          1.280    0.112   11.446    0.000    1.061    1.499
##    .affect            0.461    0.040   11.446    0.000    0.382    0.540
##    Std.lv  Std.all
##     1.280    0.826
##     0.461    0.884
parameterEstimates(fit)
##        lhs op      rhs   est    se      z pvalue ci.lower ci.upper
## 1 withdraw  ~   affect 0.718 0.097  7.417      0    0.528    0.907
## 2   affect  ~  estress 0.173 0.030  5.853      0    0.115    0.231
## 3 withdraw ~~ withdraw 1.280 0.112 11.446      0    1.061    1.499
## 4   affect ~~   affect 0.461 0.040 11.446      0    0.382    0.540
## 5  estress ~~  estress 2.019 0.000     NA     NA    2.019    2.019
######labeled
Model<-'
withdraw ~ b * affect + age + sex + estress
affect ~ a * estress + age + sex
ind := a * b'

fit <- sem(Model,withdraw_data) 
fit
## lavaan 0.6.13 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                           262
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
summary(fit, header = FALSE, standardize = TRUE, ci = TRUE)
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   withdraw ~                                                            
##     affect     (b)    0.767    0.102    7.490    0.000    0.566    0.968
##     age              -0.003    0.007   -0.444    0.657   -0.016    0.010
##     sex               0.112    0.145    0.773    0.440   -0.172    0.396
##     estress          -0.080    0.053   -1.525    0.127   -0.183    0.023
##   affect ~                                                              
##     estress    (a)    0.174    0.030    5.834    0.000    0.116    0.232
##     age              -0.003    0.004   -0.698    0.485   -0.011    0.005
##     sex               0.006    0.087    0.071    0.944   -0.165    0.177
##    Std.lv  Std.all
##                   
##     0.767    0.445
##    -0.003   -0.025
##     0.112    0.044
##    -0.080   -0.091
##                   
##     0.174    0.342
##    -0.003   -0.041
##     0.006    0.004
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .withdraw          1.266    0.111   11.446    0.000    1.049    1.483
##    .affect            0.461    0.040   11.446    0.000    0.382    0.539
##    Std.lv  Std.all
##     1.266    0.817
##     0.461    0.883
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     ind               0.133    0.029    4.603    0.000    0.077    0.190
##    Std.lv  Std.all
##     0.133    0.152
#parameterEstimates(fit)

############

# library("semPlot")
# 
# semPaths(fit, what = "est", fade = FALSE)
# 
# library(lavaanPlot)
# 
# lavaanPlot(model = fit)
# 
# #
# withdraw_pa <- sem(model= withdraw_model, sample.cov = cov_mat, sample.nobs = 262)
# withdraw_pa
# 
# summary(withdraw_pa, header = FALSE, standardize = TRUE, ci = TRUE)

library(lavaanPlot) # for plotting SEMs
## Warning: package 'lavaanPlot' was built under R version 4.2.2
# lavaanPlot(
#   model = withdraw_pa, coefs = TRUE, covs = TRUE,
#   stars = "regress")

lavaanPlot(
  model = fit, coefs = TRUE, covs = TRUE,
  stars = "regress", stand = TRUE)
fit_mod <- sem(
  model = Model, data =withdraw_data,
  se = "bootstrap", bootstrap = 5000)
summary(fit_mod, standardize = TRUE, rsquare = TRUE, ci = TRUE)
## lavaan 0.6.13 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                           262
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                            Bootstrap
##   Number of requested bootstrap draws             5000
##   Number of successful bootstrap draws            5000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   withdraw ~                                                            
##     affect     (b)    0.767    0.142    5.404    0.000    0.495    1.038
##     age              -0.003    0.007   -0.444    0.657   -0.016    0.010
##     sex               0.112    0.150    0.746    0.456   -0.184    0.396
##     estress          -0.080    0.055   -1.447    0.148   -0.183    0.034
##   affect ~                                                              
##     estress    (a)    0.174    0.041    4.254    0.000    0.091    0.250
##     age              -0.003    0.005   -0.610    0.542   -0.012    0.006
##     sex               0.006    0.093    0.066    0.947   -0.182    0.185
##    Std.lv  Std.all
##                   
##     0.767    0.445
##    -0.003   -0.025
##     0.112    0.044
##    -0.080   -0.091
##                   
##     0.174    0.342
##    -0.003   -0.041
##     0.006    0.004
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .withdraw          1.266    0.094   13.435    0.000    1.062    1.428
##    .affect            0.461    0.081    5.688    0.000    0.310    0.624
##    Std.lv  Std.all
##     1.266    0.817
##     0.461    0.883
## 
## R-Square:
##                    Estimate
##     withdraw          0.183
##     affect            0.117
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     ind               0.133    0.034    3.977    0.000    0.072    0.204
##    Std.lv  Std.all
##     0.133    0.152
#The interpretation of results 
# We used path analysis to test the withdrawal intentions path model based on data from 262 entrepreneurs. We used lavaan version 0.6.14 (Rosseel, 2012), with maximum likelihood estimation. 
#Entrepreneurs who reported experiencing greater economic stress reported greater depressed affect (b = 0.174, se = 0.04, p = .000), and this greater depressed affect in turn was related to an increased intention to withdraw from entrepreneurial activity (b = 0.767, se = 0.142, p = .000).
#Depressed affect is the proposed mediator of economic stress on withdrawal intentions. The results demonstrated that the indirect effects from economic stress (b = 0.133, se = 0.029, p = .000)to quantitative withdrawal intentions via Depressed affect were statistically significant. 
#There were no prediction of significant effect of gender or age on the withdrawal intentions  P>0.05

citation("lavaan") 
## 
## To cite lavaan in publications use:
## 
##   Yves Rosseel (2012). lavaan: An R Package for Structural Equation
##   Modeling. Journal of Statistical Software, 48(2), 1-36.
##   https://doi.org/10.18637/jss.v048.i02
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {{lavaan}: An {R} Package for Structural Equation Modeling},
##     author = {Yves Rosseel},
##     journal = {Journal of Statistical Software},
##     year = {2012},
##     volume = {48},
##     number = {2},
##     pages = {1--36},
##     doi = {10.18637/jss.v048.i02},
##   }

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: