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
z <- function(data, FUN = mean, ...) aggregate(. ~ 1, data = data, FUN = FUN, ...) | |
y <- function(data, FUN = mean, ...) data.frame(t(apply(data, 2, FUN = FUN, ...))) | |
x <- function(data, FUN = mean, ...) data.frame(t(sapply(data, mean, ...))) | |
d1 <- data.frame(matrix(1e3, ncol=10)) | |
d2 <- data.frame(matrix(1e6, ncol=10)) | |
d3 <- data.frame(matrix(1e6, ncol=100)) | |
# MEAN |
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("R6") | |
rpm <- R6Class("rpm", | |
public = list( | |
initialize = function() { | |
self$update_available() | |
self$update_installed() | |
}, | |
use = function(pkgs, quietly = TRUE, ...) { | |
self$install(pkgs[!self$installed(pkgs)], quiet = quietly, ...) |
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
layout(matrix(1:3, nrow = 1)) | |
# alpha = 0.05, two-tailed | |
curve(dnorm, from = -3.5, to = +3.5, lwd = 2, xaxs = "i", yaxs = "i", xlab = "z-statistic", ylim = c(0, .41), bty = "l", main = 'p<0.05, two-tailed ("Significant, Star-Worthy")') | |
polygon(c(qnorm(0.025), seq(qnorm(0.025), qnorm(.001), length.out = 20), -5), | |
c(0,dnorm(seq(qnorm(0.025), qnorm(.001), length.out = 20)), 0), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.025), 0, qnorm(0.025), 0.4, lwd = 2) | |
polygon(c(5, qnorm(0.975), seq(qnorm(0.975), qnorm(.999), length.out = 20)), | |
c(0,0,dnorm(seq(qnorm(0.975), qnorm(.999), length.out = 20))), col = rgb(1,0,0,alpha = 0.5)) | |
segments(qnorm(0.975), 0, qnorm(0.975), 0.4, lwd = 2) | |
text(qnorm(0.975), 0.3, paste0("z = ", sprintf("%0.2f", qnorm(0.975))), pos = 4, cex = 1.5) |
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
mab <- function(obj, expr, envir = .GlobalEnv) { | |
makeActiveBinding(obj, | |
function(e) { | |
if(missing(e)) { | |
eval(parse(text = force(expr)), envir = envir) | |
} else { | |
makeActiveBinding(force(obj), function(expr) eval(parse(text = force(e)), envir = force(envir)), force(envir)) | |
} | |
}, | |
env = envir) |
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
# effect sizes | |
d <- seq(.01, 2, length.out = 1000) | |
# required sample size at different power levels | |
n50 <- sapply(x, function(x) power.t.test(n = NULL, delta = x, power = 0.50)$n) | |
n80 <- sapply(x, function(x) power.t.test(n = NULL, delta = x, power = 0.80)$n) # conventional | |
n90 <- sapply(x, function(x) power.t.test(n = NULL, delta = x, power = 0.90)$n) | |
n95 <- sapply(x, function(x) power.t.test(n = NULL, delta = x, power = 0.95)$n) | |
n99 <- sapply(x, function(x) power.t.test(n = NULL, delta = x, power = 0.99)$n) |
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
# check for and remove previous R-devel install | |
g <- getwd() | |
setwd(R.home()) | |
setwd("../") | |
if("R-devel") %in% dir()) { | |
setwd("R-devel") | |
shell.exec(dir()[grep("unin.+exe$", dir())]) | |
## walk through uninstall dialog | |
setwd("../") | |
} |
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
# The UNF algorithm provides a clearly defined specification for creating a data hash. | |
# The algorithm has many strengths, including the fact that it is file format-independent, | |
# controls for floating point and rounding errors, and is independent of the column- | |
# organization of a dataset (i.e., variable order is irrelevant). | |
# | |
# A weakness, however, is that UNF is row-order sensitive. This is useful in terms of | |
# data subsetting (i.e., a subset of a dataset produces a different UNF than the full | |
# dataset), but it produces a weakness when two identical datasets are arranged in | |
# different row orders. Here's a simple example: |
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
thing,chocolatey_name | |
Adobe Reader,adobereader | |
ccleaner,ccleaner | |
chocolatey, | |
Chrome,google-chrome-x64 | |
ConEmu,conemu | |
curl,curl | |
cutepdf,cutepdf | |
Dropbox,dropbox | |
gettext, |
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
endpoint <- function(verb, url, body = (verb %in% c("POST", "PUT")), encode = "json", query, headers, dots = TRUE, class) { | |
f <- function() {} | |
if (body) { | |
if (dots) { | |
if (missing(headers)) { | |
if (missing(query)) { | |
formals(f) <- alist(body = , ... = ) | |
body(f)[[2]] <- as.call(list(verb, url, quote(...), body = quote(body), encode = encode)) | |
} else { | |
formals(f) <- alist(body = , ... = ) |
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("ggmap") | |
# https://github.com/reureu/Minneapolis-ALPR-Data | |
# removed 163478: 8b79f42dd1f945d588df16f271cafb54,Latitude,Longitude,Timestamp,Device | |
d <- read.csv("data.csv", header = FALSE, colClasses = c("factor", "numeric", "numeric", "character", "factor")) | |
names(d) <- c("id", "lat", "lon", "datetime", "reader") | |
# create map | |
map <- get_googlemap("minneapolis", zoom = 12, color = "bw") |