covariance matrix, missing variables

24 views
Skip to first unread message

ju.lis.br...@gmail.com

unread,
Nov 6, 2018, 6:55:40 AM11/6/18
to lavaan
Hi,

I fitted two models using sem(). Both models run  perfectly fine and summary() returns estimates for all variables. Using lavInspect(model1, what="cov.ov") I get a covariance matrix from model 1 in which the exogenous categorical variables landscapeforest.fragment, landscapeisland, sexM and season2014.2015 (all are dummy coded) are missing. Other categorical variables (supertypes3x1, etc.) do however appear in the covariance matrix. In model 2 the exogenous variables landscapeforest.fragment and landscapeisland are present in the covariance matrix. 

Is there something wrong in my script or is there another reason for this? See below for the script:

Thank you very much for your help!

Julian

data2[,c("tryp.inf0",
        "n1.2",
        "n15.29",
        "n23",
        "hepaci.inf",
        "picorna",
        "picobirna",
        "supertype3x1",
        "supertype5x1",
        "supertype6x1",
        "supertype9x1",
        "supertype10x1")] <-
  lapply(data2[,c("tryp.inf0",
                 "n1.2",
                 "n15.29",
                 "n23",
                 "hepaci.inf",
                 "picorna",
                 "picobirna",
                 "supertype3x1",
                 "supertype5x1",
                 "supertype6x1",
                 "supertype9x1",
                 "supertype10x1")], ordered)


model1  = "#regressions
#direct effects
hepaci.inf ~ landscapeforest.fragment + landscapeisland + sexM + supertype1x1

picobirna ~ season2014.2015
picorna ~ a*juliDensity + s*season2014.2015 + t*supertype10x1 + u*supertype3x1 + v*supertype5x1 + w*supertype9x1

tryp.inf0 ~ b*marsu.density + landscapeforest.fragment + mean_pdist

n1.2 ~ d*SimpsonInv2018ed.in + c*juliDensity + landscapeisland

n15.29 ~ f*SimpsonInv2018ed.in + landscapeisland + e*juliDensity + x*supertype6x1

n23 ~ h*SimpsonInv2018ed.in + g*juliDensity 

SimpsonInv2018ed.in ~ k*landscapeforest.fragment

juliDensity ~ i*landscapeisland

marsu.density ~ j*landscapeforest.fragment + season2014.2015

supertype3x1 ~ l*season2014.2015 + m*landscapeisland
supertype5x1 ~ n*landscapeisland
supertype6x1 ~ o*landscapeforest.fragment + p*landscapeisland
supertype9x1 ~ q*landscapeisland
supertype10x1 ~ r*season2014.2015


#indirect effects 
#landscapeisland~picorna via juliDensity
ai := a*i
#landscapeforest.fragment~tryp.inf0 via marsu.density
bj := b*j
#landscapeforest.fragment/landscapeisland~n1.2 via juliDensity,SimpsonInv2018ed.in
ci := c*i
dk := d*k
#landscapeforest.fragment/island~n15.29 via juliDensity, SimpsonInv2018ed.in
ei := e*i
fk := f*k  
#landscapeisland/forest.fragment~n23 via juliDensity, SimpsonInv2018ed.in
gi := g*i
hk := h*k
#season2014.2015/landscapeisland~picorna via st3
sl := s*l
um := u*m
#landscapeisland~picorna via st5
vn := v*n
#landscapeforest.fragment/landscapeisland~n15.29 via st6
xo := x*o
xp := x*p
#landscapeisland~picorna via st9
wq := w*q
#season2014.2015~picorna via st10
tr := t*r"

model1 = sem(model1, data2, estimator = "WLSMV")
lavInspect(model1, what = "cov.ov")


















hepaci.inf picobirna picorna tryp.inf0 n1.2 n15.29 n23 SimpsonInv juliDensity marsu.density supertype3x1  supertype5x1 supertype6x1 supertype9x1 supertype10x1
hepaci.inf 1.000













picobirna -0.305 1.000












picorna 0.000 0.185 1.367











tryp.inf0 -0.077 0.319 0.052 1.000










n122 0.071 -0.089 -0.200 -0.134 1.000









n15.29 0.065 0.082 0.287 0.166 0.196 1.066








n23 0.045 0.155 0.176 -0.030 0.162 -0.088 1.000







SimpsonInv 0.000 0.000 0.000 0.000 -0.198 -0.129 -0.122 0.176






juliDensity 0.000 0.000 1.148 0.000 0.718 1.358 -0.971 0.000 17.061





marsu.density 0.000 0.000 0.000 0.125 0.000 0.000 0.000 0.000 0.000 0.213




supertype3x1 0.000 0.000 0.192 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000



supertype5x1 0.000 0.000 0.185 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000


supertype6x1 0.000 0.000 0.000 0.000 0.000 0.258 0.000 0.000 0.000 0.000 0.000 0.000 1.000

supertype9x1 0.000 0.000 -0.329 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000
supertype10x1 0.000 0.000 0.433 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000



model 2 = "#regressions
#direct effects
multi.inf ~ landscapeforest.fragment + b*SimpsonInv2018ed.in + a*juliDensity 

SimpsonInv2018ed.in ~ d*landscapeforest.fragment

juliDensity ~ c*landscapeisland

#indirect effects
#landscapeisland~multi.inf via juliDensity
ac := a*c
#landscapeforest.fragment~multi.inf via SimpsonInv2018ed.in
bd := b*d"
 
sem(model2, data2, estimator = "MLM")

lavInspect(model2, what = "cov.ov")


multi.inf SimpsonInv juliDensity landscapeforest.fragment landscapeisland
multi.inf 1.149



SimpsonInv -0.218 0.399


juliDensity 1.587 -0.551 24.250

landscapeforest.fragment -0.178 0.196 -0.536 0.191
landscapeisland 0.142 -0.105 1.254 -0.103 0.240


Terrence Jorgensen

unread,
Nov 9, 2018, 5:29:17 AM11/9/18
to lavaan
In model 2 the exogenous variables landscapeforest.fragment and landscapeisland are present in the covariance matrix. 

Is there something wrong in my script or is there another reason for this?

You are using 2 different estimators, which may have different default settings for the fixed.x argument (see the ?lavOptions help page for a description, although it will not say what controls the default setting).  You can see what the options are:

lavInspect(model1, what = "options")$fixed.x
lavInspect
(model2, what = "options")$fixed.x

FYI, if they are exogenous, do NOT define the dummy codes as ordered.  They should be numeric dummy codes, and set fixed.x=TRUE to avoid making distributional assumptions about them (i.e., they don't have to be multivariate normal because their summary statistics are used instead of actually estimating their (co)variances).


Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages