discont_basis: Provides set of basis functions on either side of a time...

Description Usage Arguments Examples

View source: R/discont_basis.R

Description

Provides set of basis functions on either side of a time point, allowing for a discontinuity in the fitted functions

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
discont_basis(
  timepoints,
  discont_point,
  knots = NULL,
  dfPre = NULL,
  dfPost = dfPre,
  degree = 3,
  intercept = TRUE,
  type = c("ns", "bs")
)

Arguments

timepoints

vector of numeric timepoints for which the splines basis will be evaluated

discont_point

a single numeric value that represents where the discontinuity should be

knots

passed to ns or bs. If not NULL, should give knots on either side of discon_point as single vector – they will be separated in the call to discon_point

dfPre

the df for the basis functions defined before the discontinuity point

dfPost

the df for the basis functions defined after the discontinuity point

degree

passed to bs (if applicable)

intercept

Whether to include an intercept (vector of all 1s) for each side of the discontinuity. Note this is different than the argument intercept of either bs or ns, which is set to FALSE.

type

either "ns" or "bs" indicating which splines basis function should be used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
x<-seq(0,10,length=100)
basis<-discont_basis(x,discont_point=3, dfPre=3, dfPost=4, intercept=TRUE)
# Plot of the basis functions
par(mfrow=c(3,3))
for(i in 1:ncol(basis)){
   plot(x,basis[,i],type="l")
   abline(v=3,lty=2)
}
# Use it in a moanin_model object instead of ns/bs:
data(exampleData)
moanin <- create_moanin_model(data=testData, meta=testMeta,
    spline_formula=~Group:discont_basis(Timepoint,dfPre=3,
        dfPost=3,discont=20,intercept=TRUE)+0,
    degrees_of_freedom=6)

NelleV/moanin documentation built on July 28, 2021, 7:34 p.m.