Description Usage Arguments Examples
Create a piecewise object
1 |
models |
A list with the models. |
condition |
A character vector with the conditions to use each model. |
... |
Other arguments |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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.