@@ -12,22 +12,22 @@ parse_hetero_formula <- function(formula) {
1212 f_char <- Reduce(paste , deparse(formula ))
1313
1414
15- # Check for | separator
16-
15+ # Check for | separator - if missing, default to intercept-only variance
1716 if (! grepl(" \\ |" , f_char )) {
18- stop(" Formula must contain '|' separating mean and variance equations.\n " ,
19- " Usage: y ~ x1 + x2 | z1 + z2" , call. = FALSE )
20- }
17+ # No variance equation specified - use intercept-only (homoscedastic)
18+ mean_part <- f_char
19+ var_part <- " 1"
20+ } else {
21+ # Split: everything before | is mean equation, after is variance equation
22+ parts <- strsplit(f_char , " \\ |" )[[1 ]]
23+ if (length(parts ) != 2 ) {
24+ stop(" Formula must have exactly one '|' separator." , call. = FALSE )
25+ }
2126
22- # Split: everything before | is mean equation, after is variance equation
23- parts <- strsplit(f_char , " \\ |" )[[1 ]]
24- if (length(parts ) != 2 ) {
25- stop(" Formula must have exactly one '|' separator." , call. = FALSE )
27+ mean_part <- trimws(parts [1 ]) # "y ~ x1 + x2"
28+ var_part <- trimws(parts [2 ]) # "z1 + z2"
2629 }
2730
28- mean_part <- trimws(parts [1 ]) # "y ~ x1 + x2"
29- var_part <- trimws(parts [2 ]) # "z1 + z2"
30-
3131 # Parse mean equation (standard formula)
3232 mean_formula <- as.formula(mean_part )
3333 lhs <- all.vars(mean_formula [[2 ]]) # Response variable
0 commit comments