demean_matrix: Worker function for demeaning a matrix

Description Usage Arguments Value Examples

View source: R/demean_matrix.R

Description

De-means a matrix based on the column means or the visit-specific means.

Usage

1
2
3
demean_matrix(y, visit, twoway = TRUE, tol = 0)

demean_matrix.Deprecated(y, visit, twoway = TRUE, tol = 0)

Arguments

y

n by p matrix of data

visit

Vector of visits, EX) (1, 2, 1, 2, 1, 2, ... , 1, 2)

twoway

a logical argument indicating whether a oneway or twoway mean subtraction is more appropriate for the problem. If FALSE, only the overall sample mean will be removed only; if TRUE, it will also remove visit specific means to avoid scanner or batch effects

tol

tolerance for matching visits.

Value

Matrix of the same size as y

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
id = c(1:10, 1:10)
visit = rep(1:2, each = 10)
n = length(id)
p = 100
y = matrix(rnorm(n * p), nrow = n, ncol = p)
result = demean_matrix(y, visit = visit)
result.oneway = demean_matrix(y, visit = visit, twoway = FALSE)

testthat::expect_warning({
result.old = demean_matrix.Deprecated(y, visit = visit)
})
testthat::expect_warning({
result.old_oneway = demean_matrix.Deprecated(y,
visit = visit,
twoway = FALSE)
})
stopifnot(
isTRUE(all.equal(
result.oneway, result.old_oneway)
))

stopifnot(
isTRUE(all.equal(result.old, result))
)

neuroconductor-devel/I2C2 documentation built on May 3, 2021, 12:33 p.m.