Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

picor

Piecewise-constant regression


Description

picor looks for a piecewise-constant function as a regression function. The regression is necessarily univariate. This is essentially a wrapper for rpart (regression tree) and isoreg.

Usage

picor(formula, data, method, min_length = 0, ...)

## S3 method for class 'picor'
knots(Fn, ...)

## S3 method for class 'picor'
predict(object, newdata, ...)

## S3 method for class 'picor'
plot(x, ...)

## S3 method for class 'picor'
print(x, ...)

Arguments

formula

formula of the model to be fitted.

data

optional data frame.

method

character. If method = "isotonic", then isotonic regression is applied with the isoreg from package stats. Otherwise, rpart is used, with the corresponding method argument.

min_length

integer. The minimal distance between two consecutive knots.

...

Additional arguments to be passed to rpart.

object, x, Fn

An object of class "picor".

newdata

data.frame to be passed to the predict method.

Value

An object of class "picor", which is a list composed of the following elements:

  • formula: the formula passed as an argument;

  • x: the numeric vector of predictors;

  • y: the numeric vector of responses;

  • knots: a numeric vector (possibly of length 0), the knots found;

  • values: a numeric vector (of length length(knots)+1), the constant values taken by the regression function between the knots.

Examples

## Not run: 
s <- stats::stepfun(c(-1,0,1), c(1., 2., 4., 3.))
x <- stats::rnorm(1000)
y <- s(x)
p <- picor(y ~ x, data.frame(x = x, y = y))
print(p)
plot(p)

## End(Not run)

statip

Statistical Functions for Probability Distributions and Regression

v0.2.3
GPL-3
Authors
Paul Poncet [aut, cre], The R Core Team [aut, cph] (C function 'BinDist' copied from package 'stats'), The R Foundation [cph] (C function 'BinDist' copied from package 'stats'), Adrian Baddeley [ctb] (C function 'BinDist' copied from package 'stats')
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.