Skip to content

Instantly share code, notes, and snippets.

Avatar

John Myles White johnmyleswhite

View GitHub Profile
View GOL.R
counts <- read.csv('counts.csv', header = TRUE, sep = '\t')
counts <- transform(counts, logCount = log(Count))
ggplot(counts, aes(x = Length, y = logCount)) +
geom_point() +
geom_smooth(method = 'lm') +
xlab('Length of Entire Word') +
ylab('Log Number of Occurrences of Spelling') +
opts(title = 'How Many O\'s Does It Take to Make a GOL?')
View gist:3734935
df <- data.frame(Fahrenheit = c(212, 32),
Celsius = c(100, 0))
lm.fit <- lm(Fahrenheit ~ Celsius, data = df)
summary(lm.fit)
predict(lm.fit, data.frame(Celsius = 40))
View gist:3734955
df <- data.frame(IsSpam = c(1, 1, 0, 1),
MentionsViagra = c(0, 1, 0, 1),
MentionsNigeria = c(1, 1, 0, 0))
logistic.fit <- glm(IsSpam ~ MentionsViagra + MentionsNigeria,
data = df,
family = binomial(link = "logit"))
summary(logistic.fit)
@johnmyleswhite
johnmyleswhite / gist:3735101
Created Sep 17, 2012
Toy Regression w/ Errors
View gist:3735101
df <- data.frame(Fahrenheit = c(212, 102, 32),
Celsius = c(100, 50, 0))
lm.fit <- lm(Fahrenheit ~ Celsius, data = df)
summary(lm.fit)
predict(lm.fit, data.frame(Celsius = 40))
@johnmyleswhite
johnmyleswhite / gist:4195980
Created Dec 3, 2012
Imitating plyr and reshape in Julia
View gist:4195980
# A top priority for making DataFrames useful in Julia is the development of
# good documentation and a nice API for doing plyr+reshape style operations
# in Julia. This Gist is a draft of such documentation.
load("DataFrames")
using DataFrames
load("RDatasets")
baseball = RDatasets.data("plyr", "baseball")
@johnmyleswhite
johnmyleswhite / differentiate.jl
Last active Nov 19, 2021
Symbolic Differentiation in Julia
View differentiate.jl
differentiate(x::Number, target::Symbol) = 0
function differentiate(s::Symbol, target::Symbol)
if s == target
return 1
else
return 0
end
end
@johnmyleswhite
johnmyleswhite / gist:4596783
Created Jan 22, 2013
Entering more variables into a linear regression and then checking the p-values for each is a bad thing to do.
View gist:4596783
library("ggplot2")
n.sims <- 100
max.n.vars <- 100
n.obs <- 100
res <- data.frame()
for (sim in 1:n.sims)
{
@johnmyleswhite
johnmyleswhite / gist:5222915
Created Mar 22, 2013
Comparing two ways of computing expectations in Julia
View gist:5222915
using Distributions
using Calculus
using Benchmark
function expectation(distr::Distribution,
g::Function,
epsilon::Real)
f = x -> pdf(distr, x)
endpoints = map(e -> quantile(distr, e), (epsilon, 1 - epsilon))
integrate(x -> f(x) * g(x), endpoints[1], endpoints[2])
View gist:5225361
##############################################################################
#
# A macro for doing delegation
#
# This macro call
#
# @delegate MyContainer.elems [:size, :length, :ndims, :endof]
#
# produces this block of expressions
#
@johnmyleswhite
johnmyleswhite / gist:5248212
Created Mar 26, 2013
The Joys of Sparsity: Forward Stagewise Regression
View gist:5248212
# Generate (x, y) data with a sparse set of active predictors
# prob controls the frequency of predictors having zero effect
function simulate_date(n::Integer, p::Integer, prob::Real)
x = randn(n, p)
beta = randn(p)
for j in 1:p
if rand() < prob
beta[j] = 0.0
end
end