Skip to contents

Calculates the largest R-hat statistic across all variables and chain statistics for the it most recent iterations

Usage

rhat_max(mids, n = 1L)

Arguments

mids

A mids object as created by mice::mice()

n

The number of recent iterations for which R-hat should be calculated. If this is larger than the total number of iterations, it is truncated.

Value

A scalar double containing the maximum R-hat statistic

Examples

# Create `mids` object
mids <- mice::mice(mice::nhanes)
#> 
#>  iter imp variable
#>   1   1  bmi  hyp  chl
#>   1   2  bmi  hyp  chl
#>   1   3  bmi  hyp  chl
#>   1   4  bmi  hyp  chl
#>   1   5  bmi  hyp  chl
#>   2   1  bmi  hyp  chl
#>   2   2  bmi  hyp  chl
#>   2   3  bmi  hyp  chl
#>   2   4  bmi  hyp  chl
#>   2   5  bmi  hyp  chl
#>   3   1  bmi  hyp  chl
#>   3   2  bmi  hyp  chl
#>   3   3  bmi  hyp  chl
#>   3   4  bmi  hyp  chl
#>   3   5  bmi  hyp  chl
#>   4   1  bmi  hyp  chl
#>   4   2  bmi  hyp  chl
#>   4   3  bmi  hyp  chl
#>   4   4  bmi  hyp  chl
#>   4   5  bmi  hyp  chl
#>   5   1  bmi  hyp  chl
#>   5   2  bmi  hyp  chl
#>   5   3  bmi  hyp  chl
#>   5   4  bmi  hyp  chl
#>   5   5  bmi  hyp  chl

# Get max R-hat for most recent 2 iterations
rhat <- rhat_max(mids, n = 2L)
rhat
#> [1] 2.497963 1.902514