resid() method for sem() not working after 0.5-16 upgrade?

192 views
Skip to first unread message

Antti Simola

unread,
Apr 5, 2014, 10:36:34 AM4/5/14
to lav...@googlegroups.com
I just updated to 0.5-16 version of lavaan. However, my code that worked perfectly well before produces now an error when I try to extract residuals from a sem model.

E.g.:

sem.model <- sem()

resid(sem.model, "obs")

Error in: VETA[[g]] %*% t(LAMBDA[[g]]) : non-conformable arguments

Does anyone have any idea what's going on?

Cheers,

Antti

Antti Simola

unread,
Apr 6, 2014, 2:26:44 AM4/6/14
to lav...@googlegroups.com
Just an extra note: resid without "obs" works as it should.

yrosseel

unread,
Apr 14, 2014, 11:31:44 AM4/14/14
to lav...@googlegroups.com
No. Can you show us your full syntax?

example(sem)
resid(fit, "obs")

works, so something else must be going on.

Yves.

Antti Simola

unread,
Apr 17, 2014, 3:30:44 AM4/17/14
to lav...@googlegroups.com
Here is the  code:

# Retrieving needed packages

require(lavaan)

# Retrieving the data

load("example_data.Rdata")

# Structural equations model

sem.model <- 'y.1 ~ c(b1a,b1b,b1c,b1d,b1e,b1f)*x.1 + y2005 + y2006 + y2007 + y2009
              y.2 ~ c(b21a,b21b,b21c,b21d,b21e,b21f)*x.21 +
                    c(b22a,b22b,b22c,b22d,b22e,b22f)*x.22 + y2005 + y2006 + y2007 + y2009
              y.3 ~ c(b31a,b31b,b31c,b31d,b31e,b31f)*x.21 +
                    c(b32a,b32b,b32c,b32d,b32e,b32f)*x.32 + y2005 + y2006 + y2007 + y2009

              b21a == b31a
              b21b == b31b
              b21c == b31c
              b21d == b31d
              b21e == b31e
              b21f == b31f

              b21a == -b22a/(1-b1a)
              b21b == -b22b/(1-b1b)
              b21c == -b22c/(1-b1c)
              b21d == -b22d/(1-b1d)
              b21e == -b22e/(1-b1e)
              b21f == -b22f/(1-b1f)

              b22a == b32a
              b22b == b32b
              b22c == b32c
              b22d == b32d
              b22e == b32e
              b22f == b32f'

# First CES
CES.1 <- sem(sem.model, data=data.1, group = "ts2", start = "Mplus")


# Extraction of the results
 
CES.est.1 <- parameterEstimates(CES.1)

sigma.upper.1 <- subset(CES.est.1, lhs == "y.1" & rhs == "x.1")
sigma.lower.1 <- subset(CES.est.1, lhs == "y.2" & rhs == "x.22")
sigma.lower.1$est <- 1 - sigma.lower.1$est

alfa1.1 <- subset(CES.est.1, lhs == "y.1" & op == "~1")
alfa2.1 <- subset(CES.est.1, lhs == "y.2" & op == "~1")
alfa3.1 <- subset(CES.est.1, lhs == "y.3" & op == "~1")

resid.1 <- NULL
for(i in 1:6){
    resid.1[[i]] <- as.data.frame(resid(CES.1, "obs")[i])
}

sysresid.1 <- NULL
for(i in 1:3){
    sysresid.1[[i]] <- c(resid.1[[1]][,i],resid.1[[2]][,i],resid.1[[3]][,i],
                         resid.1[[4]][,i],resid.1[[5]][,i],resid.1[[6]][,i])
}

I will send you some of the data privately so that you can check it.

yrosseel

