Skip to main content

segmented: A toolbox for segmented regression.

Project description

Segmented

segmented is a Python toolbox for segmented regression.

Installation

segmented is written for Python 3.7+. To install...

Features

  • 0.0.1
    • single change point
    • identity link functions
    • single predictor
  • 0.0.2
    • single, parametric change point
    • identity link functions
    • single predictor
  • = 0.0.3

    • user-specified number of segments (>2)
    • link functions
    • etc.

How to Use segmented

import segmented as sgmt
import pandas as pd

data = pd.read_csv('mydata.csv')

###############################################################################
# 2 segment model (1 change point)

# specify 2 model specifications: pre- and post-changepoint
model = sgmt.segment(models=['y~x', 'y~x'], data=data)

# specify a single model specification that will be used for each segment
model = sgmt.segment(models=['y~x'], num_segments=2, data=data)

# might need to provide some initial guesses at to-be-estimated parameters
model = sgmt.segment(models=['y~1', 'y~x'], x0=.5, data=data)

# might provide GLM capabilities
model = sgmt.segment(models=['y~x'], family=['binomial'], num_segments=2, data=data)
model = sgmt.segment(models=['y~x'], family=['binomial'], num_segments=2, data=data)

# estimate parameters
model.fit()
# check out estimates
print(model.summary())

OR

###############################################################################
# 2 segments, each segments has an intercept and slope associated with x

# the changepoint is a single value of x
model = sgmt.segment(models='y~x', changepoint='~1', num_segments=2, data=data)
# is equivalent to:
model = sgmt.segment(models='y~x', num_segments=2, data=data)

# 2 segments, each segments has an intercept and slope associated with x
# changepoint is parametric, with it's own intercept and slope associated with z
model = sgmt.segment(models='y~x', changepoint='~z', num_segments=2, data=data)

model = sgmt.segment(models=['y~x','y~x','y~x'], changepoint=['~z','~w'], data=data)

References

  • TBD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segmented-0.0.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

segmented-0.0.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page