Skip to content
Draft
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
4 changes: 2 additions & 2 deletions R/aFIPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ autoFIPC <-
if (checkIPD == T) {
# config
IPDgroup <-
as.factor(c(
factor(c(
rep('oldForm', nrow(oldformYDataK)),
rep('newForm', nrow(newformXDataK))
))
), levels = c('newForm', 'oldForm'))
Comment on lines +616 to +619

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Group reference semantics stay stable

as.factor() ordered these labels as newForm, then oldForm. The explicit order preserves encoding and reference-group selection across every estimation branch.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

IPDItemCount <- 0

# IPD target item checking
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-ipdgroup-factor-equivalence.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test_that("explicit IPD group levels preserve the protected factor contract", {
cardinalities <- list(
c(old_form = 1L, new_form = 1L),
c(old_form = 3L, new_form = 5L),
c(old_form = 37L, new_form = 61L)
)

for (sizes in cardinalities) {
labels <- c(
rep("oldForm", sizes[["old_form"]]),
rep("newForm", sizes[["new_form"]])
)
protected <- as.factor(labels)
candidate <- factor(labels, levels = c("newForm", "oldForm"))

expect_identical(candidate, protected)
expect_identical(levels(candidate), c("newForm", "oldForm"))
}
})
Loading