# Piece Wise Linear Interpretation in R and plotting with ggplot [duplicate]

I've been able to fit a piece wise linear fit to my data set using Rs splines2 package. I'm hoping someone could help me with interpretation and vizualization.

Here is the model code:

fit <- glm(Frequency ~ state + eff_year + channel + marital_status + usage +
term_2 + pay_plan_2 + dbs(insured_age2, degree = 1, knots = c(40, 65)) +
vehicle_type + dbs(veh_age, degree = 1, knots = c(29, 45, 60)) +
dbs(rating_base_amt, degree = 1, knots = c(5000, 15000, 40000)) +
dbs(length, degree= 1, knots = c(8, 30, 38)) +
dbs(credit_bucket, degree = 1, knots = c(524, 499, 649, 724)), family =
quasipoisson, data = spline_training_set)


Below is part of my summary. My question is now to interpret the spline? Is the estimate on the first spline the estimate I would use for estimate values 40 and below and for all records 65 and above using the second estimate?

Further more, if I wanted to make a line graph using ggplot2 showing each term on the x axis and the estimate on the y axis, how exactly would I do that?

• Questions about interpretations of results from statistical models belong on Cross Validated, not Stack Overflow. You have a lot of variables there so i'm not exactly sure how you want to plot that. Perhaps you could be more specific and give a reproducible example with sample data so we can actually run the code to see what's going on. – MrFlick Nov 8 '17 at 20:02
• Hi @MrFlick. My apologies for the late reply and thank you for comment. I did find a way to graph the splines. Basically, ggplotstart + geom_smooth(method = "glm", formula = y ~ bSpline(x, degree = 1, knots = c(#, #)), se = T). Now I realized that I don't know how to extract the raw coefficients inside the spline which is what I need to provide to my internal partners. We have software (Emblem) that does this automatically but we may be loosing it and I have to recreate in R. – Jordan Dec 8 '17 at 11:16