-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sim.fmsm()
different results with tidy=TRUE
vs tidy=FALSE
#163
Comments
Thanks for this report - yes, one would expect there to be equivalent information in the messy and tidy results. For the moment I will at least fix the documentation to explain that the tidy results exclude the censoring times, but I will leave the issue open, because ideally I think they should be included somehow. Though to implement that, I'm not sure whether |
This in the meantime works for my specific case, but it just set the tidy_sim.fmsm <- function(simfs) {
trans <- attr(simfs, "trans")
start <- which(apply(trans, 1, function(x) any(!is.na(x))))
res <- NULL
id_vector <- seq_len(nrow(simfs$st))
## for each starting state
for (i in seq_along(start)) {
subject_i <- NULL
end_i <- which(!is.na(trans[start[i], ]))
## for each next state
for (j in seq_len(ncol(simfs$st) - 1)) {
## break down the following conditions
match_start <- simfs$st[, j] == start[i]
match_end <- simfs$st[, j + 1] %in% end_i
same_end <- simfs$st[, j + 1] == start[i]
matching_subjects <- match_start & match_end
censored_subjects <- match_start & same_end
if (any(matching_subjects)) {
subject_j <-
data.frame(id = id_vector[which(matching_subjects)],
end = simfs$st[matching_subjects, j + 1],
time = simfs$t[matching_subjects, j + 1],
delay = simfs$t[matching_subjects, j + 1] -
simfs$t[matching_subjects, j],
status = 1L)
subject_i <- rbind(subject_i, subject_j)
}# END - if: matching_subjects
if (any(censored_subjects)) {
cens_j <-
data.frame(id = id_vector[which(censored_subjects)],
end = simfs$st[censored_subjects, j + 1],
time = simfs$t[censored_subjects, j + 1],
delay = simfs$t[censored_subjects, j + 1] -
simfs$t[censored_subjects, j],
status = 0L)
subject_i <- rbind(subject_i, cens_j)
}# END - if: censored_subjects
}# END - for: j
if (nrow(subject_i) > 0) {
subject_i$start <- start[i]
res <- rbind(res, subject_i)
simfs$st <- simfs$st[!censored_subjects, ]
simfs$t <- simfs$t[!censored_subjects, ]
id_vector <- id_vector[!censored_subjects]
}# END - if
}# END - for: i
## remove subjects already censored one step before
res <- res[res$delay > 0, ]
res$start <- as.character(res$start)
res$end <- as.character(res$end)
which_censored <- which(res$start == res$end)
res$end[which_censored] <- NA_character_
res$trans <- paste(res$start, res$end, sep = " - ")
res <- res[, c("id", "start", "end", "trans",
"time", "delay", "status")]
attr(res, "trans") <- trans
attr(res, "statenames") <- colnames(trans)
res <- res[order(res$id, res$start), ]
rownames(res) <- seq_len(nrow(res))
res
}# END - tidy_sim.fmsm |
The MRE below shows that only uncensored paths are returned when
tidy=TRUE
.Is this on purpose @chjackson? I couldn't find reference to this behaviour in the help page.
I think this is created by
simfs_bytrans
which is called whentidy=TRUE
.The text was updated successfully, but these errors were encountered: