stepfitClass: Fitted step function

stepfitR Documentation

Fitted step function

Description

Constructs an object containing a step function fitted to some data.

Usage

stepfit(cost, family, value, param = NULL, leftEnd, rightEnd, x0,
  leftIndex = leftEnd, rightIndex = rightEnd)
## S3 method for class 'stepfit'
x[i, j, drop = if(missing(i)) TRUE else
  if(missing(j)) FALSE else length(j) == 1, refit = FALSE] 
## S3 method for class 'stepfit'
print(x, ...)
## S3 method for class 'stepfit'
plot(x, dataspace = TRUE, ...)
## S3 method for class 'stepfit'
lines(x, dataspace = TRUE, ...)
## S3 method for class 'stepfit'
fitted(object, ...)
## S3 method for class 'stepfit'
residuals(object, y, ...)
## S3 method for class 'stepfit'
logLik(object, df = NULL, nobs = object$rightIndex[nrow(object)], ...)

Arguments

cost

the value of the cost-functional used for the fit: RSS for family gauss, log-likelihood (up to a constant) for families poisson and binomial

family

distribution of the errors, either "gauss", "poisson" or "binomial"

value

a numeric vector containing the fitted values for each block; its length gives the number of blocks

param

additional paramters specifying the distribution of the errors, the number of trials for family "binomial"

leftEnd

a numeric vector of the same length as value containing the left end of each block

rightEnd

a numeric vector of the same length as value containing the left end of each block

x0

a single numeric giving the last unobserved sample point directly before sampling started, i.e. before leftEnd[0]

leftIndex

a numeric vector of the same length as value containing the index of the sample points corresponding to the block's left end, cf. stepcand

rightIndex

a numeric vector of the same length as value containing the index of the sample points corresponding to the block's right end, cf. stepcand

x, object

the object

y

a numeric vector containing the data with which to compare the fit

df

the number of estimated parameters: by default the number of blocks for families poisson and binomial, one more (for the variance) for family gauss

nobs

the number of observations used for estimating

...

for generic methods only

i,j,drop

see "[.data.frame"

refit

logical; determines whether the function will be refitted after subselection, i.e. whether the selection should be interpreted as a fit with fewer jumps); in that case, for family = "gaussKern", refit needs to be set to the original data, i.e. y

dataspace

logical determining whether the expected value should be plotted instead of the fitted parameter value, useful e.g. for family = "binomial", where it will plot the fitted success probability times the number of trials per observation

Value

stepfit

an object of class stepfit which extends stepblock, additionally containing attributes cost, family and param, as well as columns leftIndex and rightIndex

[.stepfit

an object of class stepfit which contains the selected subset

fitted.stepfit

a numeric vector of length rightIndex[length(rightIndex)] giving the fit at the original sample points

residuals.stepfit

a numeric vector of length rightIndex[length(rightIndex)] giving the residuals at the original sample points

logLik.stepfit

an object of class logLik giving the likelihood of the data given this fit, e.g. for use with AIC and stepsel; this will (incorrectly) treat family = "gaussKern" as if it were fitted with family = "gauss"

plot.stepfit, plot.stepfit

the corresponding functions for stepblock are called

See Also

stepblock, stepbound, steppath, stepsel, family, "[.data.frame", fitted, residuals, logLik, AIC

Examples

# simulate 5 blocks (4 jumps) within a total of 100 data points
b <- c(sort(sample(1:99, 4)), 100)
p <- rep(runif(5), c(b[1], diff(b))) # success probabilities
# binomial observations, each with 10 trials
y <- rbinom(100, 10, p)
# find solution with 5 blocks
fit <- steppath(y, family = "binomial", param = 10)[[5]]
plot(y, ylim = c(0, 10))
lines(fit, col = "red")
# residual diagnostics for Gaussian data
yg <- rnorm(100, qnorm(p), 1)
fitg <- steppath(yg)[[5]]
plot(yg, ylim = c(0, 10))
lines(fitg, col = "red")
plot(resid(fitg, yg))
qqnorm(resid(fitg, yg))

stepR documentation built on Nov. 14, 2023, 1:09 a.m.