RE: Lavaan error

54 views
Skip to first unread message

roger akanji

unread,
Apr 19, 2024, 7:32:21 AM4/19/24
to lav...@googlegroups.com
Hi

I am trying to conduct path analysis using lavaan

Model specification 
specmod <- "
return_on_assets ~ C*equity_based_compensation
derivative_use ~ a*equity_based_compensation
return_on_assests ~ b*derivative_use
ab := a*b
"

Fit model:
fitmod <- sem(specmod,data=df)
fitmod <- sem(specmod,data=Df)
fitmod <- sem(specmod,data=DF)

when i run this model, lavaan error pops up as follows: 
Error in lavaan::lavaan(model = specmod, data = df, int.ov.free = TRUE,  : 
  lavaan ERROR: missing observed variables in dataset: ROA Derivativeuse

Error in lavaan::lavaan(model = specmod, data = DF, int.ov.free = TRUE,  : 
  lavaan ERROR: missing observed variables in dataset: ROA Derivativeuse
Error in lavaan::lavaan(model = specmod, data = Df, int.ov.free = TRUE,  : 
  lavaan ERROR: missing observed variables in dataset: ROA Derivativeuse

Error in sem(specmod, data = df, data = DF, data = Df) : 
  formal argument "data" matched by multiple actual arguments

I am stuck and can't go ahead with my research, can someone help?

thank you very much

Roger

Rönkkö, Mikko

unread,
Apr 19, 2024, 8:23:04 AM4/19/24
to lav...@googlegroups.com

Hi,

 

I would recommend restarting R or clearing the environment to ensure that “specmod” contains the model of interest and not an older version. The code that you profided cannot produce the error that you provided because the model does not have ROA as variable.

 

As a sidenote: I would probably not use lavaan to run the model that you have. The model is saturated path model and just running it as two regressions (lm) gives you the same result with less complexity.

 

Mikko

 

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAHrukrxVqZZEZKSoATFeQ%3DknSU0L9b--agzNFVSOpeWLHiK5nQ%40mail.gmail.com.

roger akanji

unread,
Apr 19, 2024, 8:28:15 AM4/19/24
to lav...@googlegroups.com

roger akanji

unread,
Apr 19, 2024, 8:35:44 AM4/19/24
to lav...@googlegroups.com
Hi Mikko

Sorry, what you mean by 'The model is a saturated path model and just running it as two regressions (lm) gives you the same result with less complexity'.

do you mean there is another package which works exactly like lavaan? If so, which package do you recommend?

regards

 


On Fri, 19 Apr 2024 at 13:23, Rönkkö, Mikko <mikko....@jyu.fi> wrote:

roger akanji

unread,
Apr 20, 2024, 3:45:19 AM4/20/24
to lav...@googlegroups.com
Hi 

Good morning/afternoon

I hope this email finds you well

I am a research student new to mediation analysis. 
I have been following videos on mediation analysis on youtube for some time now.  
I have adapted the model specification used by specialists in youtube videos which seems to me to be ok.
However, when I try to fit model, lavaan error pop up as indicated below:

Error in lavaan::lavaan(model = specmod, data = newdata, int.ov.free = TRUE, : lavaan ERROR: missing observed variables in dataset: return_on_assets derivative_use
Model specification is:
specmod <- "
return_on_assets ~ c*equity_based_compensation
derivative_use ~ a*equity_based_compensation
return_on_assets ~ b*derivative_use
ab := a*b
"
Fit Model is:
fitmod <- sem(specmod,data=newdata)

More so, when I typed in cat(specmod) it gives me the output below:
variables        X2022        X2021        X2020        X2019
1   equity_based_compensation            0       240588       299517       112206
2   equity_based_compensation         1233          565            0          554
3   equity_based_compensation            0            0            0            0
4   equity_based_compensation           20           21           23           23
5   equity_based_compensation          466       441247       159574            0
6   equity_based_compensation     11165439     11601866     13514588     15821972
7   equity_based_compensation       210473       218711       210473       723913
8   equity_based_compensation            0            0            0            0
9   equity_based_compensation            0            0            0            0
10  equity_based_compensation          451          496          369          222
11  equity_based_compensation            0            0            0            0
12  equity_based_compensation           23           24            0            0
13  equity_based_compensation            5            5            5            5
14  equity_based_compensation            7            4            0            0
15  equity_based_compensation           69          127          145          205
16  equity_based_compensation         1278         1278         2995         3119
17  equity_based_compensation            9            8            7           11
18  equity_based_compensation           71       188144        55398            0
19  equity_based_compensation         1686         7806         1475         1228
20  equity_based_compensation        30222       184732       775552       981042
21  equity_based_compensation         1226         1274          976          573
22  equity_based_compensation            0            0        62574       140289
23  equity_based_compensation          114           70           38          247
24  equity_based_compensation        26019        33686        62226       193802
25  equity_based_compensation         5884         8699            0          744
26  equity_based_compensation         1562          863          110          762
27  equity_based_compensation           28         1612          556          535
28  equity_based_compensation            0            0            0            0
29  equity_based_compensation         7661            0         1898            0
30  equity_based_compensation        47627        11955        16586         2217
31  equity_based_compensation           19            0         1271            3
32  equity_based_compensation          569          569          495          462
33  equity_based_compensation         1416         1972         1938          540
34  equity_based_compensation       107450        76080       193333        27342
35  equity_based_compensation         4764         4611         6664         6154
36  equity_based_compensation         1645         4349          666         2085
37  equity_based_compensation            7            5            0            0
38  equity_based_compensation       930243       637521      1033623      1560338
39  equity_based_compensation           58          116          209          277
40  equity_based_compensation           30           34           31            2
41             derivative_use            0            0            0        5,312
42             derivative_use           -3            5            3          -53
43             derivative_use  19.61956522       -3,338       -2,027  254.0217391
44             derivative_use       -1,076          -86          336         -244
45             derivative_use        4,385       -1,375 -448.4042553 -259.1567852
46             derivative_use       94,702       55,605       52,246       51,824
47             derivative_use       -3,095       -3,095        1,184          102
48             derivative_use        5,247        5,526        4,761       10,567
49             derivative_use          165         -646         -152       -1,682
50             derivative_use          101        3,332        3,871          -89
51             derivative_use  98.90282132 -73.31628303  69.87951807  82.08255159
52             derivative_use        1,422 -68.04260985  592.6122931        1,455
53             derivative_use         -428          -10         -428           -3
54             derivative_use         -622       -1,693       -1,532       -1,341
55             derivative_use            0          -17          842       -1,265
56             derivative_use     -216,608     -216,608       -5,025     -216,608
57             derivative_use           40          111         -108  4.529370134
58             derivative_use  60.84161309  570.2821317  527.2229822           34
59             derivative_use -34.54210203 -66.06145251  45.22439586 -25.51092319
60             derivative_use          -26          -26          -26       -1,053
61             derivative_use        9,820         -842            0            0
62             derivative_use     -175,640     -140,818       18,959      296,323
63             derivative_use            0            0 -169.0102389  -578.683834
64             derivative_use      685,463    1,837,176      339,012            0
65             derivative_use -6.627565982 -0.878293601 -0.476839237  3.862660944
66             derivative_use        3,196 -129.1450777       -1,051 -671.3178295
67             derivative_use            5           27           15          -31
68             derivative_use          134          134  134.4439784        3,461
69             derivative_use          686          180       -9,639         -918
70             derivative_use     -719,718     -271,960      -16,204       79,496
71             derivative_use            0            0            0  50.42918455
72             derivative_use  16.94805195  11.44179894   9.08509277  4.474431818
73             derivative_use          754       -3,745       -1,648         -162
74             derivative_use           38           78          -15           23
75             derivative_use           -5           -2           18          101
76             derivative_use       -7,148       10,170       -5,297       -4,031
77             derivative_use  8.764705882  43.57366771            0            0
78             derivative_use     -763,753            0            0            0
79             derivative_use       -2,442         -180         -158          -12
80             derivative_use -27.77777778 -5.379131562  20.30169705 -12.17150761
81           return_on_assets       -18.59        -0.41        -0.39        -0.08
82           return_on_assets         0.07         0.04         0.03         0.03
83           return_on_assets         0.06         0.06         7.41        -0.04
84           return_on_assets         0.09         0.18         0.05         0.08
85           return_on_assets        -0.07        -0.06         0.01         0.04
86           return_on_assets         0.35         0.12         0.08         0.09
87           return_on_assets          0.1         0.11         0.14         0.35
88           return_on_assets         0.05         0.03         0.03         0.03
89           return_on_assets         0.08          0.1        -0.03         0.02
90           return_on_assets         0.01            0            0        -0.01
91           return_on_assets          0.2         0.21          0.1         0.12
92           return_on_assets         0.04         0.04        -0.05         0.01
93           return_on_assets        -9.24         0.04        -9.24        -2.06
94           return_on_assets         0.12         0.03        -0.03        -0.01
95           return_on_assets          0.1         0.11          0.1         0.03
96           return_on_assets        -0.21        -0.21        -0.05        -0.21
97           return_on_assets        -0.02          0.1       -19.02        -0.07
98           return_on_assets         0.05          0.1        -0.05        -0.28
99           return_on_assets         0.22          0.3         0.21         0.02
100          return_on_assets        -0.01        -0.01        -0.01        -0.13
101          return_on_assets         0.08         0.06        -0.08         0.04
102          return_on_assets         0.06         0.07         0.01         0.06
103          return_on_assets         0.25         0.34        -0.32         -0.3
104          return_on_assets        -0.18         -0.2        -0.21        -0.12
105          return_on_assets         0.06         0.05         0.06         0.04
106          return_on_assets         0.04         0.08         0.02         0.03
107          return_on_assets         0.26         0.14         0.09         0.21
108          return_on_assets        -0.22        -0.22         -0.1        -0.22
109          return_on_assets         0.16         0.15         0.12          0.1
110          return_on_assets         0.19         0.15         0.12         0.13
111          return_on_assets         0.09         0.19         0.11         2.38
112          return_on_assets          0.1         0.05         0.06         0.06
113          return_on_assets         0.03         0.04        -0.02         0.08
114          return_on_assets         0.12         0.24          0.2         4.28
115          return_on_assets         0.16        -0.01        -4.73         0.03
116          return_on_assets         0.18         0.19         0.11         0.02
117          return_on_assets         0.45         0.22         0.11         0.02
118          return_on_assets        -0.07        -0.04        -0.25        -0.05
119          return_on_assets         0.01        -0.01        -0.19         -0.2
120          return_on_assets          0.1          0.1         0.09          0.1
           X2018
1          21175
2              0
3              0
4             24
5              0
6       13356657
7         241203
8              0
9              0
10           545
11             0
12             0
13             8
14             0
15           375
16          1278
17            18
18         94816
19             9
20        981042
21          1208
22        336476
23           234
24             0
25            21
26           487
27           296
28             0
29          4388
30             0
31             9
32           530
33           476
34        180094
35          6961
36          1982
37             0
38       1168943
39           262
40             2
41       181,987
42           -53
43   453.5869565
44          -375
45             0
46        51,824
47        -1,569
48        11,830
49             0
50          -995
51  -38.18860878
52         2,995
53            58
54           239
55             0
56        -4,177
57   29.54380883
58             8
59  -48.21558631
60      -503,398
61             0
62        53,958
63        -3,389
64             0
65   3.963838665
66         1,114
67          -274
68         5,097
69         2,895
70      -372,062
71             0
72  -3.543307087
73         8,772
74            15
75           149
76        40,007
77             0
78             0
79           104
80  -11.76470588
81          -0.3
82          0.03
83         23.07
84          0.08
85          0.03
86          0.08
87           0.1
88          0.03
89          0.11
90          0.05
91          0.13
92          0.02
93         21.58
94          0.02
95         -0.06
96         -0.06
97         -0.11
98         -0.12
99         -0.15
100        -0.01
101         0.03
102         0.07
103          0.1
104        -0.11
105         0.04
106         0.03
107         0.32
108         0.03
109        -0.36
110        -0.51
111          6.1
112         0.07
113         0.06
114        -0.03
115         0.09
116         0.11
117         0.02
118        -0.05
119         0.01
120         0.12

The output indicated above seems to me that the variables in the dataset are correct. I have changed variables in the dataset several times but the lavaan error message keeps popping up. I am stuck at this stage, and would be grateful if someone can help.

I look forward to hearing from you soon

thank you very much

Have a wonderful weekend

Kind regards
Roger

Rönkkö, Mikko

unread,
Apr 20, 2024, 8:04:25 AM4/20/24
to lav...@googlegroups.com

Hi,

 

cat(specmod) should print the model, not the data. But looking at the printout of your data, the variable names are

 

variables        X2022        X2021        X2020        X2019           X2018
 

This means that your data are in an incorrect format and you need to reshape or pivot the data.

 

https://r4ds.hadley.nz/data-tidy.html#sec-pivoting

 

That being said, I strongly recommend starting with just a set of two regressions (lm command) to estimate your model. Once you have that working, you can move to more advanced analyses.  

 

Mikko

 

From: lav...@googlegroups.com <lav...@googlegroups.com> on behalf of roger akanji <roger...@gmail.com>
Date: Saturday, 20. April 2024 at 10.45
To: lav...@googlegroups.com <lav...@googlegroups.com>
Subject: RE: Lavaan error

--

You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages