knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" ) suppressPackageStartupMessages(require('dplyr')) require(purrr)
An R package to manage piecewise models
# To install the development version from GitHub: # install.packages("devtools") devtools::install_github("alvarofranq/piecewise")
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.