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
)
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
xwhere 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.