unread,
Apr 17, 2014, 3:45:56 AM4/17/14
to lav...@googlegroups.com
Confirmed. This is the same bug affecting predict() (see
http://lavaan.ugent.be/history/dot5.html) and only happens if you have
exogenous covariates in the model (as in your case).

Will be fixed ASAP.

Yves.

Antti Simola

unread,
Apr 17, 2014, 7:45:17 AM4/17/14
to lav...@googlegroups.com
Thank you Yves for the reply!

Antti Simola

unread,
May 30, 2014, 2:55:03 AM5/30/14
to lav...@googlegroups.com
Have you made any progress with this predict issue?

Antti

yrosseel

unread,
Jun 2, 2014, 4:20:16 AM6/2/14
to lav...@googlegroups.com
On 05/30/2014 08:55 AM, Antti Simola wrote:
> Have you made any progress with this predict issue?

working on it; almost done.

Yves.

jesse miller

unread,
Jul 24, 2014, 11:37:11 AM7/24/14
to lav...@googlegroups.com

Hi Yves,
I am also having the same issue with residuals in 0.5-16. Just wondering if there's been any more progress on fixing it...

thanks,
Jesse

Yves Rosseel

unread,
Jul 26, 2014, 11:24:10 AM7/26/14
to lav...@googlegroups.com
On 07/24/2014 05:37 PM, jesse miller wrote:
>
> Hi Yves,
> I am also having the same issue with residuals in 0.5-16. Just wondering
> if there's been any more progress on fixing it...

This should be fixed in the dev version (0.5-17). See

http://lavaan.ugent.be/development.html

how to install it and try it out.

Yves.

jesse miller

unread,
Jul 28, 2014, 6:05:56 PM7/28/14
to lav...@googlegroups.com


Ah, yes, it works! Thanks very much and have a great vacation. 

Antti Simola

unread,
Jul 29, 2014, 2:41:47 AM7/29/14
to lav...@googlegroups.com
This is good news for me as well. Thank you Yves! Is the official 0.5-17 going to be available at CRAN anytime soon?


--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/g-epNMjA5zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Antti Simola

unread,
Oct 1, 2014, 1:44:08 PM10/1/14
to lav...@googlegroups.com
I just upgraded to new 0.5-17 version and the same error returned although it was solved in an earlier development version. I also tried the new development version 0.5-18 but to no avail. Could this be fixed again any time soon?

Cheers,

Antti 

yrosseel

unread,
Oct 1, 2014, 2:28:14 PM10/1/14
to lav...@googlegroups.com
On 10/01/2014 07:44 PM, Antti Simola wrote:
> I just upgraded to new 0.5-17 version and the same error returned
> although it was solved in an earlier development version

True. Unfortunately, it is one of the 'known issues' in 0.5-17.

> the new development version 0.5-18 but to no avail. Could this be fixed
> again any time soon?

I don't do 'soon' anymore. But, sure, it is on my list.

Yves.

Antti Simola

unread,
Oct 2, 2014, 3:09:42 AM10/2/14
to lav...@googlegroups.com
All right. Thank you so much for all the work with this package. That problem mainly bothers me while I calculate system R-squared values. No big deal as there's other ways to compare models as well. I'm waiting forward the forthcoming lavaan releases, but meanwhile I try to remain with that development version that got it fixed (I did the upgrade with my home computer and workplace machines still have that earlier development version). Is there a way to download some specific development version from your repo if I happen to lose that development version somehow?

Cheers,

Antti

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/g-epNMjA5zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.

Yves Rosseel

unread,
Oct 2, 2014, 3:18:45 AM10/2/14
to lav...@googlegroups.com
> Is there a way to download some specific
> development version from your repo if I happen to lose that development
> version somehow?

Not directly. You can download the full git repository from github, and
then 'roll back' to the point where the change(s) were made...

Yves.

yros...@gmail.com

unread,
Oct 8, 2014, 5:07:06 AM10/8/14
to lav...@googlegroups.com

Another way around this (it would seem) is to explicitly add 'meanstructure = TRUE' to the fitting function.

Yves.

yros...@gmail.com

unread,
Oct 10, 2014, 7:51:42 AM10/10/14
to lav...@googlegroups.com
This should be fixed (again) in dev 0.5-18.733 and higher.

Yves.

Antti Simola

unread,
Oct 15, 2014, 9:37:52 AM10/15/14
to lav...@googlegroups.com

Thank you Yves! Much appreciated!

On Oct 10, 2014 2:51 PM, <yros...@gmail.com> wrote:
This should be fixed (again) in dev 0.5-18.733 and higher.

Yves.

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/g-epNMjA5zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages