Skip to content

df_with_chain2array() silently corrupts data when chains have unequal iterations #498

@utkarshpawade

Description

@utkarshpawade

df_with_chain2array() uses ceiling(nrow(a) / n_chain) to compute the iteration dimension of the output array. When chains have unequal numbers of iterations, R's recycling rule silently duplicates rows to fill the gap, producing a corrupted MCMC array with no error or warning.

Reproducible example:

df <- data.frame(Chain = c(1L, 1L, 1L, 1L, 2L, 2L, 2L), V1 = 1:7)
# Chain 1 has 4 iterations, Chain 2 has 3
# ceiling(7/2) = 4, so chain 2's 3 rows get recycled to fill 4 slots

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions