indProd function does not work

200 views
Skip to first unread message

walkywalky

unread,
Aug 23, 2019, 3:46:40 PM8/23/19
to lavaan
Hi all,

I want to include an interaction term in my structural equation model defined to check whether car use moderates the relation between effort expectancy and intention to use

Effort expectancy is composed of three observed indicators, car use is an observed single item indicator 


When I run the IndProd function I get the following error message:

dataset <- indProd(Datensatz_neu.sav, var1 = c("V2_EE1", "V2_EE2","V2_EE3" ), var2 = c("CarUse"))
Error in indProd(Datensatz_neu.sav, var1 = c("V2_EE1", "V2_EE2", "V2_EE3"),  : 
  If the match-paired approach is used, the number of variables in all sets must be equal.

I assume that CarUse also has to be measured by three indicators too?

What am I doing wrong?

Second, after computing the interaction term, I can simply include it in my SEM model below?

Thanks a lot


mod.PE <-' PE =~ V2_PE1 + V2_PE2 
EE =~ V2_EE1 + V2_EE2 + V2_EE3 
SI =~ V2_SI1 + V2_SI2 + V2_SI3
BI =~ V2_BI1 + V2_BI2 + V2_BI3
HM =~ V2_HM1 + V2_HM2 + V2_HM3
FC =~ V2_FC1 + V2_FC2 + V2_FC4 
BI ~ PE + EE + SI + FC + HM + CarUse + PublicTransportUse + TechAcceptance + NoInteractions + NoUses + EE 
PE ~ FC + EE + HM + SI + CarUse + PublicTransportUse + TechAcceptance + NoInteractions + NoUses 
EE ~ FC + SI + HM + CarUse + PublicTransportUse + TechAcceptance + NoInteractions + NoUses 
HM ~ FC + SI + CarUse + PublicTransportUse + TechAcceptance + NoInteractions + NoUses 
FC ~ SI + CarUse + PublicTransportUse + TechAcceptance + NoInteractions + NoUses 
SI ~ TechAcceptance
'
fit.PE <- lavaan::cfa(mod.PE,
data = Datensatz_neu.sav,
missing="FIML",
estimator = "ML")
summary(fit.PE, standardized=TRUE, fit.measures=TRUE, rsquare = TRUE)

Edward Rigdon

unread,
Aug 23, 2019, 5:52:13 PM8/23/19
to lav...@googlegroups.com
You don't have to use the matched pair option. The default is match=T, so add the option match=F.


--
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/d5aaac7e-f8ed-47dd-a444-ceec2c51551a%40googlegroups.com.

Sina Nordhoff

unread,
Aug 23, 2019, 8:12:00 PM8/23/19
to lav...@googlegroups.com
Thanks a lot for the quick response. It is very much appreciated! 

When I now specify the interaction term as follows,
dataset <- indProd(Datensatz_neu.sav, var1 = c("V2_EE1", "V2_EE2","V2_EE3" ), var2 = c("CarUse"), match = F)

I get this error message:

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: dataset


I just added dataset now in my model along with the IV and M as predictors of the DV

Do you have an idea what went wrong here?

Thank you!



Edward Rigdon

unread,
Aug 23, 2019, 10:27:25 PM8/23/19
to lav...@googlegroups.com
Sina--
Is that a semTools error or a lavaan error?

I notice that you did not provide labels for the new variables that indProd() creates. Are you identifying them correctly in your lavaan syntax? The message suggests that observedvariablesare not labeled correctly. What do 
summary(Datensatz_neu.sav)
and
summary(dataset)
show?
If either variable used in a product is missing for a given case, then the product variable will also be missing. If the original variables have many missing values, then the product variables will have many, many missing values. But I do notthink this error relates to missing values--Ithink the function canot find the variables it is looking for.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Edward Rigdon

unread,
Aug 24, 2019, 11:31:31 AM8/24/19
to lav...@googlegroups.com
No, the reports are not the same. "dataset" includes 3 new variables:
V2_EE1.CarUse      V2_EE2.CarUse      V2_EE3.CarUse 
which are not listed for the original data set. Soit looks like indProd worked. (If you don't specifically provide variable names for the product terms, indProd does the best it can.

So I would guess that your lavaan model syntax did not use the correct names for the 3 new variables. Remember that R is case sensitive always. If you are off by one letter being incorrectly lowercase or uppercase, R tells you the variable is not present.

On Sat, Aug 24, 2019 at 4:16 AM Sina Nordhoff <sina.n...@gmail.com> wrote:
Hi Edward,

thanks for your quick response.

It is a lavaan error. 

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: dataset

Summary(dataset) and summary(Datensatz_neu.sav) show exactly the same. 

I guess this can't be right. 

There are only few missing values. 

Thanks a lot. 

 summary(Datensatz_neu.sav)
   Result_Id           Location  SurveyedDate         StartTime     SurveyDuration_Time SurveyDuration_Decimal NoInteractions 
 Min.   :11961183   Min.   :3   Min.   :1.367e+10   Min.   : 4866   Min.   :-2838       Min.   :-47.300        Min.   :1.000  
 1st Qu.:12072982   1st Qu.:3   1st Qu.:1.367e+10   1st Qu.:41799   1st Qu.:   82       1st Qu.:  1.367        1st Qu.:2.000  
 Median :12259839   Median :3   Median :1.367e+10   Median :45144   Median :  112       Median :  1.867        Median :3.000  
 Mean   :12215685   Mean   :3   Mean   :1.367e+10   Mean   :49092   Mean   :  307       Mean   :  5.117        Mean   :3.638  
 3rd Qu.:12325644   3rd Qu.:3   3rd Qu.:1.367e+10   3rd Qu.:50740   3rd Qu.:  205       3rd Qu.:  3.417        3rd Qu.:5.000  
 Max.   :12402808   Max.   :3   Max.   :1.368e+10   Max.   :80046   Max.   :32034       Max.   :533.900        Max.   :6.000  
                                                                                                                              
     NoUses          Gender           Age          AgeCategory        CarUse       CarUseCategory  PublicTransportUse
 Min.   :1.000   Min.   :0.000   Min.   : 9.177   Min.   :1.000   Min.   : 0.000   Min.   :1.000   Min.   : 0.000    
 1st Qu.:1.000   1st Qu.:0.000   1st Qu.:25.896   1st Qu.:4.000   1st Qu.: 2.000   1st Qu.:1.000   1st Qu.: 0.000    
 Median :2.000   Median :1.000   Median :33.426   Median :4.000   Median : 4.000   Median :2.000   Median : 1.000    
 Mean   :2.225   Mean   :0.546   Mean   :33.353   Mean   :4.241   Mean   : 3.917   Mean   :1.981   Mean   : 2.051    
 3rd Qu.:3.000   3rd Qu.:1.000   3rd Qu.:39.589   3rd Qu.:5.000   3rd Qu.: 7.000   3rd Qu.:3.000   3rd Qu.: 3.000    
 Max.   :6.000   Max.   :1.000   Max.   :65.829   Max.   :8.000   Max.   :22.000   Max.   :3.000   Max.   :85.000    
                                                                                                   NA's   :2         
 PublicTransportUseCategory TechAcceptance     V2_PE1          V2_PE2          V2_PE3          V2_EE1          V2_EE2     
 Min.   :1.000              Min.   :1.0    Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:1.000              1st Qu.:1.0    1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:4.000  
 Median :1.000              Median :2.0    Median :4.000   Median :4.000   Median :3.000   Median :4.000   Median :4.000  
 Mean   :1.367              Mean   :1.8    Mean   :3.673   Mean   :3.562   Mean   :3.267   Mean   :3.883   Mean   :3.921  
 3rd Qu.:2.000              3rd Qu.:2.0    3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :3.000              Max.   :3.0    Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
 NA's   :2                                                                                                                
     V2_EE3          V2_SI1          V2_SI2          V2_SI3          V2_SI4          V2_FC1          V2_FC2          V2_FC3     
 Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:4.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:3.000  
 Median :4.000   Median :3.000   Median :3.000   Median :3.000   Median :4.000   Median :4.000   Median :4.000   Median :4.000  
 Mean   :3.965   Mean   :3.403   Mean   :3.356   Mean   :3.365   Mean   :3.816   Mean   :3.905   Mean   :3.917   Mean   :3.695  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                                                                                
     V2_FC4          V2_HM1          V2_HM2          V2_HM3          V2_BI1          V2_BI2         V2_BI3          V2_EE1.c.V1     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :2.000   Min.   :1.00   Min.   :1.000   Min.   :-2.8825397  
 1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.00   1st Qu.:3.000   1st Qu.:-0.8825397  
 Median :4.000   Median :4.000   Median :4.000   Median :4.000   Median :4.000   Median :4.00   Median :4.000   Median : 0.1174603  
 Mean   :3.886   Mean   :3.803   Mean   :3.898   Mean   :3.749   Mean   :3.781   Mean   :3.73   Mean   :3.717   Mean   : 0.0000000  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.00   3rd Qu.:4.000   3rd Qu.: 0.1174603  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.00   Max.   :5.000   Max.   : 1.1174603  
                                                                                                                                    
     V2_EE2.c.V1          V2_EE3.c.V1          V2_BI2.c.V1          V2_BI1.c.V1          V2_BI3.c.V1         CarUse.c.V1    
 Min.   :-2.9206349   Min.   :-1.9650794   Min.   :-2.7301587   Min.   :-1.7809524   Min.   :-2.7174603   Min.   :-3.91746  
 1st Qu.: 0.0793651   1st Qu.: 0.0349206   1st Qu.:-0.7301587   1st Qu.:-0.7809524   1st Qu.:-0.7174603   1st Qu.:-1.91746  
 Median : 0.0793651   Median : 0.0349206   Median : 0.2698413   Median : 0.2190476   Median : 0.2825397   Median : 0.08254  
 Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.00000  
 3rd Qu.: 0.0793651   3rd Qu.: 0.0349206   3rd Qu.: 0.2698413   3rd Qu.: 0.2190476   3rd Qu.: 0.2825397   3rd Qu.: 3.08254  
 Max.   : 1.0793651   Max.   : 1.0349206   Max.   : 1.2698413   Max.   : 1.2190476   Max.   : 1.2825397   Max.   :18.08254  
                                                                                                                            
> summary(dataset)
   Result_Id           Location  SurveyedDate         StartTime     SurveyDuration_Time SurveyDuration_Decimal NoInteractions 
 Min.   :11961183   Min.   :3   Min.   :1.367e+10   Min.   : 4866   Min.   :-2838       Min.   :-47.300        Min.   :1.000  
 1st Qu.:12072982   1st Qu.:3   1st Qu.:1.367e+10   1st Qu.:41799   1st Qu.:   82       1st Qu.:  1.367        1st Qu.:2.000  
 Median :12259839   Median :3   Median :1.367e+10   Median :45144   Median :  112       Median :  1.867        Median :3.000  
 Mean   :12215685   Mean   :3   Mean   :1.367e+10   Mean   :49092   Mean   :  307       Mean   :  5.117        Mean   :3.638  
 3rd Qu.:12325644   3rd Qu.:3   3rd Qu.:1.367e+10   3rd Qu.:50740   3rd Qu.:  205       3rd Qu.:  3.417        3rd Qu.:5.000  
 Max.   :12402808   Max.   :3   Max.   :1.368e+10   Max.   :80046   Max.   :32034       Max.   :533.900        Max.   :6.000  
                                                                                                                              
     NoUses          Gender           Age          AgeCategory        CarUse       CarUseCategory  PublicTransportUse
 Min.   :1.000   Min.   :0.000   Min.   : 9.177   Min.   :1.000   Min.   : 0.000   Min.   :1.000   Min.   : 0.000    
 1st Qu.:1.000   1st Qu.:0.000   1st Qu.:25.896   1st Qu.:4.000   1st Qu.: 2.000   1st Qu.:1.000   1st Qu.: 0.000    
 Median :2.000   Median :1.000   Median :33.426   Median :4.000   Median : 4.000   Median :2.000   Median : 1.000    
 Mean   :2.225   Mean   :0.546   Mean   :33.353   Mean   :4.241   Mean   : 3.917   Mean   :1.981   Mean   : 2.051    
 3rd Qu.:3.000   3rd Qu.:1.000   3rd Qu.:39.589   3rd Qu.:5.000   3rd Qu.: 7.000   3rd Qu.:3.000   3rd Qu.: 3.000    
 Max.   :6.000   Max.   :1.000   Max.   :65.829   Max.   :8.000   Max.   :22.000   Max.   :3.000   Max.   :85.000    
                                                                                                   NA's   :2         
 PublicTransportUseCategory TechAcceptance     V2_PE1          V2_PE2          V2_PE3          V2_EE1          V2_EE2     
 Min.   :1.000              Min.   :1.0    Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:1.000              1st Qu.:1.0    1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:4.000  
 Median :1.000              Median :2.0    Median :4.000   Median :4.000   Median :3.000   Median :4.000   Median :4.000  
 Mean   :1.367              Mean   :1.8    Mean   :3.673   Mean   :3.562   Mean   :3.267   Mean   :3.883   Mean   :3.921  
 3rd Qu.:2.000              3rd Qu.:2.0    3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :3.000              Max.   :3.0    Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
 NA's   :2                                                                                                                
     V2_EE3          V2_SI1          V2_SI2          V2_SI3          V2_SI4          V2_FC1          V2_FC2          V2_FC3     
 Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:4.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:3.000  
 Median :4.000   Median :3.000   Median :3.000   Median :3.000   Median :4.000   Median :4.000   Median :4.000   Median :4.000  
 Mean   :3.965   Mean   :3.403   Mean   :3.356   Mean   :3.365   Mean   :3.816   Mean   :3.905   Mean   :3.917   Mean   :3.695  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                                                                                
     V2_FC4          V2_HM1          V2_HM2          V2_HM3          V2_BI1          V2_BI2         V2_BI3          V2_EE1.c.V1     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :2.000   Min.   :1.00   Min.   :1.000   Min.   :-2.8825397  
 1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.00   1st Qu.:3.000   1st Qu.:-0.8825397  
 Median :4.000   Median :4.000   Median :4.000   Median :4.000   Median :4.000   Median :4.00   Median :4.000   Median : 0.1174603  
 Mean   :3.886   Mean   :3.803   Mean   :3.898   Mean   :3.749   Mean   :3.781   Mean   :3.73   Mean   :3.717   Mean   : 0.0000000  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.00   3rd Qu.:4.000   3rd Qu.: 0.1174603  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.00   Max.   :5.000   Max.   : 1.1174603  
                                                                                                                                    
     V2_EE2.c.V1          V2_EE3.c.V1          V2_BI2.c.V1          V2_BI1.c.V1          V2_BI3.c.V1         CarUse.c.V1    
 Min.   :-2.9206349   Min.   :-1.9650794   Min.   :-2.7301587   Min.   :-1.7809524   Min.   :-2.7174603   Min.   :-3.91746  
 1st Qu.: 0.0793651   1st Qu.: 0.0349206   1st Qu.:-0.7301587   1st Qu.:-0.7809524   1st Qu.:-0.7174603   1st Qu.:-1.91746  
 Median : 0.0793651   Median : 0.0349206   Median : 0.2698413   Median : 0.2190476   Median : 0.2825397   Median : 0.08254  
 Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.0000000   Mean   : 0.00000  
 3rd Qu.: 0.0793651   3rd Qu.: 0.0349206   3rd Qu.: 0.2698413   3rd Qu.: 0.2190476   3rd Qu.: 0.2825397   3rd Qu.: 3.08254  
 Max.   : 1.0793651   Max.   : 1.0349206   Max.   : 1.2698413   Max.   : 1.2190476   Max.   : 1.2825397   Max.   :18.08254  
                                                                                                                            
 V2_EE1.CarUse      V2_EE2.CarUse      V2_EE3.CarUse      
 Min.   :-15.6790   Min.   :-9.78372   Min.   :-8.060902  
 1st Qu.: -0.1806   1st Qu.:-0.33293   1st Qu.:-0.175188  
 Median :  0.2892   Median : 0.06389   Median :-0.000585  
 Mean   :  0.0000   Mean   : 0.00000   Mean   : 0.000000  
 3rd Qu.:  0.6416   3rd Qu.: 0.22262   3rd Qu.: 0.104177  
 Max.   : 11.5718   Max.   :11.41945   Max.   : 7.659733  

--
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.

Edward Rigdon

unread,
Aug 24, 2019, 11:33:10 AM8/24/19
to lav...@googlegroups.com
You need to put the result into an object, as you have been doing:

data.out <- indProd(Datensatz_neu.sav, var1 = c("V2_EE1", "V2_EE2","V2_EE3" ), var2 = c("CarUse"), match = F)


On Sat, Aug 24, 2019 at 4:20 AM Sina Nordhoff <sina.n...@gmail.com> wrote:
Btw when I only run the indprod function

indProd(Datensatz_neu.sav, var1 = c("V2_EE1", "V2_EE2","V2_EE3" ), var2 = c("CarUse"), match = F)

I get an overview of all rows (n observations) and columns (variables) in my sample.
Thus, I suspect that the way the function is written is not recognised by the system?

Am Sa., 24. Aug. 2019 um 10:16 Uhr schrieb Sina Nordhoff <sina.n...@gmail.com>:
Hi Edward,

thanks for your quick response.

It is a lavaan error. 

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: dataset

--
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