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
require(caret) | |
#load some data | |
data(USArrests) | |
### Prepare Data (postive observations) | |
# add a column to be the strata. In this case it is states, it can be sites, or other locations | |
# the original data has 50 rows, so this adds a state label to 10 consecutive observations | |
USArrests$state <- c(rep(c("PA","MD","DE","NY","NJ"), each = 5)) | |
# this replaces the existing rownames (states) with a simple numerical index |
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
##### Your code leading up to this point ###### | |
# initialize active cases | |
SWDetail$active_cases <- 0 | |
SWDetail[1,"active_cases"] <- 1 | |
# initialize most recent cases | |
SWDetail$last_case_given <- 0 | |
SWDetail[1,"last_case_given"] <- 1 | |
# resorting this by date | |
cps_test_assignment <- cps_test_assignment[order(cps_test_assignment$assignment_date),] |
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('foreach') | |
library('ggplot2') | |
library('gganimate') | |
# library('animation') # require for original code | |
library('reshape2') | |
library('doParallel') # for multicore support | |
## Guts and working concept from post below. | |
## http://johnramey.net/blog/2011/06/05/conways-game-of-life-in-r-with-ggplot2-and-animation/#comments | |
## I updated ggplot, melt, varnames, gganimate, and faded cells |
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("data.table") | |
library("rowr") | |
library("inTrees") | |
library("dplyr") | |
library("randomForest") | |
library("xtable") | |
library("caret") | |
library("gbm") | |
library("rpart") | |
library("reshape2") |
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
#Package installs ------------------------------------------------------------- | |
load.fun <- function(x) { | |
x <- as.character(x) | |
if(isTRUE(x %in% .packages(all.available=TRUE))) { | |
eval(parse(text=paste("require(", x, ")", sep=""))) | |
print(paste(c(x, " : already installed; requiring"), collapse='')) | |
} else { | |
#update.packages() | |
print(paste(c(x, " : not installed; installing"), collapse='')) | |
eval(parse(text=paste("install.packages('", x, "')", sep=""))) |
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
######################################################################## | |
### 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 |