Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Added code
Browse files Browse the repository at this point in the history
  • Loading branch information
GAYNOR Chris committed Feb 1, 2018
0 parents commit 4919474
Show file tree
Hide file tree
Showing 30 changed files with 1,904 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
Notes.txt
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
src/*.o
src/*.so
src/*.dll
Notes.txt

21 changes: 21 additions & 0 deletions AlphaMME.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
13 changes: 13 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Package: AlphaMME
Type: Package
Title: Alpha Mixed Model Equations
Version: 0.1.0
Date: 2018-01-25
Authors@R: c(person("Chris","Gaynor",email="[email protected]",role="cre"))
Description: This package contains mixed model equation solvers written in C++.
License: MIT + file LICENSE
URL: https://bitbucket.org/hickeyjohnteam/alphamme
Imports: Rcpp (>= 0.12.13), RcppArmadillo
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 6.0.1
NeedsCompilation: true
19 changes: 19 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by roxygen2: do not edit by hand

export(calcD)
export(calcG)
export(calcGIbs)
export(fastDist)
export(fastPairDist)
export(gaussKernel)
export(readMat)
export(solveAniModel)
export(solveMKM)
export(solveMVM)
export(solveRRBLUP)
export(solveRRBLUPMK)
export(solveRRBLUPMV)
export(solveUVM)
import(Rcpp)
import(RcppArmadillo)
useDynLib(AlphaMME, .registration = TRUE)
11 changes: 11 additions & 0 deletions R/AlphaMME.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' @useDynLib AlphaMME, .registration = TRUE
#' @import Rcpp RcppArmadillo

#' @title Alpha Mixed Model Equations
#'
#' @description
#' This package contains mixed model equation solvers written in C++.
#'
#' @docType package
#' @name AlphaMME-package
NULL
228 changes: 228 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @title Read Matrix
#'
#' @description
#' Uses C++ to quickly read a matrix from a text
#' file. Requires knowledge of the number of rows
#' and columns in the file.
#'
#' @param fileName path to the file to read
#' @param rows number of rows to read in
#' @param cols number of columns to read in
#' @param sep a single character seperating data entries
#' @param skipRows number of rows to skip
#' @param skipCols number of columns to skip
#'
#' @return a numeric matrix
#'
#' @export
readMat <- function(fileName, rows, cols, sep = ' ', skipRows = 0L, skipCols = 0L) {
.Call(`_AlphaMME_readMat`, fileName, rows, cols, sep, skipRows, skipCols)
}

#' @title Solve Univariate Model
#'
#' @description
#' Solves a univariate mixed model of form \eqn{y=X\beta+Zu+e}
#'
#' @param y a matrix with n rows and 1 column
#' @param X a matrix with n rows and x columns
#' @param Z a matrix with n rows and m columns
#' @param K a matrix with m rows and m columns
#'
#' @export
solveUVM <- function(y, X, Z, K) {
.Call(`_AlphaMME_solveUVM`, y, X, Z, K)
}

#' @title Solve animal model
#'
#' @description
#' Solves a univariate mixed model of form \eqn{y=X\beta+u+e}
#'
#' @param y a matrix with n rows and 1 column
#' @param X a matrix with n rows and x columns
#' @param K the numeric relationship matrix
#' with n rows and n columns
#'
#' @export
solveAniModel <- function(y, X, K) {
.Call(`_AlphaMME_solveAniModel`, y, X, K)
}

#' @title Solve RR-BLUP
#'
#' @description
#' Solves a univariate mixed model of form \eqn{y=X\beta+Mu+e}
#'
#' @param y a matrix with n rows and 1 column
#' @param X a matrix with n rows and x columns
#' @param M a matrix with n rows and m columns
#'
#' @export
solveRRBLUP <- function(y, X, M) {
.Call(`_AlphaMME_solveRRBLUP`, y, X, M)
}

#' @title Solve Multivariate Model
#'
#' @description
#' Solves a multivariate mixed model of form \eqn{Y=X\beta+Zu+e}
#'
#' @param Y a matrix with n rows and q columns
#' @param X a matrix with n rows and x columns
#' @param Z a matrix with n rows and m columns
#' @param K a matrix with m rows and m columns
#' @param tol tolerance for convergence
#' @param maxIter maximum number of iteration
#'
#' @export
solveMVM <- function(Y, X, Z, K, tol = 1e-6, maxIter = 1000L) {
.Call(`_AlphaMME_solveMVM`, Y, X, Z, K, tol, maxIter)
}

#' @title Solve Multivariate RR-BLUP
#'
#' @description
#' Solves a multivariate mixed model of form \eqn{Y=X\beta+Mu+e}
#'
#' @param Y a matrix with n rows and q columns
#' @param X a matrix with n rows and x columns
#' @param M a matrix with n rows and m columns
#' @param tol tolerance for convergence
#' @param maxIter maximum number of iteration
#'
#' @export
solveRRBLUPMV <- function(Y, X, M, tol = 1e-6, maxIter = 1000L) {
.Call(`_AlphaMME_solveRRBLUPMV`, Y, X, M, tol, maxIter)
}

#' @title Solve Multikernel Model
#'
#' @description
#' Solves a univariate mixed model with multiple random effects.
#'
#' @param y a matrix with n rows and 1 column
#' @param X a matrix with n rows and x columns
#' @param Zlist a list of Z matrices
#' @param Klist a list of K matrices
#' @param maxIter maximum number of iteration
#'
#' @export
solveMKM <- function(y, X, Zlist, Klist, maxIter = 40L) {
.Call(`_AlphaMME_solveMKM`, y, X, Zlist, Klist, maxIter)
}

#' @title Solve Multikernel RR-BLUP
#'
#' @description
#' Solves a univariate mixed model with multiple random effects.
#'
#' @param y a matrix with n rows and 1 column
#' @param X a matrix with n rows and x columns
#' @param Mlist a list of M matrices
#' @param maxIter maximum number of iteration
#'
#' @export
solveRRBLUPMK <- function(y, X, Mlist, maxIter = 40L) {
.Call(`_AlphaMME_solveRRBLUPMK`, y, X, Mlist, maxIter)
}

#' @title Calculate G Matrix
#'
#' @description
#' Calculates the genomic relationship matrix.
#'
#' @param X a matrix of marker genotypes scored as 0,1,2
#'
#' @return a matrix of the realized genomic relationships
#'
#' @export
calcG <- function(X) {
.Call(`_AlphaMME_calcG`, X)
}

#' @title Calculate Dominance Matrix
#'
#' @description
#' Calculates the dominance relationship matrix.
#'
#' @param X a matrix of marker genotypes scored as 0,1,2
#'
#' @references
#' \cite{Nishio, M, and M. Satoh. 2014. Including Dominance Effects in the Genomic BLUP Method for Genomic Evaluation. PLOS ONE 9(1): e85792.}
#'
#' @return a matrix of the realized dominance relationships
#'
#' @export
calcD <- function(X) {
.Call(`_AlphaMME_calcD`, X)
}

#' @title Calculate IBS G Matrix
#'
#' @description
#' Calculates an identity-by-state genomic relationship matrix
#' based on simple matching.
#'
#' @param X a matrix of marker genotypes scored as 0,1,2
#'
#' @return a matrix of genomic relationships
#'
#' @export
calcGIbs <- function(X) {
.Call(`_AlphaMME_calcGIbs`, X)
}

#' @title Calculate Euclidean distance
#'
#' @description
#' Calculates a Euclidean distance matrix using a binomial
#' theorem trick. Results in much faster computation than the
#' \code{dist} function in package \code{stats}.
#'
#' @param X a numeric matrix
#'
#' @return a matrix of columnwise distances
#'
#' @export
fastDist <- function(X) {
.Call(`_AlphaMME_fastDist`, X)
}

#' @title Calculate Paired Euclidean distance
#'
#' @description
#' Calculates a Euclidean distance between two matrices using
#' a binomial theorem trick.
#'
#' @param X a numeric matrix
#' @param Y a numeric matrix
#'
#' @return a matrix of columnwise distances between matrices
#' X and Y
#'
#' @export
fastPairDist <- function(X, Y) {
.Call(`_AlphaMME_fastPairDist`, X, Y)
}

#' @title Calculate Gaussian Kernel
#'
#' @description
#' Calculates a Gaussian kernel using a Euclidean distance
#' matrix.
#'
#' @param D a matrix of Euclidean distances,
#' see \code{\link{fastDist}}
#' @param theta the tuning parameter
#'
#' @return a numeric matrix
#'
#' @export
gaussKernel <- function(D, theta) {
.Call(`_AlphaMME_gaussKernel`, D, theta)
}

9 changes: 9 additions & 0 deletions man/AlphaMME-package.Rd

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

20 changes: 20 additions & 0 deletions man/calcD.Rd

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

17 changes: 17 additions & 0 deletions man/calcG.Rd

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

18 changes: 18 additions & 0 deletions man/calcGIbs.Rd

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

19 changes: 19 additions & 0 deletions man/fastDist.Rd

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

Loading

0 comments on commit 4919474

Please sign in to comment.