Learn R Programming

stepR (version 1.0-1)

stepcand: Forward selection of candidate jumps

Description

Find candidates for jumps in serial data by forward selection.

Usage

stepcand(y, x = 1:length(y), x0 = 2 * x[1] - x[2], max.cand = NULL,
  family = c("gauss", "gaussvar", "poisson", "binomial", "gaussKern"), param = NULL,
  weights = rep(1, length(y)), cand.radius = 0)

Arguments

y
a numeric vector containing the serial data
x
a numeric vector of the same length as y containing the corresponding sample points
x0
a single numeric giving the last unobserved sample point directly before sampling started
max.cand
single integer giving the maximal number of blocks to find; defaults to using all data (note: there will be one block more than the number of jumps
family
distribution of the errors, either "gauss", "poisson" or "binomial"; "gaussInhibit" is like "gauss" forbids jumps getting close together or to the ends in
param
additional parameters specifying the distribution of the errors; the number of trials for family "binomial"; for gaussInhibit and gaussInhibitBoth a numeric of length 3 with components "start", "mi
weights
a numeric vector of the same length as y containing non-negative weights
cand.radius
a non-negative integer: adds for each candidate found all indices that are at most cand.radius away

Value

  • An object of class stepcand extending class stepfit such that it can be used as an input to steppath.stepcand: additionally contains columns
  • cumSumThe cumulative sum of x up to rightEnd.
  • cumSumSqThe cumulative sum of squares of x up to rightEnd (for family = "gauss").
  • cumSumWeThe cumulative sum of weights up to rightEnd.
  • improveThe improvement this jump brought about when it was selected.

See Also

steppath, stepfit, family

Examples

Run this code
# simulate 5 blocks (4 jumps) within a total of 100 data points
b <- c(sort(sample(1:99, 4)), 100)
f <- rep(rnorm(5, 0, 4), c(b[1], diff(b)))
rbind(b = b, f = unique(f), lambda = exp(unique(f) / 10) * 20)
# add gaussian noise
x <- f + rnorm(100)
# find 10 candidate jumps
stepcand(x, max.cand = 10)
# for poisson observations
y <- rpois(100, exp(f / 10) * 20)
# find 10 candidate jumps
stepcand(y, max.cand = 10, family = "poisson")
# for binomial observations
size <- 10
z <- rbinom(100, size, pnorm(f / 10))
# find 10 candidate jumps
stepcand(z, max.cand = 10, family = "binomial", param = size)

Run the code above in your browser using DataLab