Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khakieconomics/c65161c27aed270f96574505aa9536cb to your computer and use it in GitHub Desktop.
Save khakieconomics/c65161c27aed270f96574505aa9536cb to your computer and use it in GitHub Desktop.
# 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