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
library(corrplot) | |
library(viridis) | |
library(stargazer) | |
library(tidyverse) | |
library(dplyr) | |
library(sf) | |
library(tigris) | |
library(ggplot2) | |
library(rgdal) | |
library(maptools) |
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
library(tidyverse) | |
g <- glimpse | |
g(iris) | |
dat <- iris %>% | |
nest(data = c(-Species)) | |
dat$data[[1]] |
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
### Example of ggplot code for multiclass confusion matrix with caret::confusionMatrix and ggplot | |
### `Example_plot1` is the result of applying `caret::confusionMatrix()` to the outcome ... | |
### of a model that included a reference class and a predicted class; both as factors | |
### calling `as.data.frame(Example_plot1$table)` casts the predicted class frequency table from the ... | |
### `caret::confusionMatrix()` object into a nice long format table of columns `Reference`, `Prediction`, and `Freq`. | |
### Do this for a bunch of models, and then use `cowplot::plot_grid()` to arrange them. | |
library(tidyverse) | |
library(cowplot) | |
library(caret) |
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
library('rnoaa') | |
library("tidyverse") | |
library("lubridate") | |
library("ggrepel") | |
token = 'GET YOUR API KEY at: http://www.ncdc.noaa.gov/cdo-web/token' | |
locs <- ncdc_locs(locationcategoryid='CITY', sortfield='name', sortorder='desc', token = token, limit = 800) | |
loc_data <- locs$data | |
dplyr::filter(loc_data, grepl(", PA",loc_data$name)) |
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
######################################################################## | |
### Bespoke Neural Network R code attributed to: David Selby | |
### From blog post: http://selbydavid.com/2018/01/09/neural-network/ | |
### Adapted here for making animated GIF of node density | |
### output gifs compiled at gifmaker.me for final output | |
### output tweeted here: | |
### https://twitter.com/Md_Harris/status/951257342418608128 | |
######################################################################## | |
two_spirals <- function(N = 200, |
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
### ------- Load Packages ---------- ### | |
library("purrr") | |
library("future") | |
library("dplyr") | |
library("randomForest") | |
library("rsample") | |
library("ggplot2") | |
library("viridis") | |
### ------- Helper Functions for map() ---------- ### | |
# breaks CV splits into train (analysis) and test (assessmnet) sets |
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
library("ggraph") | |
library("igraph") | |
library("ggplot2") | |
# create some simulated sites that contain various numbers of measurements on a regular grid | |
site_dat <- data.frame(size = rep(c("A","B","C","D"), times = c(3,4,8,5)), | |
x = c(25,26,26, | |
40,41,41,40, | |
15,16,17,17,16,15,15,16, | |
40,41,42,42,41), |
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
data { | |
int<lower=0> N; | |
int<lower=0> P; | |
matrix[P, P] K; | |
vector[N] y; | |
//real lambda; | |
} | |
transformed data{ | |
// this block results verified with KRR_logit() analytical solution | |
vector[N] q; |
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
### Simualte some one-dimensional data | |
# Constants | |
a = 50 | |
b = 50 | |
c = 80 | |
N = 10 # low dimensions help to visualize matrix | |
#Limits | |
x_upper <- 100 | |
x_lower <-.01 | |
spacing = (x_upper-x_lower)/(N-1) |
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
KRR_logit_predict <- function(test_data, train_data, alphas_pred, sigma, dist_method = "Euclidean", progress = TRUE){ | |
# example: KRR_logit_predict(test_dat, train_dat, theSol, sigma) | |
pred_yhat <- matrix(nrow = length(test_data), ncol = length(train_data)) | |
if(isTRUE(progress)){ | |
total_iter <- length(test_data) * length(train_data) | |
pb <- txtProgressBar(min = 0, max = total_iter, style = 3) | |
} | |
iter <- 0 | |
for(j in 1:length(test_data)){ | |
for(i in 1:length(train_data)){ |