Skip to contents

Wrapper around splines::ns() with default Boundary.knots of c(0, max(time)).

Usage

time_spline_basis(time, df, Boundary.knots = c(0, max(time)), ...)

Arguments

time

Continuous time variable, passed directly to splines::ns() as the first argument.

df

Degrees of freedom, passed directly to the df argument of splines::ns().

Boundary.knots

Boundary knots, passed directly to the Boundary.knots argument of splines::ns(). Defaults to c(0, max(time)).

...

Passed to splines::ns().

Value

A matrix of dimension length(time) * df. See the Value section of splines::ns().

Details

time_spline() is primarily useful because it can create the spline basis from time and then re-input time into the spline basis to obtain the predictions in one step. Or, it can calculate predictions from a basis supplied to the basis argument.

Examples

time_spline_basis(Theoph$Time, df = 3)
#>                   1          2           3
#>   [1,]  0.000000000 0.00000000  0.00000000
#>   [2,] -0.031886120 0.07479893 -0.04282603
#>   [3,] -0.070807627 0.16805702 -0.09622083
#>   [4,] -0.125964695 0.31293414 -0.17916995
#>   [5,] -0.169412675 0.48806315 -0.27927835
#>   [6,] -0.115368472 0.64343847 -0.36471168
#>   [7,] -0.005439624 0.64376443 -0.35709820
#>   [8,]  0.187939184 0.56594061 -0.28713439
#>   [9,]  0.336223856 0.48518463 -0.19148429
#>  [10,]  0.432921151 0.40296875 -0.02765524
#>  [11,] -0.140818100 0.37708366  0.76373230
#>  [12,]  0.000000000 0.00000000  0.00000000
#>  [13,] -0.034401475 0.08073620 -0.04622541
#>  [14,] -0.064955064 0.15378594 -0.08804994
#>  [15,] -0.115680778 0.28362245 -0.16238767
#>  [16,] -0.167320051 0.47227657 -0.27028435
#>  [17,] -0.135633825 0.63136451 -0.35893139
#>  [18,] -0.013265008 0.64554696 -0.35878460
#>  [19,]  0.187939184 0.56594061 -0.28713439
#>  [20,]  0.333419797 0.48691072 -0.19397616
#>  [21,]  0.431739620 0.40536423 -0.03443175
#>  [22,] -0.135520210 0.37659567  0.75892036
#>  [23,]  0.000000000 0.00000000  0.00000000
#>  [24,] -0.034401475 0.08073620 -0.04622541
#>  [25,] -0.071965460 0.17089459 -0.09784548
#>  [26,] -0.117472923 0.28861038 -0.16524350
#>  [27,] -0.169412675 0.48806315 -0.27927835
#>  [28,] -0.128469570 0.63656288 -0.36151519
#>  [29,] -0.007403778 0.64422798 -0.35753255
#>  [30,]  0.191599626 0.56411346 -0.28534422
#>  [31,]  0.333419797 0.48691072 -0.19397616
#>  [32,]  0.433186017 0.40237949 -0.02595674
#>  [33,] -0.125686467 0.37569104  0.74998465
#>  [34,]  0.000000000 0.00000000  0.00000000
#>  [35,] -0.044374820 0.10436966 -0.05975672
#>  [36,] -0.074267838 0.17655229 -0.10108478
#>  [37,] -0.121816839 0.30090106 -0.17228051
#>  [38,] -0.170988539 0.50443930 -0.28859376
#>  [39,] -0.135633825 0.63136451 -0.35893139
#>  [40,] -0.013265008 0.64554696 -0.35878460
#>  [41,]  0.187019320 0.56639890 -0.28758125
#>  [42,]  0.334546483 0.48621869 -0.19298014
#>  [43,]  0.431523624 0.40576949 -0.03555843
#>  [44,] -0.162020769 0.37903913  0.78298164
#>  [45,]  0.000000000 0.00000000  0.00000000
#>  [46,] -0.038158943 0.08962167 -0.05131277
#>  [47,] -0.064955064 0.15378594 -0.08804994
#>  [48,] -0.115680778 0.28362245 -0.16238767
#>  [49,] -0.169412675 0.48806315 -0.27927835
#>  [50,] -0.135633825 0.63136451 -0.35893139
#>  [51,] -0.013265008 0.64554696 -0.35878460
#>  [52,]  0.187019320 0.56639890 -0.28758125
#>  [53,]  0.338985800 0.48347180 -0.18898637
#>  [54,]  0.431739620 0.40536423 -0.03443175
#>  [55,] -0.139304250 0.37694418  0.76235743
#>  [56,]  0.000000000 0.00000000  0.00000000
#>  [57,] -0.034401475 0.08073620 -0.04622541
#>  [58,] -0.071965460 0.17089459 -0.09784548
#>  [59,] -0.128360092 0.32003121 -0.18323322
#>  [60,] -0.169587065 0.48959437 -0.28015006
#>  [61,] -0.131520539 0.63449736 -0.36050068
#>  [62,] -0.015207904 0.64596224 -0.35918470
#>  [63,]  0.185173915 0.56731723 -0.28847414
#>  [64,]  0.345443447 0.47941486 -0.18296684
#>  [65,]  0.432737810 0.40336372 -0.02878661
#>  [66,] -0.101522574 0.37347754  0.72799512
#>  [67,]  0.000000000 0.00000000  0.00000000
#>  [68,] -0.031886120 0.07479893 -0.04282603
#>  [69,] -0.062585869 0.14804054 -0.08476042
#>  [70,] -0.117472923 0.28861038 -0.16524350
#>  [71,] -0.169412675 0.48806315 -0.27927835
#>  [72,] -0.136774489 0.63041696 -0.35845070
#>  [73,] -0.015207904 0.64596224 -0.35918470
#>  [74,]  0.183321049 0.56823778 -0.28936584
#>  [75,]  0.333419797 0.48691072 -0.19397616
#>  [76,]  0.432255723 0.40435862 -0.03161162
#>  [77,] -0.129467769 0.37603869  0.75342133
#>  [78,]  0.000000000 0.00000000  0.00000000
#>  [79,] -0.031886120 0.07479893 -0.04282603
#>  [80,] -0.064955064 0.15378594 -0.08804994
#>  [81,] -0.113858263 0.27859466 -0.15950901
#>  [82,] -0.169412675 0.48806315 -0.27927835
#>  [83,] -0.133893864 0.63274194 -0.35962540
#>  [84,] -0.010340372 0.64490104 -0.35816820
#>  [85,]  0.198829456 0.56048783 -0.28175081
#>  [86,]  0.337333680 0.48449791 -0.19048585
#>  [87,]  0.432737810 0.40336372 -0.02878661
#>  [88,] -0.121906461 0.37534379  0.74654816
#>  [89,]  0.000000000 0.00000000  0.00000000
#>  [90,] -0.038158943 0.08962167 -0.05131277
#>  [91,] -0.077687049 0.18499373 -0.10591792
#>  [92,] -0.120102880 0.29601578 -0.16948345
#>  [93,] -0.169412675 0.48806315 -0.27927835
#>  [94,] -0.133893864 0.63274194 -0.35962540
#>  [95,] -0.013265008 0.64554696 -0.35878460
#>  [96,]  0.200617994 0.55958737 -0.28084975
#>  [97,]  0.321779716 0.49394857 -0.20388285
#>  [98,]  0.426370035 0.41379984 -0.05681476
#>  [99,] -0.145360341 0.37750232  0.76785698
#> [100,]  0.000000000 0.00000000  0.00000000
#> [101,] -0.046843101 0.11024514 -0.06312071
#> [102,] -0.093041003 0.22359645 -0.12801985
#> [103,] -0.117472923 0.28861038 -0.16524350
#> [104,] -0.169917035 0.49263118 -0.28187848
#> [105,] -0.132714772 0.63363118 -0.36007016
#> [106,] -0.010340372 0.64490104 -0.35816820
#> [107,]  0.192509988 0.56365816 -0.28489600
#> [108,]  0.353680730 0.47412303 -0.17488729
#> [109,]  0.432737810 0.40336372 -0.02878661
#> [110,] -0.090224045 0.37244888  0.71769159
#> [111,]  0.000000000 0.00000000  0.00000000
#> [112,] -0.031886120 0.07479893 -0.04282603
#> [113,] -0.062585869 0.14804054 -0.08476042
#> [114,] -0.113858263 0.27859466 -0.15950901
#> [115,] -0.168652039 0.48185238 -0.27574137
#> [116,] -0.129701084 0.63575371 -0.36111993
#> [117,] -0.013265008 0.64554696 -0.35878460
#> [118,]  0.187939184 0.56594061 -0.28713439
#> [119,]  0.335107293 0.48587347 -0.19248177
#> [120,]  0.432921151 0.40296875 -0.02765524
#> [121,] -0.118883480 0.37506632  0.74379911
#> [122,]  0.000000000 0.00000000  0.00000000
#> [123,] -0.031886120 0.07479893 -0.04282603
#> [124,] -0.062585869 0.14804054 -0.08476042
#> [125,] -0.115680778 0.28362245 -0.16238767
#> [126,] -0.169045005 0.48497498 -0.27751992
#> [127,] -0.134477691 0.63228862 -0.35939765
#> [128,] -0.008383944 0.64445532 -0.35774656
#> [129,]  0.191599626 0.56411346 -0.28534422
#> [130,]  0.335107293 0.48587347 -0.19248177
#> [131,]  0.432255723 0.40435862 -0.03161162
#> [132,] -0.124174302 0.37555209  0.74861003
#> attr(,"degree")
#> [1] 3
#> attr(,"knots")
#> [1] 1.040000 7.023333
#> attr(,"Boundary.knots")
#> [1]  0.00 24.65
#> attr(,"intercept")
#> [1] FALSE
#> attr(,"class")
#> [1] "ns"     "basis"  "matrix"