This file contains 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
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?') |
This file contains 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
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)) |
This file contains 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
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) |
This file contains 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
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)) |
This file contains 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
# 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") |
This file contains 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
differentiate(x::Number, target::Symbol) = 0 | |
function differentiate(s::Symbol, target::Symbol) | |
if s == target | |
return 1 | |
else | |
return 0 | |
end | |
end |
This file contains 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("ggplot2") | |
n.sims <- 100 | |
max.n.vars <- 100 | |
n.obs <- 100 | |
res <- data.frame() | |
for (sim in 1:n.sims) | |
{ |
This file contains 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
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]) |
This file contains 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
############################################################################## | |
# | |
# A macro for doing delegation | |
# | |
# This macro call | |
# | |
# @delegate MyContainer.elems [:size, :length, :ndims, :endof] | |
# | |
# produces this block of expressions | |
# |
This file contains 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
# 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 |
OlderNewer