Skip to content
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

Casting standata as dataframe #2

Open
ghurault opened this issue May 28, 2021 · 0 comments
Open

Casting standata as dataframe #2

ghurault opened this issue May 28, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@ghurault
Copy link
Owner

I don't use the following function anymore, but it may become handy in the future?

#' Convert Stan data list to original dataframe
#'
#' Not exported. Useful to use with [get_index()] when we only have data_stan.
#'
#' @param data_stan List (output from [prepare_data_lgtd()])
#'
#' @return Dataframe with columns Patient, Time, Score, Label
#'
#' @details This function is designed to use with the Markov Chain model (MC).
#'
#' @noRd
standata_to_df <- function(data_stan) {
  
  stopifnot(is.list(data_stan),
            all(c("k_obs", "t_obs", "y_obs", "k_test", "t_test", "y_test") %in% names(data_stan)),
            length(data_stan$k_obs) == length(data_stan$t_obs),
            length(data_stan$k_obs) == length(data_stan$y_obs),
            length(data_stan$k_test) == length(data_stan$t_test),
            length(data_stan$k_test) == length(data_stan$y_test))
  
  out <- with(data_stan,
              data.frame(Patient = c(k_obs, k_test),
                         Time = c(t_obs, t_test),
                         Score = c(y_obs, y_test),
                         Label = c(rep("Training", length(y_obs)),
                                   rep("Testing", length(y_test)))))
  
  return(out)
  
}
@ghurault ghurault added the enhancement New feature or request label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant