Search code examples
rspline

Splines in R: Location of knots when only df is defined


I have defined a logistic model for a complex survey with splines for the variable edadt defining the degrees of freedom, but not the position of the knots. After running the model:

    > log3<-svyglm(compo ~  bs(edadt,degree=1, df = 3), dclus, family = quasibinomial)

I would like to know where bs has located the knots. When I type:

splineKnots(log3)

This is what I get:

    Error in UseMethod("splineKnots") : 
    no applicable method for 'splineKnots' applied to an object of class "c('svyglm', 'glm',      'lm')"

Any alternative to know the position of the knots?

Thank you.


Solution

  • The splineKnots function doesn't work on many objects. I think you'll have to write your own method for it:

    library(splines)
    splineKnots.default <- function(object) attr(object, "knots")
    edadt <- rnorm(1000)
    splineKnots(bs(edadt,degree=1, df = 3))
    

    Notice that this works on bs(edadt,degree=1, df = 3), not on log3. If you really want it to work on log3, you'll have to figure out what class that object is, and find whether it has the result of bs(edadt,degree=1, df = 3) stored in it anywhere, or the formula so you can reconstruct it.