Skip to content

Commit

Permalink
Merge pull request #7 from Merck/address-v010-cran-review-comment
Browse files Browse the repository at this point in the history
update per CRAN reviewer's suggestions
  • Loading branch information
nanxstats authored Aug 26, 2022
2 parents 335b12e + 5446384 commit 26c9f92
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 42 deletions.
44 changes: 22 additions & 22 deletions R/graphMCP.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

## Graph representation in gMCP

#' Class graphMCP
Expand Down Expand Up @@ -195,24 +195,24 @@ setMethod("print", "gMCPResult",
setMethod("show", "gMCPResult",
function(object) {
# callNextMethod(x, ...)
cat("gMCP-Result\n")
cat("\nInitial graph:\n")
message("gMCP-Result\n")
message("\nInitial graph:\n")
print(object@graphs[[1]])
cat("\nP-values:\n")
message("\nP-values:\n")
print(object@pvalues)
if (length(object@adjPValues)>0) {
cat("\nAdjusted p-values:\n")
message("\nAdjusted p-values:\n")
print(object@adjPValues)
}
cat(paste("\nAlpha:",object@alpha,"\n"))
message(paste("\nAlpha:",object@alpha,"\n"))
if (all(!object@rejected)) {
cat("\nNo hypotheses could be rejected.\n")
message("\nNo hypotheses could be rejected.\n")
} else {
cat("\nHypothesis rejected:\n")
message("\nHypothesis rejected:\n")
print(object@rejected)
}
if (length(object@graphs)>1) {
cat("\nFinal graph after", length(object@graphs)-1 ,"steps:\n")
message("\nFinal graph after", length(object@graphs)-1 ,"steps:\n")
print(object@graphs[[length(object@graphs)]])
}
})
Expand Down Expand Up @@ -414,31 +414,31 @@ setMethod("show", "graphMCP",
function(object) {
#callNextMethod(object)
nn <- getNodes(object)
cat("A graphMCP graph\n")
message("A graphMCP graph\n")
if (!isTRUE(all.equal(sum(getWeights(object)),1))) {
cat(paste("Sum of weight: ",sum(getWeights(object)),"\n", sep=""))
message(paste("Sum of weight: ",sum(getWeights(object)),"\n", sep=""))
}
for (node in getNodes(object)) {
cat(paste(node, " (",ifelse(nodeAttr(object, node, "rejected"),"rejected, ",""),"weight=",format(object@weights[node], digits=4, drop0trailing=TRUE),")\n", sep=""))
message(paste(node, " (",ifelse(nodeAttr(object, node, "rejected"),"rejected, ",""),"weight=",format(object@weights[node], digits=4, drop0trailing=TRUE),")\n", sep=""))
}
printEdge <- FALSE;
for (i in getNodes(object)) {
for (j in getNodes(object)) {
if (object@m[i,j]!=0) {
if (!printEdge) {
cat("Edges:\n")
message("Edges:\n")
printEdge <- TRUE
}
cat(paste(i, " -(", object@m[i,j], ")-> ", j, "\n"))
message(paste(i, " -(", object@m[i,j], ")-> ", j, "\n"))
}
}
}
if (!printEdge) cat("No edges.\n")
if (!printEdge) message("No edges.\n")
#if (!is.null(attr(object, "pvalues"))) { # TODO Do we want to have more output here?
# cat("\nAttached p-values: ", attr(object, "pvalues"), "\n")
# message("\nAttached p-values: ", attr(object, "pvalues"), "\n")
#}
#cat(paste("\nalpha=",paste(format(getWeights(object), digits=4 ,drop0trailing=TRUE),collapse="+"),"=",sum(getWeights(object)),"\n", sep=""))
cat("\n")
#message(paste("\nalpha=",paste(format(getWeights(object), digits=4 ,drop0trailing=TRUE),collapse="+"),"=",sum(getWeights(object)),"\n", sep=""))
message("\n")
}
)

Expand Down Expand Up @@ -641,19 +641,19 @@ setMethod("print", "gPADInterim",

setMethod("show","gPADInterim",
function(object) {
cat("Pre-planned graphical MCP at level:",object@alpha,"\n")
message("Pre-planned graphical MCP at level:",object@alpha,"\n")
show(object@preplanned)
n <- length(object@z1)
cat("Proportion of pre-planned measurements\n collected up to interim:\n")
message("Proportion of pre-planned measurements\n collected up to interim:\n")
v <- object@v
if(length(v) == 1) v <- rep(v,n)
names(v) <- paste('H',1:n,sep='')
print(v)
cat("Z-scores computed at interim\n")
message("Z-scores computed at interim\n")
z1 <- object@z1
names(z1) <- paste('H',1:n,sep='')
print(z1)
cat("\n Interim PCE's by intersection\n")
message("\n Interim PCE's by intersection\n")
tab <- round(cbind(object@Aj,object@BJ),3)
rownames(tab) <- to.intersection(1:nrow(tab))
colnames(tab) <- c(paste('A(',1:n,')',sep=''),'BJ')
Expand Down
12 changes: 2 additions & 10 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ substituteEps <- function(graph, eps=10^(-3)) {
# Real function:
if (is.numeric(graph@m)) return(graph)
m <- matrix(gsub("\\\\epsilon", eps, graph@m), nrow=length(getNodes(graph)))
options(warn=-1)

m2 <- matrix(sapply(m, function(x) {
result <- try(eval(parse(text=x)), silent=TRUE);
ifelse(class(result)=="try-error",NA,result)
}), nrow=length(getNodes(graph)))
options(warn=0)

if (all(is.na(m)==is.na(m2))) m <- m2
rownames(m) <- colnames(m) <- getNodes(graph)
graph@m <- m
Expand Down Expand Up @@ -104,9 +104,6 @@ substituteEps <- function(graph, eps=10^(-3)) {
#' @examples
#'
#' graph <- HungEtWang2010()
#' \dontrun{
#' replaceVariables(graph)
#' }
#' replaceVariables(graph, list("tau"=0.5,"omega"=0.5, "nu"=0.5))
#' replaceVariables(graph, list("tau"=c(0.1, 0.5, 0.9),"omega"=c(0.2, 0.8), "nu"=0.4))
#'
Expand Down Expand Up @@ -376,11 +373,6 @@ permutations <- function(n) {
#'
#' g <- placeNodes(g, nrow=2, force=TRUE)
#'
#' \dontrun{
#' graphGUI(g)
#'
#' }
#'
#'
#' @export placeNodes
placeNodes <- function(graph, nrow, ncol, byrow = TRUE, topdown = TRUE, force = FALSE) {
Expand Down
2 changes: 1 addition & 1 deletion man/gMCPLite-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions man/placeNodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/replaceVariables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion vignettes/GraphicalMultiplicity.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ The initial code block sets options and loads needed packages; no modification s

```{r, message=FALSE, warning=FALSE}
### THERE SHOULD BE NO NEED TO MODIFY THIS CODE SECTION
options(scipen = 999)
# Prefer fixed notation
old <- options(scipen = 999)
# Colorblind palette
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
# 2 packages used for data storage and manipulation: dplyr, tibble
Expand Down Expand Up @@ -644,6 +645,11 @@ for (i in 1:nHypotheses) {
}
```

```{r}
# Restore default options
options(old)
```

## Session information

You can use `sessionInfo()` to document the versions of R and R packages used to render this document.
Expand Down

0 comments on commit 26c9f92

Please sign in to comment.