error when 'outcome' variable is not continuous

202 views
Skip to first unread message

MD S

unread,
Jul 25, 2016, 11:03:50 AM7/25/16
to lavaan
Hi everyone,

As part of a current project I'm trying to use SEM to determine the effect of a latent variable.
All variables are continuous except for the 'outcome' variable.
When trying to run my model, assuming that everything (including outcome) is continuous, there are no problem.
However, I run into problems trying to account for the outcome variable type.

Here is the error message I get:

Error in X[[g]][, num.idx, drop = FALSE] : subscript out of bounds
In addition: Warning message:
In ov.names[[g]] %in% ov$name & ov$type == "numeric" :
  longer object length is not a multiple of shorter object length


I've already searched the forum here and found similar error messages, however seems like only the warning is known and not the error.
So I sat down and tried to recreate the issue in a small test scenario (see below).
Any insights on what's going on?

And as a more general question: Would there be a general trend if I'd assume the outcome to be continuous, i.e. will the model underestimate or overestimate the "goodness" of the model? Or is it so unpredictable that this cannot be stated?

Best wishes,
M

########################
library(lavaan)

# dataset
aa <- c(0,1,1,2,2,2,3,3,4)
bb <- c(0,1,6,2,3,1,4,2,5) # outcome variable
cc <- aa
dd <- aa
dat <- data.frame(aa=aa, bb=bb, cc=cc, dd=dd)

# 1
model.a <- '
lat =~ start(1.)*aa + cc
# regression model
bb ~ aa + dd
'

# 2
fit <- sem(model.a, data = dat, std.lv = TRUE, std.ov = TRUE, ordered=c('bb'))

Yves Rosseel

unread,
Jul 31, 2016, 4:51:43 PM7/31/16
to lav...@googlegroups.com
> Any insights on what's going on?

> # dataset
> aa <- c(0,1,1,2,2,2,3,3,4)
> bb <- c(0,1,6,2,3,1,4,2,5) # outcome variable
> cc <- aa
> dd <- aa
> dat <- data.frame(aa=aa, bb=bb, cc=cc, dd=dd)
>
> # 1
> model.a <- '
> lat =~ start(1.)*aa + cc
> # regression model
> bb ~ aa + dd
> '

The error message is very uninformative. I just never anticipated a
latent variable ('lat'), measured by two identical indicators ('aa' and
'cc').

In addition, why do you need std.ov = TRUE? Set this to FALSE, and avoid
using identical variables.

Yves.

MD S

unread,
Aug 1, 2016, 1:33:50 PM8/1/16
to lavaan
Thank you for your reply, Yves.
The reason why those were the same vectors was just because I was to lazy to define separate vectors. Apologies for that. I added the updated model at the bottom. The error message is still the same:

> fit <- sem(model.a, data = dat, std.lv = TRUE, std.ov = TRUE, ordered=c('bb'))

Error in X[[g]][, num.idx, drop = FALSE] : subscript out of bounds
In addition: Warning message:
In ov.names[[g]] %in% ov$name & ov$type == "numeric" :
  longer object length is not a multiple of shorter object length


If I change std.ov to False, as you suggested, I get a different error message:

> fit <- sem(model.a, data = dat, std.lv = TRUE, std.ov = FALSE, ordered=c('bb'))

Error in tmp[cbind(REP$row[idx], REP$col[idx])] <- lavpartable$free[idx] :
  NAs are not allowed in subscripted assignments


Same issue in my real dataset.
Unfortunately I'm not understanding where these error messages are coming from. Is there a way how I could get more detailed error descriptions?

Just for completeness: If I delete the ordered=c('bb') part, the error goes away and this warning shows up:
Warning message:
In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING: could not compute standard errors!
  lavaan NOTE: this may be a symptom that the model is not identified.


Thanks again for the help!
M

####

# 1) specify model
# 2) estimate the model
library(lavaan)

# load dataset

aa <- c(0,1,1,2,2,2,3,3,4)
bb <- c(0,1,6,2,3,1,4,2,5)
cc <- c(10,11.1,10.9,12.1,12.2,11.9,13.1,12.9,14)
dd <- c(5,6.3,5.7,7.9,7.2,7.3,7.8,8.3,9.1)

dat <- data.frame(aa=aa, bb=bb, cc=cc, dd=dd)

# 1
model.a <- '
lat =~ start(1.)*aa + cc
# regression model
bb ~ aa + dd + lat
'

# 2
fit <- sem(model.a, data = dat, std.lv = TRUE, std.ov = FALSE, ordered=c('bb'))
Reply all
Reply to author
Forward
0 new messages