I was trying to teach myself the math behind what produces the slope and intercept of a segmented variable in the segmented package using the plant
data set. My plan was to run a model through the segmented
package, produce the slopes and intercept using the slope
and intercept
commands and compare to summary
output to the summary
output of splines2
package.
I notice then that both outputs from both packages summary
functions were not the same.
My questions are thus:
- Am I wrong in assuming the segmented function in the
segmented
package fits a spline with a degree of 1 similar to using thebSpline
function with a degree of 1 in thesplines2
package? - Is there a way to get the slopes and intercept for each variable (as opposed to the orthogonal spline in the
summary
output) from tehsplines2
package? Even hard coding the steps would nice to know.
Here is the code I used to try and do this task:
library(segmented)
library(splines2)
data <- data("plant")
#run glm
plant_glm <- glm(y ~ time, data = plant)
#run segmented model
plant_segmented <- segmented(plant_glm, Z = ~time, psi = c(366.5))
#get summary, slope, and intecept
summary(plant_segmented)
slope(plant_segmented)
intercept(plant_segmented)
#Run BSpline model
spline_model <- glm(y ~ bSpline(time, degree = 1, knots = 366.5),data =
plant)
#get bSpline summary
summary(spline_model)