Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow autoregression if coeff. fixed to zero #398

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading