Compute \(G G^T\) from a bed object, with possible filtering and scaling
of G
. For example, this can be used to compute GRMs.
bed_tcrossprodSelf(
obj.bed,
fun.scaling = bed_scaleBinom,
ind.row = rows_along(obj.bed),
ind.col = cols_along(obj.bed),
block.size = block_size(length(ind.row))
)
Object of type bed, which is the mapping of some bed file.
Use obj.bed <- bed(bedfile)
to get this object.
A function with parameters X
(or obj.bed
), ind.row
and
ind.col
, and that returns a data.frame with $center
and $scale
for the
columns corresponding to ind.col
, to scale each of their elements such as followed:
$$\frac{X_{i,j} - center_j}{scale_j}.$$ Default uses binomial scaling.
You can also provide your own center
and scale
by using bigstatsr::as_scaling_fun()
.
An optional vector of the row indices (individuals) that
are used. If not specified, all rows are used.
Don't use negative indices.
An optional vector of the column indices (SNPs) that are used.
If not specified, all columns are used.
Don't use negative indices.
Maximum number of columns read at once. Default uses block_size.
A temporary FBM, with the following two attributes:
a numeric vector center
of column scaling,
a numeric vector scale
of column scaling.
Large matrix computations are made block-wise and won't be parallelized
in order to not have to reduce the size of these blocks. Instead, you can use
the MKL
or OpenBLAS in order to accelerate these block matrix computations.
You can control the number of cores used by these optimized matrix libraries
with bigparallelr::set_blas_ncores()
.
bedfile <- system.file("extdata", "example.bed", package = "bigsnpr")
obj.bed <- bed(bedfile)
K <- bed_tcrossprodSelf(obj.bed)
K[1:4, 1:6] / ncol(obj.bed)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.09900885 0.05531637 0.08230576 0.06440704 0.06389930 0.06632927
#> [2,] 0.05531637 1.14651667 0.08627960 0.09470694 0.12318884 0.09608808
#> [3,] 0.08230576 0.08627960 1.11142319 0.06860068 0.09951989 0.04400732
#> [4,] 0.06440704 0.09470694 0.06860068 1.06728731 0.08570288 0.09599564