Skip to content

Instantly share code, notes, and snippets.

@DoktorMike
DoktorMike / plotInfluence.R
Last active May 24, 2018 02:12
This is my influence plot function. It uses ggplot to visualize leverage and studentized errors in a balloon plot where the balloon size is scaled by Cook's distance.
plotInfluence <- function (model, fill="white",
outline="black", size=30) {
require(ggplot2)
if(!inherits(model, "lm"))
stop("You need to supply an lm object.")
df<-data.frame(Residual=rstudent(model),
Leverage=hatvalues(model),
Cooks=cooks.distance(model),
Observation=names(hatvalues(model)),
stringsAsFactors=FALSE)
@DoktorMike
DoktorMike / passByReference.R
Created March 15, 2016 08:17
An example of passing matrix by reference in R using the R6 framework
library(R6)
library(pryr)
# Class defining a storage for a local matrix
LocalMatrix <- R6Class("LocalMatrix", public = list(x = NULL))
# Class defining a container for a shared matrix
SharedMatrix <- R6Class("SharedMatrix", public = list(e = LocalMatrix$new()))
# Initialize a shared container containing a local matrix and print it
@DoktorMike
DoktorMike / modevsmean.R
Created January 2, 2017 12:38
Plot of Mode vs Mean Estimation Using Skew Normal Distribution
require(sn)
require(ggplot2)
x<-rsn(3000, 10, 30, 5)
ggplot(data.frame(counter=1, x=x), aes(x=x)) + theme_minimal() + ylab("Probability density") + geom_density() + geom_rug() + geom_vline(xintercept = 40, color="red") + geom_vline(xintercept = 22, color="orange")
@DoktorMike
DoktorMike / mp4togif.sh
Created May 3, 2017 10:55
Convert mp4 video to gif
#!/bin/bash
mdir frames
ffmpeg -i video.mp4 -r 5 'frames/frame-%03d.jpg'
cd frames
convert -delay 20 -loop 0 *.jpg myimage.gif
cd ..
#rm -rf frames
@DoktorMike
DoktorMike / decryptunzip.sh
Created January 4, 2018 12:04
Encrypt / Decrypt and compress / uncompress a folder on a linux system
#!/bin/bash
# Usage ./decryptunzip.sh myfolder.tar.xz.gpg
gpg -d "$1" | tar -xJvf -
@DoktorMike
DoktorMike / drawgraph.sh
Last active January 23, 2018 09:10
Sample graph generation using Graphviz dot
#!/bin/bash
dot -Tpng simpledag.dot > simpledag.png
@DoktorMike
DoktorMike / multinomial_visualization.R
Created September 19, 2018 12:36
Illustration the probability and variance of 5 classes in a 10 trail setting
multinomial_visualization <- function(n=10, p=runif(5)){
v<-sapply(p, function(x) n*x*(1-x))
curve(n*x*(1-x), 0, 1)
points(p, v, col="red", pch=20)
}
@DoktorMike
DoktorMike / pcaplotexample.R
Created October 17, 2018 10:51
PCA plot of sample data
library(tibble)
library(dplyr)
library(tidyr)
if(!require(ggbiplot)){
install.packages('devtools')
library(devtools)
devtools::install_github('vqv/ggbiplot')
}
@DoktorMike
DoktorMike / compresspdf.sh
Last active October 28, 2018 22:30
Compress a pdf to a much smaller size
#!/bin/bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf "$1"
@DoktorMike
DoktorMike / dockercleanup.sh
Created April 22, 2019 18:27
Docker Cleanup Script
#!/bin/bash
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker volume rm $(sudo docker volume ls -q)