1
$\begingroup$

I'm wondering if someone can assist me in extracting GLM relativities when using splines? I have searched CV and cannot find an easily understandable answer.

Here is some code in R (my apologies as I do not know python).

#load segemented package for plant data
library(segmented)
#load splines package
library(splines)

#get data
data <- data("plant")

#run GLM and get summary
glm_model <- glm(y ~ time, data = plant)
summary(glm_model)


#add spline and get summary
glm_model2 <- glm(y ~ bs(time, degree = 1, knots = c(366.5)), data = plant)
summary(glm_model2)

Here is the summary from the splines model.

Call: glm(formula = y ~ bs(time, degree = 1, knots = c(366.5)), data = plant)

Deviance Residuals:

Min 1Q Median 3Q Max
-0.37187 -0.15317 0.05867 0.12065 0.23452

Coefficients:

Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.36133 0.04236 8.529 1.63e-13 ***

bs(time, degree = 1, knots = c(366.5))1 0.48467 0.05794 8.365 3.71e-13 ***

bs(time, degree = 1, knots = c(366.5))2 0.42415 0.05469 7.756 7.59e-12 ***

How would I convert the polynomial coeefficients in the spline summary to actual GLM relativities? It doesn't need to be in R if someone can explain the math but if anyone has an R example, that would be great!

$\endgroup$
  • 1
    $\begingroup$ What are relativities? $\endgroup$ – AdamO Mar 12 '18 at 19:25
  • $\begingroup$ My apologies. I'm using insurance language. I mean standard coefficients. I believe the estimates the spline packages gives in the summary statement is the orthogonal coefficients. $\endgroup$ – Jordan Mar 12 '18 at 19:34
  • 1
    $\begingroup$ By orthogonal, the spline forms a basis, yes, each column of the spline representation using bs has a dot-product of 0. The coefficients are not orthogonal. "Standard coefficients": why wouldn't you get them by fitting the model regressed with no bs call to time? Or is there a different spline representation you are trying to code? I talk about some alternate parametrizations in another SE answer here. $\endgroup$ – AdamO Mar 12 '18 at 19:36
  • $\begingroup$ I could. In doing this "real world," I do then add splines to form a piecewise regression model to those variables that the technique is applicable to. This changes what the coefficients are but the summary in splines does not show me what I need to know. I can get the slopes and intercept using the segmented package but that only works for continuous segments so I need the splines package or something comparable to fit non-continuous splines. I still need to get those coefficients in the end though. $\endgroup$ – Jordan Mar 12 '18 at 19:40
  • $\begingroup$ I think the post I linked will be useful to you, if anything to clarify what you're asking for here. I recommend working through an exhaustive set of simulations and examples. The version I propose in the answer is interpretable, albeit cumbersome. The basis version is practically uninterpretable. Inspecting matplot(model.matrix( ~ bs(time, degree = 1, knots = c(366.5)), data = plant)) will show you just how contrived the coding is. $\endgroup$ – AdamO Mar 12 '18 at 19:45
0
$\begingroup$

By "relative" do you mean "relative risk"? If so, this question doesn't have a simple answer, since it will be different for different values of $x$ (time). You can do this empirically for two values of time. Something like this should work:

pred1 <- predict(glm_model, data.frame(time = whatever1), type = 'response') pred2 <- predict(glm_model, data.frame(time = whatever2), type = 'response') relative_risk <- pred1 / pred2

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ When I say relativities I actually mean the coefficients I would normally see without a spline. I may be wrong, but I think the estimates or coeffcients are for the splines themselves and not at time < knots. I also would need the correct intercept for each segment the knot/s create. Does that make sense? $\endgroup$ – Jordan Mar 12 '18 at 19:24
  • 1
    $\begingroup$ It sounds like you want the equations of the two separate lines that will make up your model. The way spline regression works (in R, at least) does not allow you to do this easily. You might better off separating your x-variable and doing two separate GLMs. $\endgroup$ – Tim Atreides Mar 12 '18 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.