A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | ||||||||||||||||||||||||
2 | Author | Chad Milando, PhD, MS | cmilando@bu.edu | Interested in similar spreadsheets? see here: | ||||||||||||||||||||
3 | Date | 7.18.2023 | https://chadmilando.com/teaching/ | |||||||||||||||||||||
4 | ||||||||||||||||||||||||
5 | A walkthrough of B-spline basis functions | Recommended view % is 75% | ||||||||||||||||||||||
6 | if downloaded, some graph formatting gets distored | |||||||||||||||||||||||
7 | Helpful source | |||||||||||||||||||||||
8 | https://www.hsph.harvard.edu/wp-content/uploads/sites/565/2018/08/572Spr07-BasisMethods-4up.pdf | *Others listed in the Appendix | ||||||||||||||||||||||
9 | ||||||||||||||||||||||||
10 | Sheet overview | https://en.wikipedia.org/wiki/B-spline | ||||||||||||||||||||||
11 | ||||||||||||||||||||||||
12 | bs_calc | calculates recursive functions | ||||||||||||||||||||||
13 | X | plots Y ~ X | ||||||||||||||||||||||
14 | b0 | plots Y ~ b0 | ||||||||||||||||||||||
15 | b1 | plots Y ~ b1 | ||||||||||||||||||||||
16 | b2 | plots Y ~ b2 | ||||||||||||||||||||||
17 | b3 | plots Y ~ b3 | ||||||||||||||||||||||
18 | Appendix | references I found in creating this | In these functions, "i" is the spline function (e.g., 1 knot can mean 2+ spline functions, but it could be the left side and right side) | |||||||||||||||||||||
19 | and k is the "order" or "degree" (so degree = 3 is cubic polynomila, degree = 2 is quadratic polynomial) | |||||||||||||||||||||||
20 | R code to replicate each page is listed in Red font to the right of each page | |||||||||||||||||||||||
21 | ||||||||||||||||||||||||
22 | Problem statement | |||||||||||||||||||||||
23 | ||||||||||||||||||||||||
24 | you have an independent variable x, and a dependent variable y | |||||||||||||||||||||||
25 | They have some relationship described graphically -> | |||||||||||||||||||||||
26 | (the true relationship is piecewise described on sheet X below) | |||||||||||||||||||||||
27 | ||||||||||||||||||||||||
28 | You don't know the true relationship, and it doesn't seem linear | |||||||||||||||||||||||
29 | and it looks like there is a discontinuity at x = 0.50 | a | ||||||||||||||||||||||
30 | So you decide to split X up into components so you can | |||||||||||||||||||||||
31 | model the relationship between X and Y more flexibly | |||||||||||||||||||||||
32 | with a single knot at x = 0.5 | |||||||||||||||||||||||
33 | Specifically, you want to use B-splines with various degrees (knowing that many other basis functions exist that could split X up differently) | |||||||||||||||||||||||
34 | ||||||||||||||||||||||||
35 | Below, you compare a linear model of Y ~ X, or linear models of Y ~ bs(X, degree = {0, 1, 2, or 3}) | |||||||||||||||||||||||
36 | ||||||||||||||||||||||||
37 | ||||||||||||||||||||||||
38 | ||||||||||||||||||||||||
39 | ||||||||||||||||||||||||
40 | ||||||||||||||||||||||||
41 | ||||||||||||||||||||||||
42 | ||||||||||||||||||||||||
43 | ||||||||||||||||||||||||
44 | ||||||||||||||||||||||||
45 | ||||||||||||||||||||||||
46 | ||||||||||||||||||||||||
47 | ||||||||||||||||||||||||
48 | ||||||||||||||||||||||||
49 | ||||||||||||||||||||||||
50 | ||||||||||||||||||||||||
51 | ||||||||||||||||||||||||
52 | ||||||||||||||||||||||||
53 | ||||||||||||||||||||||||
54 | ||||||||||||||||||||||||
55 | ||||||||||||||||||||||||
56 | ||||||||||||||||||||||||
57 | ||||||||||||||||||||||||
58 | ||||||||||||||||||||||||
59 | ||||||||||||||||||||||||
60 | ||||||||||||||||||||||||
61 | ||||||||||||||||||||||||
62 | ||||||||||||||||||||||||
63 | ||||||||||||||||||||||||
64 | ||||||||||||||||||||||||
65 | ||||||||||||||||||||||||
66 | ||||||||||||||||||||||||
67 | ||||||||||||||||||||||||
68 | ||||||||||||||||||||||||
69 | ||||||||||||||||||||||||
70 | ||||||||||||||||||||||||
71 | ||||||||||||||||||||||||
72 | ||||||||||||||||||||||||
73 | ||||||||||||||||||||||||
74 | ||||||||||||||||||||||||
75 | ||||||||||||||||||||||||
76 | ||||||||||||||||||||||||
77 | ||||||||||||||||||||||||
78 | ||||||||||||||||||||||||
79 | ||||||||||||||||||||||||
80 | ||||||||||||||||||||||||
81 | ||||||||||||||||||||||||
82 | ||||||||||||||||||||||||
83 | ||||||||||||||||||||||||
84 | ||||||||||||||||||||||||
85 | ||||||||||||||||||||||||
86 | ||||||||||||||||||||||||
87 | ||||||||||||||||||||||||
88 | ||||||||||||||||||||||||
89 | ||||||||||||||||||||||||
90 | ||||||||||||||||||||||||
91 | ||||||||||||||||||||||||
92 | ||||||||||||||||||||||||
93 | ||||||||||||||||||||||||
94 | ||||||||||||||||||||||||
95 | ||||||||||||||||||||||||
96 | ||||||||||||||||||||||||
97 | ||||||||||||||||||||||||
98 | ||||||||||||||||||||||||
99 | ||||||||||||||||||||||||
100 |