hesim-dev / hesim

Health economic simulation modeling and decision analysis
https://hesim-dev.github.io/hesim/
62 stars 17 forks source link

rdirichlet_mat #12

Closed oliver-diaz closed 4 years ago

oliver-diaz commented 4 years ago

It seems that on R 3.6 the hesim function rdirichlet_mat has a conflict with the R package data.table. **

Error in hesim::rdirichlet_mat(n, mat) : The number of rows of 'alpha' must be less than or equal to the number of columns.

old **

previous versions run fine. Here is the difference between the old and new version of the rdirichlet_mat function

function (n, alpha) { if (n <= 0) { stop("n must be greater than 0") } if (!is.matrix(alpha) & !is.vector(alpha)) { stop("alpha must be a vector or a matrix") } if (is.vector(alpha)) { alpha <- matrix(alpha, nrow = 1) } samp <- C_rdirichlet_mat(n, alpha) return(samp) } <bytecode: 0x6bdca78>

**

new

function (n, alpha, output = c("array", "matrix", "data.frame", "data.table")) { output <- match.arg(output) if (n <= 0) { stop("n must be greater than 0") } if (!(is.numeric(alpha) & length(dim(alpha)) <= 2)) { stop("alpha must be a numeric matrix or vector") } if (!is.matrix(alpha)) { alpha <- matrix(alpha, nrow = 1) } if (nrow(alpha) > ncol(alpha)) { stop(paste0("The number of rows of 'alpha' must be less than or equal to ", "the number of columns.")) } samp <- C_rdirichletmat(n, alpha) if (output %in% c("matrix", "data.frame", "data.table")) { samp <- matrix(c(aperm(samp, perm = c(2, 1, 3))), ncol = dim(samp)[1] * dim(samp)[2], byrow = TRUE) colnames(samp) <- paste0("prob", 1:ncol(samp)) } if (output == "data.frame") { samp <- data.frame(samp) } if (output == "data.table") { samp <- data.table(samp) } return(samp) } <bytecode: 0x7f8f479bea50>

dincerti commented 4 years ago

Hi Oliver,

The error message is intended with the updated function. It appears you are trying simulate values in a case where there are more rows than columns in 'alpha'. Is there a reason you are trying to do this? 'alpha' is meant to be a matrix where rows are transitions from a state and columns are transitions to a state.

oliver-diaz commented 4 years ago

Hi Devin,

Th call to hesim is done within the execution of the function sample_pars from the package iviRA. We will look into the source code of the latter to see I it can be modified to comply with the new version of hesim. We will use the old version in the meantime.

Best Oliver

From: Devin Incerti notifications@github.com Reply-To: hesim-dev/hesim reply@reply.github.com Date: Monday, February 17, 2020 at 9:20 AM To: hesim-dev/hesim hesim@noreply.github.com Cc: "Diaz, Oliver" oliver.diaz@precisionxtract.com, Author author@noreply.github.com Subject: Re: [hesim-dev/hesim] rdirichlet_mat (#12)

Hi Oliver,

The error message is intended with the updated function. It appears you are trying simulate values in a case where there are more rows than columns in 'alpha'. Is there a reason you are trying to do this? 'alpha' is meant to be a matrix where rows are transitions from a state and columns are transitions to a state.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/hesim-dev/hesim/issues/12?email_source=notifications&email_token=AJLWAGNBTBGFMIEIQKSKLEDRDKTK5A5CNFSM4KVLRIBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL6Y3UI#issuecomment-587042257, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJLWAGI232BN7YLMQVWKHNDRDKTK5ANCNFSM4KVLRIBA.

CAUTION: This email originated from outside the Precision network. Do not click links or open attachments unless you recognize the sender and/or know the content is safe. The information contained in this email and any attachments is confidential and may be subject to copyright or other intellectual property protection. If you are not the intended recipient, you are not authorized to use or disclose this information, and we request that you notify us by reply mail or telephone and delete the original message from your mail system.

dincerti commented 4 years ago

Hi Oliver, hope you are doing well! The function should now work for you as it did in the previous version of hesim after commit 3330d10.