Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dfToMatrix

data frame to matrix


Description

This function takes a matrix that is in data frame format and transforms it into a matrix. Other packages that allows you to obtain an additive relationship matrix from a pedigree is the 'pedigreemm' package.

Usage

dfToMatrix(x, row="Row",column="Column",
             value="Ainverse", returnInverse=FALSE, 
             bend=1e-6)

Arguments

x

ginv element, output from the Ainverse function.

row

name of the column in x that indicates the row in the original relationship matrix.

column

name of the column in x that indicates the column in the original relationship matrix.

value

name of the column in x that indicates the value for a given row and column in the original relationship matrix.

returnInverse

a TRUE/FALSE value indicating if the inverse of the x matrix should be computed once the data frame x is converted into a matrix.

bend

a numeric value to add to the diagonal matrix in case matrix is singular for inversion.

Value

K

pedigree transformed in a relationship matrix.

Kinv

inverse of the pedigree transformed in a relationship matrix.

Author(s)

Giovanny Covarrubias-Pazaran

References

Covarrubias-Pazaran G (2016) Genome assisted prediction of quantitative traits using the R package sommer. PLoS ONE 11(6): doi:10.1371/journal.pone.0156744

See Also

The core functions of the package mmer

Examples

library(Matrix)
m <- matrix(1:9,3,3)
m <- tcrossprod(m)

mdf <- as.data.frame(as.table(m))
mdf

dfToMatrix(mdf, row = "Var1", column = "Var2", 
            value = "Freq",returnInverse=FALSE )

sommer

Solving Mixed Model Equations in R

v4.1.3
GPL (>= 2)
Authors
Giovanny Covarrubias-Pazaran
Initial release
2021-04-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.