-1

In R I have produced a piecewise linear regression model and I have the outputs for the model, however, I need help constructing the models formula and I can't find online a formula to calculate the model with two breakpoints.

Please let me know if someone is able to help, I will include my figures below:

psi1.x 34.125 (breakpoint 1) psi2.x 63.690 (breakpoint 2)

(Intercept) 39.71818 x 0.23644 U1.x -0.33708 U2.x 0.42017

Thank you

I am expecting three formulas for the different intervals of my data that looks like y = B0 + B1x + e(t).

The code is as follows:

# Load necessary packages
library(segmented)
library(lmtest)

#create data
Date <- c(1:93)
Percentage <- c("38.2", "39.2", "40.4", "40.7", "41.5", "41.9", "42", "41.4", "41.9", "42.5", "42.5", "42.6", "42.4", "42.4", "43.4", "43.4", "44", "44.1", "45.2", "44.6", "45", "45.3", "45.2", "44.8", "46.2", "46.4", "46.4", "46.1", "46.4", "46.4", "46.7", "46.7", "47", "47.5", "46.4", "46.7", "46.6", "47.6", "47.8", "47.5", "47.9", "47.7", "47.7", "47", "46.8", "47.1", "46.8", "45.6", "45.2", "45.7", "46.4", "46.7", "45.5", "45.5", "45.5", "45.9", "45.8", "46.4", "46.7", "46.4", "43.6", "43.4", "44.2", "44.2", "44.9", "45.8", "45.5", "46.3", "45.9", "45.6", "46.6", "46.9", "47.9", "48.2", "49.5", "49", "49.2", "49.8", "50.5", "50.7", "50.7", "51.2", "51.5", "51.7", "52.6", "53.2", "54.1", "53.5", "52.3", "51.8", "52.2", "52.3", "52.7")

Percentage <- as.numeric(Percentage

disabilityemployment <- data.frame(Date, Percentage)
View(disabilityemployment)

y <- disabilityemployment$Percentage
x <- disabilityemployment$Date

# Fit initial piecewise linear regression model
seg.model <- segmented(lm(y ~ x, data = disabilityemployment), seg.Z = ~x, npsi = 2)
summary(seg.model)
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • 1
    Can you add the data and code you used to produce the output you reference? – DaveArmstrong Mar 14 '23 at 14:05
  • Its time series data regarding the disability employment gap in the UK from 1998 to 2021. – Ana Pereira Mar 14 '23 at 14:40
  • My code is: [link](http://example.com) _italic_**bold** `library(segmented) # Fit initial piecewise linear regression model seg.model <- segmented(lm(y ~ x, data = disabilityemployment), seg.Z = ~x, npsi = 2) summary(seg.model)` – Ana Pereira Mar 14 '23 at 14:42
  • 2
    Please add a reproducible example, see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – kjetil b halvorsen Mar 14 '23 at 14:47
  • Thank you for your help @kjetilbhalvorsen. I have now included the code in the original questions. Please let me know if you are able to help. NOTE: Your output may be slightly different to mine. – Ana Pereira Mar 14 '23 at 15:41

1 Answers1

0

This output suggests that the the knot locations for the piecewise linear basis functions are:

psi1.x 34.125 (breakpoint 1) 
psi2.x 63.690 (breakpoint 2)

So, the equation is different depending on where you are on x:

enter image description here

where k1 and k2 are the knot locations and b0, b1, b2 and b3 are the regression coefficients for the intercept, x, U1.x and U2.x, respectively.

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25