trim_cor: Calculates correlation of shifted vectors

Description Usage Arguments Value Examples

Description

This function is for calculating the correlation between two vectors x and y. The vectors are shifted n times by p elements. This relates to shifted n number of concentrations in either direction, each concentration shift being a multiple of the number of features.

Usage

1
trim_cor(x, y, n = NULL, p = NULL, metadata = NULL)

Arguments

x

vector

y

vector

n

integer. The number of titrations shifts in either directions. i.e n = 2 will shift 2 titrations to the left, and 2 to the right. If n is not directly given, then it will be calculated from by half the number of concentrations in the metadata (to the nearest integer).

p

interger. The number of features. n will always be a multiple of p. This is so identical features are always aligned despite titration shifts.

metadata

optional metadata object produced from construct_metadata. Used to extract values for n and p if none are given.

Value

cor_measurements vector of correlations for each shift

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# create dummy dataset
l <- list()
for (i in 1:100) l[[i]] <- rnorm(100)
df <- as.data.frame(l)
names(df) <- paste("col", 1:100, sep = "_")
# order values (more obvious correlation shifts)
df <- apply(df, 2, sort)
out <- trim_cor(df[,1], df[,2], n = 5, p = 5)
plot(out, type = "l")

# plot all correlations
out <- trim_cor(df[,1], df[,2], 20, 3)
plot(out,
     type = "l",
     xaxt =  "n",
     ylab = "correlation",
     main = "col_1 vs all correlation",
     sub = "20 shifts, 3 elements each")
axis(1, at = 1:41,
     labels = names(out))
for (i in 3:ncol(df)){
 lines(trim_cor(df[,1], df[,i], 20, 3), col = "gray50")
}

Swarchal/TISS documentation built on May 9, 2019, 3:24 p.m.