Skip to content

Instantly share code, notes, and snippets.

View demel's full-sized avatar

De'Mel demel

View GitHub Profile
@demel
demel / returnData.R
Created January 12, 2016 00:32 — forked from dmpe/returnData.R
returnData.R used for benchmarking RSocrata row binding
# An interface to data hosted online in Socrata data repositories
# This is the main file which uses other functions to download data from a Socrata repositories
#
# Author: Hugh J. Devlin, Ph.D et al. 2013-08-28
###############################################################################
# library("httr") # for access to the HTTP header
# library("jsonlite") # for parsing data types from Socrata
# library("mime") # for guessing mime type
# library("geojsonio") # for geospatial json
## Reproducible package management for R:
install.packages("devtools")
library(devtools)
#devtools::install_github("rstudio/packrat")
# More info @ http://rstudio.github.io/packrat/
## great shiny apps
install.packages("radiant", repos = "http://vnijs.github.io/radiant_miniCRAN/")
@demel
demel / server.R
Created September 29, 2015 19:18 — forked from reinholdsson/server.R
Shiny + Redis example
library(rredis)
shinyServer(function(input, output) {
output$show <- renderText({
redisConnect()
res <- redisGet(input$key)
redisClose()
return(res)
})
@demel
demel / server.R
Last active September 9, 2015 00:01 — forked from withr/server.R
Encrypt password with md5 for Shiny-app.
library(shiny)
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {
@demel
demel / k-NN.adoc
Last active August 29, 2015 14:25

Movie Recommendations with k-Nearest Neighbors and Cosine Similarity


Introduction

The k-nearest neighbors (k-NN) algorithm is among the simplest algorithms in the data mining field. Distances / similarities are calculated between each element in the data set using some distance / similarity metric ^[1]^ that the researcher chooses (there are many distance / similarity metrics), where the distance / similarity between any two elements is calculated based on the two elements' attributes. A data element’s k-NN are the k closest data elements according to this distance / similarity.


1. A distance metric measures distance; the higher the distance the further apart the neighbors. A similarity metric measures similarity; the higher the similarity the closer the neighbors.
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
## data input (number of reads mapped to each category)
total=100
rRNA=5 # mapped to nuclear rRNA regions
mtRNA=7 # mapped to mitochondria genome
# for the rest of above, then we divide into different category, like http://www.biomedcentral.com/1741-7007/8/149 did.
intergenic=48
introns=12
exons=30
upstream=3
downstream=6
doInstall <- TRUE
toInstall <- c("ggplot2", "cluster", "MASS", "smacof")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Generate a matrix of dissimilarities from pairwise correlations
data(breakfast) # Preference orderings of breakfast items, from smacof
corrMat <- cor(breakfast, use = "pair")
distMat <- dist(corrMat)
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("maptools", "rgdal", "ggplot2", "spatstat", "RColorBrewer")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Taking an online compressed shapefile, and opening it in R
# From http://stackoverflow.com/a/3053883
temp <- tempfile() # 110th & 111th Congressional District Shapefiles
download.file("http://www.census.gov/geo/cob/bdy/cd/cd110shp/cd99_110_shp.zip",
temp) # See http://www.census.gov/geo/www/cob/cd110.html#shp
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("sna", "ggplot2", "Hmisc", "reshape2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Empty ggplot2 theme
new_theme_empty <- theme_bw()
new_theme_empty$line <- element_blank()
new_theme_empty$rect <- element_blank()
new_theme_empty$strip.text <- element_blank()