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(tidyverse) | |
| library(lubridate) | |
| # modified from https://stackoverflow.com/questions/48026462/writing-r-function-using-lubridate-package-that-takes-dateex-august-14-and | |
| zodiac_sign <- function(input) | |
| { | |
| zodiac_sign_df <- data.frame(Month = c("March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February"), | |
| Zodiac_Separation_Dt = c(21, 20, 21, 21, 23, 23, 23, 23, 22, 22, 20, 19), | |
| LowerSideZS = c("Pisces", "Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius"), | |
| UpperSideZS = c("Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius", "Pisces"), | 
  
    
      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
    
  
  
    
  | f <- function(x) | |
| { | |
| n <- sum(x) | |
| v <- numeric(n) | |
| prev <- NULL | |
| for (i in 1:n) | |
| { | |
| idx <- x > floor(sum(x)/2) # how many counts are > n/2 | |
| if (sum(idx) >= 2) # error if more than 2 (impossible?) | |
| { | 
  
    
      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(rEDM) | |
| # generate time series | |
| set.seed(42) | |
| ts_length <- 50 | |
| x <- rnorm(ts_length) | |
| # pre-compute distance matrix | |
| x_dists <- as.matrix(dist(x)) | |
| x_dists <- x_dists[, -ts_length] # last point can't be a nearest neighbor | 
  
    
      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
    
  
  
    
  | calc3 <- function(sets) | |
| { | |
| sets <- check_sets(sets) | |
| set_lengths <- vapply(sets, length, 0) | |
| set_order <- order(set_lengths) | |
| sets <- sets[set_order] | |
| set_lengths <- set_lengths[set_order] | |
| n_sets <- length(sets) | |
| set_names <- names(sets) | 
  
    
      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(rEDM) | |
| #### Example 1: a single forward prediction | |
| # Assume we have already done the analysis, finding that the best embedding | |
| # dimension is 2. Our objective is to make multiple 1-step ahead forecasts | |
| # using simplex and E = 2. | |
| dat <- data.frame(yr = as.numeric(time(sunspot.year)), | |
| sunspot_count = as.numeric(sunspot.year)) | |
| E <- 3 | 
  
    
      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
    
  
  
    
  | full_text <- readLines(file, warn = FALSE) | |
| start_par_line <- grep("^\\$par", full_text) | |
| start_objective_line <- grep("^\\$objective", full_text) | |
| param_lines <- seq(from = start_par_line, | |
| to = start_objective_line - 3, | |
| by = 2) | |
| params <- purrr::map_dfc(param_lines, function(line_idx) | |
| { | |
| readr::read_delim(file, delim = " ", | 
  
    
      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(dplyr) | |
| library(microbenchmark) | |
| set.seed(42) | |
| n <- 10000 | |
| df <- data.frame(a = rep(seq(n), 2), | |
| x = rnorm(2 * n)) | |
| group_summarize_mutate <- function(df) | |
| { | 
  
    
      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(likert) | |
| data(pisaitems) | |
| ##### Item 24: Reading Attitudes | |
| items24 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST24Q'] | |
| head(items24); ncol(items24) | |
| names(items24) <- c( | |
| ST24Q01="I read only if I have to.", | |
| ST24Q02="Reading is one of my favorite hobbies.", | 
  
    
      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(drake) | |
| library(furrr) | |
| future::plan(future::multiprocess) | |
| tictoc::tic() | |
| params = data.frame(t = c(1, 2, 3, 1, 2, 3)) | |
| out = purrr::pmap(params, Sys.sleep) | |
| tictoc::toc() | 
  
    
      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(lavaan) | |
| library(visNetwork) | |
| model <- ' | |
| # measurement model | |
| ind60 =~ x1 + x2 + x3 | |
| dem60 =~ y1 + y2 + y3 + y4 | |
| dem65 =~ y5 + y6 + y7 + y8 | |
| # regressions | |
| dem60 ~ ind60 | 
NewerOlder