Fix package to re-upload on CRAN. TODO: check tests/example, write inst/extdata/simul...
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 22 Apr 2026 15:51:29 +0000 (17:51 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 22 Apr 2026 15:51:29 +0000 (17:51 +0200)
13 files changed:
.gitignore
doc_PDF/LeastSquareMoments_Auder.et.al_2020.pdf [moved from doc/LeastSquareMoments_Auder.et.al_2020.pdf with 100% similarity]
doc_PDF/Properties.of.GMM_Hansen_1982.pdf [moved from doc/Properties.of.GMM_Hansen_1982.pdf with 100% similarity]
doc_PDF/TensorDecompositions_Anandkumar.et.al_2014.pdf [moved from doc/TensorDecompositions_Anandkumar.et.al_2014.pdf with 100% similarity]
doc_PDF/TensorFactorization_Kuleshov.et.al_2015.pdf [moved from doc/TensorFactorization_Kuleshov.et.al_2015.pdf with 100% similarity]
doc_PDF/TensorMethods_Anandkumar.et.al_2016.pdf [moved from doc/TensorMethods_Anandkumar.et.al_2016.pdf with 100% similarity]
pkg/R/multiRun.R
pkg/R/optimParams.R
pkg/R/plot.R
pkg/R/utils.R
pkg/inst/extdata/FLXMRglm.R [moved from patch_Bettina/FLXMRglm.R with 97% similarity]
pkg/inst/extdata/code.R [moved from patch_Bettina/code.R with 100% similarity]
pkg/inst/extdata/simulateMr.R [new file with mode: 0644]

index 1499b88..68db326 100644 (file)
@@ -1,4 +1,3 @@
-/data/
 /_unversioned/
 
 #ignore roxygen2 generated files
 !/reports/*.sh
 /vignettes/cache/
 /vignettes/figure/
-/vignettes/report.html
-/vignettes/report.md
+/vignettes/*.html
 /vignettes/*.zip
-/vignettes/report_*/
 
 #ignore R session files
 .Rhistory
 .RData
 
 #ignore R CMD build/check generated files
-/*.Rcheck/
-/*.tar.gz
+*.Rcheck/
+*.tar.gz
 
 #ignore generated object files
 *.[oa]
index 767f6f9..88207fd 100644 (file)
 #' @return A list of nf aggregates of N results (matrices).
 #'
 #' @examples
-#' \dontrun{
+#' \donttest{
 #' β <- matrix(c(1,-2,3,1),ncol=2)
 #'
+#' # This example requires a patch for the flexmix package written by Bettina Grün:
+#' patch_path <- system.file("extdata", "FLXMRglm.R", package = "morpheus")
+#' source(patch_path)
+#'
 #' # Bootstrap + computeMu, morpheus VS flexmix
 #' io <- generateSampleIO(n=1000, p=1/2, β=β, b=c(0,0), "logit")
 #' μ <- normalize(β)
@@ -84,6 +88,7 @@
 #'   }, N=10, ncores=3)
 #' for (i in 1:2)
 #'   res[[i]] <- alignMatrices(res[[i]], ref=β, ls_mode="exact")}
+#'
 #' @export
 multiRun <- function(fargs, estimParams, packages = c("morpheus"),
   prepareArgs = function(x,i) x, N=10, ncores=3, agg=lapply, verbose=FALSE)
index c7b9898..c050e63 100644 (file)
@@ -30,7 +30,7 @@
 #'   1/2, matrix(c(1,-2,3,1),ncol=2), c(0,0), "logit")
 #' μ <- computeMu(io$X, io$Y, list(K=2))
 #' o <- optimParams(io$X, io$Y, 2, "logit")
-#' \dontrun{
+#' \donttest{
 #' θ0 <- list(p=1/2, β=μ, b=c(0,0))
 #' par0 <- o$run(θ0)
 #' # Compare with another starting point
index b8024f5..f76017d 100644 (file)
 #' @param ... Additional graphical parameters (xlab, ylab, ...)
 #'
 #' @examples
-#' \dontrun{
-#' β <- matrix(c(1,-2,3,1),ncol=2)
-#' mr <- multiRun(...) #see bootstrap example in ?multiRun
-#'                     #mr[[i]] is a list of estimated parameters matrices
-#' μ <- normalize(β)
-#' for (i in 1:2)
-#'   mr[[i]] <- alignMatrices(res[[i]], ref=μ, ls_mode="exact")
-#' plotHist(mr, 2, 1) #second row, first column}
+#' # mr[[i]] is a list of estimated parameters matrices (here random matrices).
+#' # Should be mr <- multiRun(...) --> see bootstrap example in ?multiRun.
+#' simmr_path <- system.file("extdata", "simulateMr.R", package = "morpheus")
+#' source(simmr_path)
+#' mr <- simulateMr(c(2,2), 10)$mr
+#' plotHist(mr, 2, 1) #second row, first column
+#'
+#' @return No return value, called for side effects.
 #'
 #' @export
 plotHist <- function(mr, x, y, ...)
 {
+  oldpar <- par(no.readonly = TRUE)
+  on.exit(par(oldpar))
+
   params <- .extractParam(mr, x, y)
   L <- length(params)
   # Plot histograms side by side
@@ -51,6 +54,7 @@ plotHist <- function(mr, x, y, ...)
       xlab=ifelse("xlab" %in% names(args), args$xlab, "Parameter value"),
       ylab=ifelse("ylab" %in% names(args), args$ylab, "Density"))
   }
+  NULL
 }
 
 # NOTE: roxygen2 bug, "@inheritParams plotHist" fails in next header:
@@ -67,24 +71,29 @@ plotHist <- function(mr, x, y, ...)
 #' @param ... Additional graphical parameters (xlab, ylab, ...)
 #'
 #' @examples
-#' \dontrun{
-#' β <- matrix(c(1,-2,3,1),ncol=2)
-#' mr <- multiRun(...) #see bootstrap example in ?multiRun
-#'                     #mr[[i]] is a list of estimated parameters matrices
-#' μ <- normalize(β)
-#' for (i in 1:2)
-#'   mr[[i]] <- alignMatrices(res[[i]], ref=μ, ls_mode="exact")
-#' plotBox(mr, 2, 1) #second row, first column}
+#' # mr[[i]] is a list of estimated parameters matrices (here random matrices).
+#' # Should be mr <- multiRun(...) --> see bootstrap example in ?multiRun.
+#' simmr_path <- system.file("extdata", "simulateMr.R", package = "morpheus")
+#' source(simmr_path)
+#' source(simmr_path)
+#' mr <- simulateMr(c(2,2), 10)$mr
+#' plotBox(mr, 2, 1) #second row, first column
+#'
+#' @return No return value, called for side effects.
 #'
 #' @export
 plotBox <- function(mr, x, y, ...)
 {
+  oldpar <- par(no.readonly = TRUE)
+  on.exit(par(oldpar))
+
   params <- .extractParam(mr, x, y)
   L <- length(params)
   # Plot boxplots side by side
   par(mfrow=c(1,L), cex.axis=1.5, cex.lab=1.5, mar=c(4.7,5,1,1))
   for (i in 1:L)
     boxplot(params[[i]], ...)
+  NULL
 }
 
 #' plotCoefs
@@ -101,19 +110,22 @@ plotBox <- function(mr, x, y, ...)
 #' @param ... Additional graphical parameters
 #'
 #' @examples
-#' \dontrun{
-#' β <- matrix(c(1,-2,3,1),ncol=2)
-#' mr <- multiRun(...) #see bootstrap example in ?multiRun
-#'                     #mr[[i]] is a list of estimated parameters matrices
-#' μ <- normalize(β)
-#' for (i in 1:2)
-#'   mr[[i]] <- alignMatrices(res[[i]], ref=μ, ls_mode="exact")
-#' params <- rbind( c(.5,.5), β, c(0,0) ) #p, β, b stacked in a matrix
-#' plotCoefs(mr[[1]], params)}
+#' # mr[[i]] is a list of estimated parameters matrices (here random matrices).
+#' # Should be mr <- multiRun(...) --> see bootstrap example in ?multiRun.
+#' simmr_path <- system.file("extdata", "simulateMr.R", package = "morpheus")
+#' source(simmr_path)
+#' mr_θ <- simulateMr(c(3,2), 10)
+#' mr <- mr_θ$mr ; θ <- mr_θ$θ
+#' plotCoefs(mr[[1]], θ)
+#'
+#' @return No return value, called for side effects.
 #'
 #' @export
 plotCoefs <- function(mr, params, ...)
 {
+  oldpar <- par(no.readonly = TRUE)
+  on.exit(par(oldpar))
+
   d <- nrow(mr[[1]])
   K <- ncol(mr[[1]])
 
@@ -142,6 +154,5 @@ plotCoefs <- function(mr, params, ...)
     col=1, lty=c(1,5,3,3), type="l", lwd=2,
     xlab=ifelse("xlab" %in% names(args), args$xlab, "Parameter index"),
     ylab=ifelse("ylab" %in% names(args), args$ylab, "") )
-
-  #print(o) #not returning o to avoid weird Jupyter issue... (TODO:)
+  NULL
 }
index 06fe25f..83cb0dc 100644 (file)
@@ -10,6 +10,7 @@
 #' x <- matrix(c(1,2,-1,3), ncol=2)
 #' normalize(x) #column 1 is 1/sqrt(5) (1 2),
 #'              #and column 2 is 1/sqrt(10) (-1, 3)
+#'
 #' @export
 normalize <- function(x)
 {
@@ -30,6 +31,7 @@ normalize <- function(x)
 #' # Next line should be a real call to multiRun()
 #' mr <- list( list(matrix(c(1,2,3,4),ncol=2),matrix(c(2,2,1,1),ncol=2)) )
 #' p <- pvalue(mr[[1]])
+#'
 #' @export
 pvalue <- function(mr)
 {
similarity index 97%
rename from patch_Bettina/FLXMRglm.R
rename to pkg/inst/extdata/FLXMRglm.R
index 30fbff6..9af08f7 100644 (file)
@@ -1,3 +1,6 @@
+# Patch provided by Bettina Grün (flexmix author).
+# https://cran.r-project.org/web/packages/flexmix/index.html
+
 FLXMRglm <- function(formula=.~., family=gaussian, offset=NULL)
 {
   if (is.character(family))
similarity index 100%
rename from patch_Bettina/code.R
rename to pkg/inst/extdata/code.R
diff --git a/pkg/inst/extdata/simulateMr.R b/pkg/inst/extdata/simulateMr.R
new file mode 100644 (file)
index 0000000..c09d7a4
--- /dev/null
@@ -0,0 +1,22 @@
+# simulateMr
+#
+# Simulate an output of multiRun(...), because this function is a little
+# complicated to call in an example (see ?multiRun).
+#
+#' β <- matrix(c(1,-2,3,1),ncol=2)
+
+
+# theta, not beta here (more general)
+.simulateMr(
+#' # mr[[i]] is a list of estimated parameters matrices (here random matrices).
+#' # Should be mr <- multiRun(...) --> see bootstrap example in ?multiRun.
+#' mr <- list()
+#' μ <- normalize(β)
+#' for (i in 1:2) {
+#'   mr[[i]] <- list()
+#'   for (j in 1:3)
+#'     mr[[i]][[j]] <- β + matrix(rnorm(4,sd=0.25),ncol=2)
+#'   mr[[i]] <- alignMatrices(mr[[i]], ref=β, ls_mode="exact") --> TODO: align in same function
+#' }
+
+            list(theta = ..., mr = ...)