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(pwr) | |
| # Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes respectively. | |
| f <- seq(0.05, 0.5, 0.05) | |
| pwrANOVA <- function(i){ | |
| z <- pwr.anova.test(k = 3, n = NULL, f = i, sig.level = 0.05, power = 0.8) | |
| as.data.frame(t(unlist(z))) |
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 glob | |
| import json | |
| from pymongo import MongoClient | |
| # fill in hostname and port | |
| HOST = "datalake2.local" #hostname | |
| PORT = 27017 | |
| # connect to client | |
| client = MongoClient(HOST, PORT) |
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(jsonlite) | |
| dir <- "./data/" # files in this folder | |
| files <- list.files(dir) | |
| files <- paste0(dir,files[grepl("Flume",files)]) | |
| readIn <- function(fileName){ | |
| stream_in(file(fileName,open="r")) | |
| } |
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) | |
| path <-"~/Dropbox_UNCC/Dropbox (UNC Charlotte)/xai-cfpb/data/Consumer_Complaints.csv" | |
| Consumer_Complaints <- read_csv(path) %>% | |
| rename(text = `Consumer complaint narrative`) %>% | |
| filter(!is.na(text)) %>% | |
| mutate(Bank = case_when( | |
| str_detect(Company, "BANK OF") ~ "BAC", | |
| str_detect(Company, "CITIBANK") ~ "CITI", | |
| str_detect(Company, "JPMORGAN") ~ "JPM", |
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
| #turn off GPU if needed | |
| #Sys.setenv("CUDA_VISIBLE_DEVICES" = -1) | |
| library(telegram.bot); library(keras); library(lime); library(magick); library(httr); library(tidyverse) | |
| # keras pre-trained model vgg16 | |
| model <- application_vgg16(weights = "imagenet",include_top = TRUE) | |
| # make sure to set up auth via .environment | |
| # see https://github.com/ebeneditos/telegram.bot/wiki/Tutorial-%E2%80%93-Building-an-R-Bot-in-3-steps |
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
| # make sure you have tidyverse installed | |
| # install it using: "install.packages('tidyverse')" | |
| library(tidyverse) | |
| # set parameters | |
| n_part = 10 # number of participants per group | |
| n_task = 5 # number of tasks | |
| low = | |
| data_frame( |
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
| ## load ggplot2 | |
| library(ggplot2) | |
| ## function to make basic hex sticker | |
| make_hexsticker <- function(pkg, pkg_size, pkg_color, pkg_y = -.33, | |
| bg, border, | |
| icon, icon_color, icon_size, family, face = "plain", | |
| url, url_size = 8, url_x = .225, url_y = -.76, | |
| url_color = "transparent", | |
| fa = "Font Awesome 5 Brands", |
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(rtweet) | |
| # make sure to set up auth, see https://rtweet.info/index.html | |
| rt <- stream_tweets( | |
| q = c(-125, 26, -65, 49), # united states | |
| timeout = 30, # run for 30 seconds; set to Inf to run indefinitely | |
| file_name = NULL, # name of file name e.g., paste0("stream",gsub(" |-|:", "", Sys.time()),".json") | |
| dir = NULL # directory to put files into | |
| ) |
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
| # from https://rdrr.io/github/thomasp85/lime/src/R/plot_image.R | |
| tidy_raster <- function(im) { | |
| if (!requireNamespace('magick', quietly = TRUE)) { | |
| stop('The magick package is required for image explanation', call. = FALSE) | |
| } | |
| raster <- as.raster(im) | |
| data.frame(x = rep(seq_len(ncol(raster)), nrow(raster)), | |
| y = rep(seq_len(nrow(raster)), each = ncol(raster)), | |
| colour = as.vector(raster), |
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
| # see https://arxiv.org/abs/1709.03856 | |
| # see http://www.bnosac.be/index.php/blog/86-neural-text-modelling-with-r-package-ruimtehol | |
| library(ruimtehol) | |
| library(tidyverse) | |
| df <- read_csv("complaints-2019-03-30_10_53.csv", | |
| col_types = cols(`Complaint ID` = col_character(), | |
| `Date received` = col_character())) %>% | |
| rename(text = `Consumer complaint narrative`) |