Skip to content

Commit

Permalink
Merge pull request #398 from lucdw/master
Browse files Browse the repository at this point in the history
Allow autoregression if coeff. fixed to zero
  • Loading branch information
yrosseel authored Nov 27, 2024
2 parents 4e01549 + 80ad0c4 commit ab477a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions R/lav_syntax_parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -903,15 +903,6 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) {
footer = tl[2L]
)
}
# check for variable regressed on itself
if (formul1$elem.text[opi] == "~" && formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) {
tl <- ldw_txtloc(modelsrc, formul1$elem.pos[opi])
lav_msg_stop(
gettext("a variable cannot be regressed on itself"),
tl[1L],
footer = tl[2L]
)
}
# checks for valid names in lhs and rhs
ldw_parse_check_valid_name(formul1, opi - 1L, modelsrc) # valid name lhs
for (j in seq.int(opi + 1L, nelem)) { # valid names rhs
Expand Down Expand Up @@ -1101,6 +1092,18 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) {
}
}
}
# check for variable regressed on itself
if (formul1$elem.text[opi] == "~" &&
formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) {
if (!grepl("^0\\.?0*$", flat.fixed[idx])) {
tl <- ldw_txtloc(modelsrc, formul1$elem.pos[opi])
lav_msg_stop(
gettext("a variable cannot be regressed on itself"),
tl[1L],
footer = tl[2L]
)
}
}
}
# create flat (omit items without operator)
filled.ones <- which(flat.op != "")
Expand Down
7 changes: 4 additions & 3 deletions R/lav_syntax_parser_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,6 @@ lav_parse_model_string_r <- function(model.syntax = "", as.data.frame. = FALSE)
if (length(contsp) > 0L) {
lav_local_msgcode(FALSE, 102L, formul1$elem.pos[contsp[1L]], msgenv)
}
# check for variable regressed on itself
if (formul1$elem.text[opi] == "~" && formul1$elem.text[opi - 1L] == formul1$elem.text[nelem])
return(c(34L, formul1$elem.pos[opi] - 1L))
# checks for valid names in lhs and rhs
lav_parse_check_valid_name(formul1, opi - 1L, modelsrc, msgenv) # valid name lhs
if (exists("error", envir = msgenv)) return(msgenv$error);
Expand Down Expand Up @@ -969,6 +966,10 @@ lav_parse_model_string_r <- function(model.syntax = "", as.data.frame. = FALSE)
}
}
}
# check for variable regressed on itself
if (formul1$elem.text[opi] == "~" &&
formul1$elem.text[opi - 1L] == formul1$elem.text[nelem])
if (!grepl("^0\\.?0*$", flat.fixed[idx])) return(c(34L, formul1$elem.pos[opi] - 1L))
}
# create flat (omit items without operator)
filled.ones <- which(flat.op != "")
Expand Down

0 comments on commit ab477a2

Please sign in to comment.