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
| fn_list <- function(y){ | |
| y$a <- y$a + 1 | |
| return(y) | |
| } | |
| fn_env <- function(y){ | |
| y$a <- y$a + 1 | |
| } | |
| x <- list(a=matrix(1:9,3,3),b=matrix(1:36,6,6)) |
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
| # for more info on comparing floats, this blog post is very informative: https://bitbashing.io/comparing-floats.html | |
| # for more info on how floating point mathematics compares to "real" mathematics, see https://www.tandfonline.com/doi/full/10.1080/10724117.2019.1611061 | |
| # helper function for approximate equality between floats | |
| approx_equal <- function(a, b, tol = sqrt(.Machine$double.eps)) { | |
| abs(a - b) <= tol | |
| } | |
| # use instead of the %in% operator to check if floats are in sets of other floats | |
| `%in_approx%` <- function(x, table) { |
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
| rm(list=ls());gc();dev.off() | |
| library(sna) | |
| set.seed(4395834L) | |
| n <- 100 | |
| w1<-rgraph(n) #Draw the AR matrix | |
| w2<-w1 #Draw the MA matrix | |
| x<-matrix(rnorm(n*5),n,5) #Draw some covariates | |
| r1<-0.2 #Set the model parameters |
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 <functional> | |
| #include <Rcpp.h> | |
| // [[Rcpp::plugins(cpp14)]] | |
| using my_lambda = std::function<double(const double)>; | |
| typedef struct lambda_st { | |
| my_lambda func; |
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 <random> | |
| #include <array> | |
| #include <iostream> | |
| #include <limits> | |
| #include <random> | |
| #include <Rcpp.h> | |
| // [[Rcpp::plugins(cpp14)]] |
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
| // Example program | |
| #include <iostream> | |
| #include <string> | |
| int main(void) { | |
| int arr[13] = {1, 2, 2, 123121, 123121, 3, 5, 6 , 7, 7, 14, 2, 16}; | |
| int len = 13; | |
| int unique[len]; |
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 <iostream> | |
| #include <iomanip> | |
| #include <string> | |
| #include <string> | |
| #include <memory> | |
| class impl_base { | |
| public: | |
| /* ctor & dtor */ |
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
| xx <- matrix(c(16,3,2,13,5,10,11,8,9,6,7,12,4,15,14,1),nrow = 4,ncol = 4,byrow = T) | |
| xxx <- xx/rowSums(xx) | |
| xeig <- eigen(xxx) | |
| xvecs <- xeig$vectors | |
| lvecs <- MASS::ginv(xvecs) | |
| pi_eq <- lvecs[1,]/sum(lvecs[1,]) | |
| pi_eq |
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
| // destination: array to fill the drawn "balls" | |
| // source: number of "balls" in each "urn" | |
| // n: number of draws to take | |
| // k: number of "urns" | |
| void rmhyper(int* destination, int const* source, int n, int k){ | |
| int sum, x, y; | |
| size_t i; | |
| if(n < 0 || k < 0){Rcpp::stop("Invalid parameters of distribution");} | |
| // total number of "balls" |