Skip to content

fragmentation doesn't handle NA values in x properly. #1

@etzkorn

Description

@etzkorn

I have data where I have non-wear periods that are not at the end of the recording time.
I have elected to pre-screen the counts vector, and place NA values in the counts variable x where there is non-wear. Your function does not provide the same output as if there were 0s for NA values. I've compared running your function with NA's (row 2) vs. 0's (row 1) using the reproducible code below. I also tried pre-filtering my data for wear time before providing it to your function (row 3). These three methods produce different results. Which one is theoretically correct? Given your answer, I would recommend editing the function to make at least rows 1 and 2 consistent.

# simulate data
x <- c(sample(0:2, 600, prob = c(.75,.2,.05), replace = T), 
       rep(0,200),
       sample(0:2, 200, prob = c(.75,.2,.05), replace = T)) %>% 
  as.integer
wear <- c(rep(1,600), rep(0,200), rep(1,200))
x.NA <- x
x.NA[wear == 0] <- NA

# fragmentation metrics
bind_rows(
fragmentation(x, wear, thresh = 1, metrics = "all") %>% as.tibble,
fragmentation(x.NA, wear, thresh = 1, metrics = "all") %>% as.tibble,
fragmentation(x.NA[wear == 1], w = rep(1,800), thresh = 1, metrics = "all") %>% as.tibble
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions