knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

suppressPackageStartupMessages(require('dplyr'))
require(purrr)

piecewise

An R package to manage piecewise models

Installation

# To install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("alvarofranq/piecewise")

Usage

require(piecewise)

 set.seed(0)
 df_01 <- data.frame(x = 1:5, y = (1:5)+rnorm(5,0,1))
 mod_01 <- glm("y ~ x", data = df_01)
 con_01 <- "x >= 0 & x < 6"

 df_02 <- data.frame(x = 6:10, y = (5:1)+rnorm(5,0,1))
 mod_02 <- glm("y ~ x", data = df_02)
 con_02 <- "x >= 6 & x <= 10"

 p <- piecewise(models = list(mod_01 = mod_01, mod_02 = mod_02),condition = c(con_01, con_02))

 # get fitted values for each model
 fitted(p)

 # predict some values
 newdata <- data.frame(x = 1.5)
 predict(p, newdata = newdata)


alvarofranq/piecewise documentation built on May 27, 2019, 7:43 a.m.