Reputation: 13
I'm having a problem with the sem() function in the 'lavaan' package in R and I was hoping someone here might have thoughts on how I can fix it.
My model is set up as follows:
mod <- 'trait ~ historical1 + historical 2 + contemporary1 + contemporary2
abundance ~ contemporary1 + contemporary2 + trait
bacteria ~ historical1 + historical 2 + contemporary1 + contemporary2 + trait + abundance'
My exogenous variables (historical1, historical 2, contemporary1, and contemporary2) are categorical variables that I manipulated for my experiment with two possible levels. I'm treating those as dummy variables with 0's and 1's. Everything else is a numeric measurement.
I have three different variables for "bacteria" that I'm trying to look at separately. When I use the first (bacteria1), the model runs smoothly.
> modA<-'trait ~ historical1 + historical 2 + contemporary1 + contemporary2
+ abundance ~ contemporary1 + contemporary2 + trait
+ bacteria1 ~ historical1 + historical 2 + contemporary1 + contemporary2 + trait + abundance'
> fit<-sem(modA,data=data,meanstructure=T)
Warning message:
In lav_data_full(data = data, group = group, group.label = group.label, :
lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
> fitmeasures(fit)
fmin chisq df pvalue
0.154 24.028 2.000 0.000
baseline.chisq baseline.df baseline.pvalue cfi
114.474 15.000 0.000 0.779
tli nnfi rfi nfi
-0.661 -0.661 1.000 0.790
pnfi ifi rni logl
0.105 0.804 0.779 -1605.897
unrestricted.logl npar aic bic
-1593.883 19.000 3249.794 3294.572
ntotal bic2 rmsea rmsea.ci.lower
78.000 3234.670 0.376 0.251
rmsea.ci.upper rmsea.pvalue rmr rmr_nomean
0.517 0.000 40.988 45.826
srmr srmr_bentler srmr_bentler_nomean srmr_bollen
0.080 0.080 0.089 0.080
srmr_bollen_nomean srmr_mplus srmr_mplus_nomean cn_05
0.089 0.080 0.089 20.450
cn_01 gfi agfi pgfi
30.899 0.997 0.946 0.057
mfi ecvi
0.868 NA
> summary(fit)
lavaan (0.5-16) converged normally after 145 iterations
Number of observations 78
Estimator ML
Minimum Function Test Statistic 24.028
Degrees of freedom 2
P-value (Chi-square) 0.000
Parameter estimates:
Information Expected
Standard Errors Standard
Estimate Std.err Z-value P(>|z|)
Regressions:
trait ~
historical1 8.722 39.607 0.220 0.826
historical2 89.529 39.607 2.260 0.024
contemporary1 6.737 39.621 0.170 0.865
contemporary2 411.556 39.621 10.387 0.000
abundance ~
contemporary1 -36.390 81.354 -0.447 0.655
contemporary2 424.993 123.301 3.447 0.001
trait -0.251 0.225 -1.116 0.265
bacteria1 ~
historical1 -2.342 2.455 -0.954 0.340
historical2 -2.142 2.533 -0.845 0.398
contemporary1 -0.268 2.459 -0.109 0.913
contemporary2 3.410 4.059 0.840 0.401
trait 0.000 0.007 0.031 0.975
abundance -0.008 0.003 -2.451 0.014
Intercepts:
trait 1299.789 44.285 29.351 0.000
abundance 1438.077 311.643 4.614 0.000
bacteria1 26.805 10.717 2.501 0.012
Variances:
trait 30569.613 4895.056
abundance 128842.663 20631.338
bacteria1 117.383 18.796
However, when I use either of the other two bacterial variables, I receive a warning "could not compute standard errors!".
> modB<-'trait ~ historical1 + historical 2 + contemporary1 + contemporary2
+ abundance ~ contemporary1 + contemporary2 + trait
+ bacteria2 ~ historical1 + historical 2 + contemporary1 + contemporary2 + trait + abundance'
> fit<-sem(modB,data=data,meanstructure=T)
Warning messages:
1: In lav_data_full(data = data, group = group, group.label = group.label, :
lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
2: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, :
lavaan WARNING: could not compute standard errors!
> fitmeasures(fit)
fmin chisq df pvalue baseline.chisq
0.154 24.028 2.000 0.000 126.602
baseline.df baseline.pvalue cfi tli nnfi
15.000 0.000 0.803 -0.480 -0.480
rfi nfi pnfi ifi rni
1.000 0.810 0.108 0.823 0.803
logl unrestricted.logl npar aic bic
-1277.674 -1265.660 19.000 2593.348 2638.126
ntotal bic2 rmsea rmsea.ci.lower rmsea.ci.upper
78.000 2578.224 0.376 0.251 0.517
rmsea.pvalue rmr rmr_nomean srmr srmr_bentler
0.000 15.075 16.855 0.078 0.078
srmr_bentler_nomean srmr_bollen srmr_bollen_nomean srmr_mplus srmr_mplus_nomean
0.087 0.078 0.087 0.078 0.087
cn_05 cn_01 gfi agfi pgfi
20.450 30.899 0.997 0.945 0.057
mfi ecvi
0.868 NA
> summary(fit)
lavaan (0.5-16) converged normally after 115 iterations
Number of observations 78
Estimator ML
Minimum Function Test Statistic 24.028
Degrees of freedom 2
P-value (Chi-square) 0.000
Parameter estimates:
Information Expected
Standard Errors Standard
Estimate Std.err Z-value P(>|z|)
Regressions:
trait ~
historical1 8.723
historical2 89.530
contemporary1 6.737
contemporary2 411.556
abundance ~
contemporary1 -36.390
contemporary2 424.993
trait -0.251
bacteria2 ~
historical1 0.020
historical2 -0.038
contemporary1 -0.075
contemporary2 -0.071
trait -0.000
abundance -0.000
Intercepts:
trait 1299.788
abundance 1438.077
bacteria2 0.367
Variances:
trait 30569.606
abundance 128842.668
bacteria2 0.026
> modC<-'trait ~ historical1 + historical 2 + contemporary1 + contemporary2
+ abundance ~ contemporary1 + contemporary2 + trait
+ bacteria3 ~ historical1 + historical 2 + contemporary1 + contemporary2 + trait + abundance'
> fit<-sem(modC,data=data,meanstructure=T)
Warning messages:
1: In lav_data_full(data = data, group = group, group.label = group.label, :
lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
2: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, :
lavaan WARNING: could not compute standard errors!
> fitmeasures(fit)
fmin chisq df pvalue baseline.chisq
0.154 24.028 2.000 0.000 112.875
baseline.df baseline.pvalue cfi tli nnfi
15.000 0.000 0.775 -0.688 -0.688
rfi nfi pnfi ifi rni
1.000 0.787 0.105 0.801 0.775
logl unrestricted.logl npar aic bic
-1414.328 -1402.314 19.000 2866.656 2911.434
ntotal bic2 rmsea rmsea.ci.lower rmsea.ci.upper
78.000 2851.532 0.376 0.251 0.517
rmsea.pvalue rmr rmr_nomean srmr srmr_bentler
0.000 15.160 16.949 0.077 0.077
srmr_bentler_nomean srmr_bollen srmr_bollen_nomean srmr_mplus srmr_mplus_nomean
0.086 0.079 0.086 0.079 0.086
cn_05 cn_01 gfi agfi pgfi
20.450 30.899 1.000 0.991 0.057
mfi ecvi
0.868 NA
> summary(fit)
lavaan (0.5-16) converged normally after 119 iterations
Number of observations 78
Estimator ML
Minimum Function Test Statistic 24.028
Degrees of freedom 2
P-value (Chi-square) 0.000
Parameter estimates:
Information Expected
Standard Errors Standard
Estimate Std.err Z-value P(>|z|)
Regressions:
trait ~
historical1 8.723
historical2 89.530
contemporary1 6.737
contemporary2 411.556
abundance ~
contemporary1 -36.390
contemporary2 424.993
trait -0.251
bacteria3 ~
historical1 0.098
historical2 0.095
contemporary1 -0.102
contemporary2 0.204
trait -0.000
abundance -0.000
Intercepts:
trait 1299.788
abundance 1438.077
bacteria3 19.984
Variances:
trait 30569.585
abundance 128842.707
bacteria3 0.864
I did some research about this warning but nothing seems to help. Does the model just fit really poorly with the other two variables?
Any ideas? Thank you in advance.
> str(data)
'data.frame': 78 obs. of 10 variables:
$ X : int 1 2 3 4 5 6 7 8 9 10 ...
$ historical1 : int 0 0 1 1 0 0 1 1 1 1 ...
$ historical2 : int 0 1 1 0 0 1 1 0 0 1 ...
$ contemporary1: int 0 1 0 1 0 0 1 0 1 0 ...
$ contemporary2: int 1 1 0 1 0 0 1 0 1 0 ...
$ trait : num 2202 1935 1371 1978 1130 ...
$ abundance : num 1011 1757 1347 1578 1674 ...
$ bacteria1 : num 30.39 6.69 7.58 6.05 8.47 ...
$ bacteria2 : num -0.0356 0.0304 0.1344 -0.0497 0.265 ...
$ bacteria3 : num 19.4 18.1 20 18.1 18.4 ...
Erica
Upvotes: 1
Views: 5022
Reputation: 56
In case anyone was wondering, I did eventually figure this one out. There was apparently a scaling issue between the variables in the model. It can be fixed using the scale() function.
data[,c(19,21)]<-scale(data[,c(19,21)],center=FALSE,scale=c(100000000,0.01))
Where column 19 corresponds to the 'bacteria2' variable and column 21 corresponds to my 'bacteria3' variable. The bacteria2 variable was roughly 10^7 while bacteria3 was roughly 10^-2. Rescaling them to 10^1 or 10^2 fixes both warnings produced in the code above and sem() successfully calculates standard errors.
Upvotes: 3