Skip to content

readBinMat for Multitrait #64

@cheuerde

Description

@cheuerde

Hi,

the function readBinMat expects the first two elements in a given file to contain the the number of rows and
columns, respectively.
A file is initialised like this in BGLR.R :

writeBin(object=c(nRow,LT$p),con=LT$fileEffects,size=ifelse(LT$storageMode=="single",4,8))

In Multitrait.R, like this:

writeBin(object=c(nRow,traits,LT$p),con=LT$fileEffects,size=ifelse(LT$storageMode=="single",4,8))

So the first 3 elements are reserved to hold: number of samples, number of traits and number of levels for the ETA,
resulting in a 3 dimensional array.

The posterior samples from a multitrait model can be read like this:

library(BGLR)

data(wheat)
Y = wheat.Y
M = wheat.X

tmpDir = tempdir()
setwd(tmpDir)

niter = 1000
burnin = 500
thin = 1

ETA <- list(
	    G = list(
		     X = M, 
		     model = "BRR", 
		     saveEffects = TRUE
	    )
)

mod <- Multitrait(
		   Y, 
		   ETA = ETA,
		   nIter = niter, 
		   burnIn = burnin, 
		   thin = thin
)

fileIn = 'ETA_G_beta.bin'
dims = readBin(fileIn, n = 3, what = numeric(), size = 8)
tmp = readBin(fileIn,n = prod(dims) + 3, what=numeric(), size = 8)[-(1:3)]
post_beta = array(data = tmp, dim = dims[c(3,2,1)]

However, the built in function readBinMat cannot be used, as it is expecting a 2-dimensional object.

This could be resolved by always reserving the first 3 elements in the output file (e.g. 'ETA_G_beta_bin')
to hold: number of samples, number of traits and number of levels for the ETA.
For a single trait model from a BGLR call, the second dimension would be 1, and can be dropped when
creating the final output array, thereby not breaking existing workflows that use readBinMat, but still allowing
the same function to be used to read posteriors for multitrait models.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions