Skip to content

Instantly share code, notes, and snippets.

View CerebralMastication's full-sized avatar
☠️
brilliantly executing terrible plans

JD Long CerebralMastication

☠️
brilliantly executing terrible plans
View GitHub Profile
drawBoard <- function() {
require(plotrix) # for the draw circle function only
plot(-260:260, -260:260, type="n", xlab="", ylab="", asp = 1, main="Dart Board")
draw.circle(0, 0, 12.7/2, border="purple", lty=1, lwd=1) # bull
draw.circle(0, 0, 31.8/2, border="purple", lty=1, lwd=1) # outer bull
draw.circle(0, 0, 107, border="purple", lty=1, lwd=1)
draw.circle(0, 0, 99, border="purple", lty=1, lwd=1)
draw.circle(0, 0, 162, border="purple", lty=1, lwd=1)
draw.circle(0, 0, 170, border="purple", lty=1, lwd=1)
require(lattice)
myGrid <- expand.grid(1:100,1:100)
names(myGrid) <- c("x1","x2")
myGrid$x3 <- with(myGrid, x1^2 + x2^2)
wireframe(x3 ~ x1 * x2, data = myGrid,
scales = list(arrows = FALSE),
drape = TRUE, colorkey = TRUE
)
#fast example of hex color + transparency in ggplot2
df <- data.frame(x=rnorm(100))
p <- ggplot(df, aes(x=x))
p + geom_density(fill = alpha("#335785", .6))
require(copula)
rmvdc.new <- function (mvdc, n)
{
dim <- mvdc@copula@dimension
u <- rcopula(mvdc@copula, n)
x <- u
for (i in 1:dim) {
if (mvdc@margins[i]=="Johnson") {
qdf.expr <- copula:::asCall(copula:::P0("q", mvdc@margins[i]), list(mvdc@paramMargins[[i]])) } else {
root@domU-12-31-39-0B-8D-81:~# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
libPath <- paste("~/R", pid, "/", sep='')
options(repos=c(CRAN="http://streaming.stat.iastate.edu/CRAN/"))
dir.create(libPath)
install.packages("Hmisc", lib=libPath)
require(Hmisc, lib=libPath)
# ____ __ __ _____ __ _ __
# / __ \___ ____ ________ _________ _/ /____ ____/ / / ___// /_ (_) /_
# / / / / _ \/ __ \/ ___/ _ \/ ___/ __ `/ __/ _ \/ __ / \__ \/ __ \/ / __/
# / /_/ / __/ /_/ / / / __/ /__/ /_/ / /_/ __/ /_/ / ___/ / / / / / /_
# /_____/\___/ .___/_/ \___/\___/\__,_/\__/\___/\__,_/ /____/_/ /_/_/\__/
# /_/
# ____ __
# / __ )___ / /___ _ __
# / __ / _ \/ / __ \ | /| / /
# / /_/ / __/ / /_/ / |/ |/ /
makeDraws <- function(numberOfDraws) {
i <- 1
myOutput <- rep(NA, numberOfDraws) #preallocate the vector so it all goes faster
while (i <= numberOfDraws) {
a <- runif(7, 0, 100) #random draws from a uniform dist 0,100
b <- runif(7, 0, 100)
absDiff <- abs(a-b) #calculate the absolute diff
myOutput[i] <- sum(absDiff) #sum up the diffs and put them in the output vector
i <- i +1
}
################################################################################################
# AUTHOR: JD Long
# PURPOSE: put confidence bands around a sample standard deviation
################################################################################################
#based on example code from here:
#http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/stat_tut/weg/cs_eg/chi_sq_intervals.html
#thanks to Vince Buffallo for sending me the link and pointing me in the right direction.
rm(list = ls())
nchooser <- function(n, r) {
if (n == r) {
#cat("called nchooser(n = r)\n")
return(1)
} else if (r == 0) {
#cat("called nchooser(r = 0)\n")
return(1)
} else
#cat("called nchooser(", n", " r ") \n")