Created
July 13, 2018 15:06
-
-
Save khakieconomics/c65161c27aed270f96574505aa9536cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script checks that the b-spline function in gist https://gist.github.com/khakieconomics/2272cd7f0d61950852622198b26a2d02 | |
# produces something approximating the function in the splines package. | |
library(rstan) | |
expose_stan_functions("b_spline_function.stan") | |
probs <- runif(1000) | |
probs <- probs[order(probs)] | |
test <- b_spline(x = probs, interior_knots = c(.25, .5, .75), order = 5) | |
ncol(test) | |
plot.ts(test) | |
rowSums(test) | |
library(splines) | |
splines_output <- bs(probs, knots = c(.25, .5, .75), degree = 3, intercept = T) | |
plot.ts(splines_output) | |
rowSums(splines_output) | |
# Producing the same output | |
sum(abs(test - splines_output)) | |
# Look -- you can approximate funky functions with b-splines | |
plot.ts(test %*% rnorm(7)) | |
plot.ts(test %*% rnorm(7)) | |
plot.ts(test %*% rnorm(7)) | |
plot.ts(test %*% rnorm(7)) | |
plot.ts(test %*% rnorm(7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment