Learn R Programming

L0TFinv (version 0.1.0)

SimuBlocksInv: Simulate Blocks Data

Description

This function generates data points of piecewise constant trends.

Usage

SimuBlocksInv(n, sigma, seed = NA, tau, h)

Value

A list containing the piecewise constant simulated data and the underlying trend:

x

The set { \(\frac{1}{n}\), \(\frac{2}{n}\), \(\frac{3}{n}\),..., \(1\)}

y

The piecewise constant simulated data of length \(n\)

y0

The underlying trend of length \(n\)

setA

The set of position indicators of change points in the simulated data

tau

The locations of change points in the underlying trend

Arguments

n

Number of data points

sigma

Standard deviation of the noise added to the signal

seed

An optional seed for random number generation to make results reproducible

tau

The locations of change points in the underlying trend

h

The constant values of the \(length(tau)+1\) segments of the underlying trend

Details

  • To simplify the analysis, normalize the change point positions to a range between 0 and 1. Require that all elements of the input \(tau\) are within this range. Consequently, the change point positions in simulated data forms a subset of the set { \(\frac{1}{n}\), \(\frac{2}{n}\), \(\frac{3}{n}\),..., 1}.

  • In fact, \(length(tau)\) change points can divide the interval into \(length(tau)+1\) segments of constant function values. Therefore, ensure that the length of vector \(h\) is \(length(tau)+1\).

Examples

Run this code
tau = c(0.1, 0.3, 0.4, 0.7, 0.85)
h = c(-1, 5, 3, 0, -1, 2)
BlocksData <- SimuBlocksInv(n = 350, sigma = 0.1, seed = 50, tau = tau ,h = h)
plot(BlocksData$x, BlocksData$y, xlab="", ylab="")
lines(BlocksData$x, BlocksData$y0, col = "red")
print(BlocksData$setA)
print(BlocksData$tau)

Run the code above in your browser using DataLab