This file contains hidden or 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
| library(ggplot2) | |
| set.seed(123) | |
| # simulated data | |
| n <- 100 | |
| nx <- ny <- 500 | |
| x <- rbinom(n, nx, 0.22) | |
| y <- rbinom(n, ny, 0.21) |
This file contains hidden or 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
| data { | |
| int<lower=3> n; | |
| vector[n] y; | |
| int<lower=0> h; | |
| } | |
| parameters { | |
| real<lower=0, upper=1> alpha; | |
| real<lower=0, upper=1> beta; | |
| real<lower=0> sigma; | |
| vector[2] mu_init; |
This file contains hidden or 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
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| // [[Rcpp::export]] | |
| List cpp_rle2( | |
| const NumericVector& x, | |
| const double h = 0, | |
| const double eps = 1e-16 | |
| ) { |
This file contains hidden or 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
| import numpy as np | |
| from sklearn.base import BaseEstimator, ClassifierMixin | |
| from sklearn.ensemble import IsolationForest | |
| from sklearn.covariance import EllipticEnvelope | |
| from sklearn.svm import OneClassSVM | |
| def mode(x): | |
| (values, counts) = np.unique(x, return_counts = True) |
This file contains hidden or 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
| lst <- function(...) { | |
| dots <- list(...) | |
| call <- match.call() | |
| names(dots) <- sapply(substitute(...()), as.character) | |
| dots | |
| } | |
| funs <- lst(mode, typeof, class, is.atomic, is.array, is.vector, is.numeric, is.character, is.logical, is.matrix, is.data.frame, is.list) | |
| tests <- lst( |
This file contains hidden or 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
| library(extraDistr) | |
| bins <- function(x, n = 512L) { | |
| x <- x[!is.na(x)] | |
| h <- diff(range(x))/(n-4) | |
| mids <- seq(min(x)-2*h, max(x)+2*h, length.out = n) | |
| breaks <- c(mids[1L] - h, mids + h) | |
| counts <- unname(tapply(x, cut(x, breaks), length, | |
| default = 0L)) |
This file contains hidden or 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
| set.seed(123) | |
| x <- rnorm(7) | |
| dx <- density(x) | |
| plot(dx) | |
| f <- approxfun(dx, yleft = 0, yright = 0) |
This file contains hidden or 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
| set.seed(123) | |
| N <- 1e5 | |
| mu <- c(2,4,6) | |
| sigma <- rep(0.5, 3) | |
| lambda <- (1:3)/6 | |
| dat <- c( |
This file contains hidden or 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
| ptmp <- par(mfrow=c(2,2), mar = c(3,3,3,3)) | |
| set.seed(123) | |
| n <- 7 | |
| x <- rnorm(n, sd = 3) | |
| K <- function(x) dnorm(x) |
This file contains hidden or 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
| priors <- c(0, 0.001, 0.333, 0.5, 1) | |
| s <- c(0, 1, 1, 5, 5) | |
| f <- c(1, 1, 2, 1, 25) | |
| dbeta2 <- function(x, prior1, prior2 = prior1) { |