noise_ydiff: noise_ydiff

Description Usage Arguments Value Examples

View source: R/noise_estimation.R

Description

Provide an estimator of noise level within a group of time-series. First step: compute hierarchical clustering and arrange data according to the clustering order. Second step: compute differences between neighboring rows. Differences can then be raised to a power to accentuate gap between large and small differences. The matrix of differences is then summarized by a list of functions.

Usage

1
2
3
noise_ydiff(x, summary.fun = c("mean", "median", "sd"), power.diff = 1,
  hcl.distance = "euclidean", hcl.linkage = "complete",
  plot.diff = T)

Arguments

x

A numerical matrix. Individuals in rows, measurements in columns.

summary.fun

A vector of character, give names of the functions used to summarize the differences. Functions must take a numerical matrix as first input. Functions are applied to the absolute values of differences. Use "colMeans" to get mean difference at each time point.

power.diff

numerical, to what power should differences be raised.

hcl.distance

character, the method used to compute distances between rows for hierarchical clustering. One of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". See ?stats::dist.

hcl.linkage

character, the agglomeration method used in hierarchical clustering. One of "ward.D", "ward.D2", "single", "complete", "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) or "centroid" (= UPGMC). See ?stats::hclust.

plot.diff

logical, whether to plot the histogram of differences.

Value

A list where each entry is the application of one of summary.fun to the difference matrix.

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
25
# Example with normally distributed data (hierarchical clust doesn't really help)
set.seed(7)
x <- rnorm(n = 50)
x <- matrix(x, nrow=5, ncol = 10)
noise_ydiff(x, summary.fun= c("mean", "median", "sd", "colMeans"))


# Example with 3 populations A-C:
# A: oscillates around 10
# B: oscillates around 5
# C: oscillates around 1
n <- 5
len <- 20
express <- expression(t(replicate(n, rnorm(len, mean = 1, sd = 0.1))))
A <- eval(express); A <- A + 9
B <- eval(express); B <- B + 4
C <- eval(express)
ABC <- rbind(A,B,C)
rownames(ABC) <-  make.names(rep(c("A","B","C"), each = 5), unique = T)
# See why hierarchical clust "normalize" the noise estimation:
par(mfrow=c(1,2))
noise_ydiff(ABC)
# Shuffle rows
ABC <- ABC[sample(1:nrow(ABC), replace = FALSE),]
noise_ydiff(ABC) # Recover difference of unshuffled data

majpark21/TSexploreR documentation built on Oct. 16, 2019, 2:46 p.m.