Skip to content

Instantly share code, notes, and snippets.

Markus Gesmann mages

Block or report user

Report or block mages

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ModelPlot_brms.R
library(lattice)
key <- list(
rep=FALSE,
lines=list(col=c("#00526D", "blue"), type=c("p","l"), pch=1),
text=list(lab=c("Observation","Estimate")),
rectangles = list(col=adjustcolor("yellow", alpha.f=0.5), border="grey"),
text=list(lab="95% Prediction credible interval"))
xyplot(l.95..CI + u.95..CI + Estimate + Units_sold ~ Temperature | Model,
data=modelData, as.table=TRUE, main="Ice cream model comparision",
xlab="Temperatures (C)", ylab="Units sold",
View ModelOutput_brms.R
modelData <- data.frame(
Model=factor(c(rep("Linear model", n),
rep("Log-transformed LM", n),
rep("Poisson (log)",n),
rep("Binomial (logit)",n)),
levels=c("Linear model",
"Log-transformed LM",
"Poisson (log)",
"Binomial (logit)"),
ordered = TRUE),
View log.lin.mod_brms.R
log.lin.mod
## Family: gaussian (identity)
## Formula: log_units ~ temp
## Data: NULL (Number of observations: 12)
## Samples: 2 chains, each with n.iter = 2000; n.warmup = 500; n.thin = 1;
## total post-warmup samples = 3000
## WAIC: -9.76
##
## Fixed Effects:
## Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
View IceCreamData.R
temp <- c(11.9,14.2,15.2,16.4,17.2,18.1,18.5,19.4,22.1,22.6,23.4,25.1)
units <- c(185L,215L,332L,325L,408L,421L,406L,412L,522L,445L,544L,614L)
log_units <- log(units)
n <- length(units)
market.size <- rep(800, n)
View SexualActivity.R
# http://www.theguardian.com/news/reality-check/2014/jan/31/sex-guardian-readers-confess-all
# Source: https://docs.google.com/spreadsheet/ccc?key=0At6CC4x_yBnMdDduelJocVo5RDZzalltd0dSQzdXUmc&usp=sharing#gid=0
dat <- data.frame(AgeGroup=factor(
1:9,
labels= c("Younger than 16", "16-24",
"25-34", "35-44", "45-54",
"55-64", "65-74",
"Older than 74", "(blank)"),
ordered=TRUE),
No=c(34, 2079, 2585, 1593,
View SexualActivityTests.R
with(dat, {
prop.test(Yes, Yes + No)
})
#
# 9-sample test for equality of proportions without continuity correction
#
# data: Yes out of Yes + No
# X-squared = 198.4, df = 8, p-value < 2.2e-16
# alternative hypothesis: two.sided
# sample estimates:
View labels_in_panels.R
set.seed(12345)
dat <- data.frame(category=rep(c("Food", "Drinks"),20),
product=rep(c("Cheese", "Wine", "Bread", "Beer"), 10),
year=sort(rep(c(2004:2013),4)),
value=sort(rnorm(40)))
dat <- dat[with(dat, order(category, year)),]
library(lattice)
# Change some of the default lattice settings
View sample_data_phones_films.R
set.seed(1234)
dat <- data.frame(
product=c(rep("Mobile",2),
rep(c("Smartphone", "Mobile"),3),
rep(c("Video rental shop"),3),
rep(c("Video rental shop",
"Online movie rental"),2)),
year=c(2008:2010, 2010, 2011, 2011, 2012, 2012,
2008:2010, 2011, 2011, 2012, 2012),
category=c(rep("Phone", 8), rep("Film", 7)),
View joy_of_joining_data.table.R
library(data.table)
dt <- data.table(dat, key="product,year")
# Create a table that list all years for all products.
py <- CJ(product=levels(dt[, product]),
year=unique(dt[,year]))
# Create a mapping table from old to new products.
# The new products are named product, so that I can
# join them with the original data and get a new colulmn
# with the old product category
mapping <- data.table(
View classrooms.R
require(googleVis) ## googleVis 0.5.0-3
dat <- data.frame(Room=c("Room 1","Room 2","Room 3"),
Language=c("English", "German", "French"),
start=as.POSIXct(c("2014-03-14 14:00",
"2014-03-14 15:00",
"2014-03-14 14:30")),
end=as.POSIXct(c("2014-03-14 15:00",
"2014-03-14 16:00",
"2014-03-14 15:30")))
plot(
You can’t perform that action at this time.