diff --git a/.Rbuildignore b/.Rbuildignore index 2cec375..d9043fd 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^misc$ +^.*\.o$ +^.*\.so$ diff --git a/DESCRIPTION b/DESCRIPTION index f78edec..374232f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ Depends: data.table, lme4, Matrix, + methods, Rcpp, stats License: GPL-3 | AGPL-3 @@ -55,7 +56,6 @@ Suggests: lmerTest, loo, MASS, - methods, MuMIn, nlme, pdftools, diff --git a/NAMESPACE b/NAMESPACE index d13e2e8..020db00 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -120,6 +120,7 @@ export(h2v2WX2019) export(haplosAlleles2num) export(haplosList2Matrix) export(hinton) +export(imageMat) export(imageWithScale) export(imputeGenosWithMean) export(imputeGenosWithMeanPerPop) @@ -311,3 +312,4 @@ import(Rcpp) import(data.table) import(lme4) import(stats) +importFrom(methods,is) diff --git a/R/misc.R b/R/misc.R index d9b2285..c3d974d 100644 --- a/R/misc.R +++ b/R/misc.R @@ -1,6 +1,7 @@ ##' @import data.table ##' @import lme4 ##' @import Matrix +##' @importFrom methods is ##' @import Rcpp ##' @import stats diff --git a/R/plotting.R b/R/plotting.R index e4464e8..3916625 100644 --- a/R/plotting.R +++ b/R/plotting.R @@ -225,6 +225,25 @@ hinton <- function(m, main="", max.sqrt.m=NULL){ on.exit(graphics::par(def.par)) } +##' Image of a matrix +##' +##' Plots an image of a matrix. +##' @param mat matrix +##' @param title optional title of the plot +##' @param col colors +##' @return nothing +##' @author Timothee Flutre +##' @export +imageMat <- function(mat, title, + col=grDevices::grey.colors(length(table(c(mat))), rev=TRUE)){ + if(missing(title)){ + title <- deparse(substitute(mat)) + title <- paste0(title, " (", nrow(mat), " x ", ncol(mat), ")") + } + graphics::image(t(mat)[,nrow(mat):1], axes=FALSE, main=title, + col=col) +} + ##' Plot a scale, e.g. to add on the side of image() ##' ##' Takes some time to draw (there is one polygon per break...) diff --git a/R/stats.R b/R/stats.R index 9196649..5a3dcbb 100644 --- a/R/stats.R +++ b/R/stats.R @@ -106,6 +106,7 @@ rmsre <- function(rel_error){ ##' Returns the relative root mean squared error (RRMSE) as defined in \href{https://doi.org/10.3354/cr030079}{Willmott and Matsuura (2005)}. ##' @param error vector \eqn{(\hat{\theta}_i - \theta_i)} ##' @param theta vector \eqn{\theta_i} +##' @param perc if TRUE, the return value will be a percentage ##' @return numeric ##' @author Timothee Flutre ##' @seealso \code{\link{rmse}}, \code{\link{rmsre}} diff --git a/man/imageMat.Rd b/man/imageMat.Rd new file mode 100644 index 0000000..783a29d --- /dev/null +++ b/man/imageMat.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotting.R +\name{imageMat} +\alias{imageMat} +\title{Image of a matrix} +\usage{ +imageMat( + mat, + title, + col = grDevices::grey.colors(length(table(c(mat))), rev = TRUE) +) +} +\arguments{ +\item{mat}{matrix} + +\item{title}{optional title of the plot} + +\item{col}{colors} +} +\value{ +nothing +} +\description{ +Plots an image of a matrix. +} +\author{ +Timothee Flutre +} diff --git a/man/matWide2Long.Rd b/man/matWide2Long.Rd index 43e3b0d..771393c 100644 --- a/man/matWide2Long.Rd +++ b/man/matWide2Long.Rd @@ -7,7 +7,7 @@ matWide2Long( mat, diag = TRUE, - outColNs = c("row", "col"), + outColNs = c("row", "col", "val"), stringsAsFactors = FALSE ) } diff --git a/man/rrmse.Rd b/man/rrmse.Rd index 7244453..c692061 100644 --- a/man/rrmse.Rd +++ b/man/rrmse.Rd @@ -10,6 +10,8 @@ rrmse(error, theta, perc = TRUE) \item{error}{vector \eqn{(\hat{\theta}_i - \theta_i)}} \item{theta}{vector \eqn{\theta_i}} + +\item{perc}{if TRUE, the return value will be a percentage} } \value{ numeric diff --git a/misc/intro-het-GxE.Rmd b/misc/intro-het-GxE.Rmd index b5ef344..38f09ac 100644 --- a/misc/intro-het-GxE.Rmd +++ b/misc/intro-het-GxE.Rmd @@ -32,6 +32,7 @@ suppressPackageStartupMessages(library(emmeans)) suppressPackageStartupMessages(library(lme4)) suppressPackageStartupMessages(library(nlme)) suppressPackageStartupMessages(library(MM4LMM)) +suppressPackageStartupMessages(library(MegaLMM)) ``` Execution time (see the appendix): @@ -830,6 +831,12 @@ cor(tmp[,"true"], tmp[,"estim"]) plot(tmp[,"estim"], tmp[,"true"], las=1, asp=1, xlab="estimated value", ylab="true value", main="Error variances (gls het)", pch=19); abline(a=0, b=1, lty=2) ``` +### `MegaLMM` + +Details: https://github.com/deruncie/MegaLMM/blob/master/vignettes/MultiEnvironmentTrial.Rmd + +TODO + ### `MMEst` from `MM4LMM` The `MMEst` from the `MM4LMM` package performs inference via ReML, and can handle both random variables and heteroscedasticity.