Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@tonyfischetti
tonyfischetti / elastic-net-regression-evaluation.R
Last active April 27, 2021 13:24
Code for my blog post "Kickin' it with elastic net regression"
#!/usr/bin/Rscript --vanilla
###########################################################
## ##
## elastic.R ##
## ##
## Author: Tony Fischetti ##
## tony.fischetti@gmail.com ##
## ##
###########################################################
@tslumley
tslumley / README.md
Last active December 17, 2017 14:34
predictive margins like SUDAAN does them

Predictive margins for generalised linear models in R

This code implements the thing that PREDMARG in SUDAAN does, as described in

  • Graubard B, Korn E (1999) "Predictive Margins with Survey Data" Biometrics 55:652-659
  • Bieler, Brown, Williams, & Brogan (2010) "Estimating Model-Adjusted Risks, Risk Differences, and Risk Ratios From Complex Survey Data" Am J Epi DOI: 10.1093/aje/kwp440
@yihui
yihui / README.md
Last active March 15, 2017 18:35
A Shiny app based on annyang that responds to voice input
@tslumley
tslumley / moe
Created August 21, 2014 23:53
Margin of error in polls, based on actual percentage and allowing for design effects
moe = function(pct, N=1000, deff=c(1,2)){
p.L = function(x, n) {
ifelse (x == 0,0,qbeta(0.025, x, n - x + 1))
}
p.U = function(x, n) {
ifelse(x == n,1,qbeta(0.975, x + 1, n - x))
}
N = rep(N,length(pct))
lower = function(pct,deff){
@ptoche
ptoche / ps-income-shares.csv
Last active August 29, 2015 14:00
Piketty & Saez, Top Incomes in the U.S., 1913-2012
Year Fractile value
1 1913-01-01 Top 0.01% 0.0275501620545077
2 1914-01-01 Top 0.01% 0.0272920847365446
3 1915-01-01 Top 0.01% 0.0436035
4 1916-01-01 Top 0.01% 0.0440493410443468
5 1917-01-01 Top 0.01% 0.0333076913805183
6 1918-01-01 Top 0.01% 0.0244816293043196
7 1919-01-01 Top 0.01% 0.0222020659211262
8 1920-01-01 Top 0.01% 0.0167163862642264
9 1921-01-01 Top 0.01% 0.0168921038823408
@dsparks
dsparks / colors.R
Last active December 23, 2020 22:12
Sunlight Foundation palettes, based on the Wes Anderson code
# Sunlight Foundation style guide: http://design.sunlightlabs.com/projects/Sunlight-StyleGuide-DataViz.pdf
# Ram's original Wes Anderson code: https://github.com/karthik/wesanderson/blob/master/R/colors.R
#' A Wes Anderson palette generator
#'
#' These are a handful of color palettes from Wes Anderson movies.
#' @param n Number of colors desired. Unfortunately most palettes now only have 4 or 5 colors. But hopefully we'll add more palettes soon. All color schemes are derived from the most excellent Tumblr blog: \href{http://wesandersonpalettes.tumblr.com/}{Wes Anderson Palettes}
#' @param name Name of desired palette. Choices are: \code{GrandBudapest}, \code{Moonrise1}, \code{Royal1}, \code{Moonrise2}, \code{Cavalcanti}, \code{Royal2}, \code{GrandBudapest2}, \code{Moonrise3}, \code{Chevalier}, \code{BottleRocket}, \code{darjeeling}, \code{darjeeling2}
#' @param type Set to continuous if you require a gradient of colors similar to how heat map works.
#' @export
@michalskop
michalskop / index.html
Last active January 3, 2016 20:29
Weighted PCA Model in R
We couldn’t find that file to show.
@briatte
briatte / 00_survey_data_README.md
Last active January 2, 2019 02:45
A few snippets to quickly get a selection of social science datasets into R.

Here are little chunks of R code to quickly access survey datasets. Some of the linked datasets are provided on an "as-is" basis: typically, you might want to check the official ANES files rather than rely on the extracts linked to below. This also applies to data extracts bundled in packages.

HOWTO

The code occasionally calls the download and foreign packages, respectively to get files from HTTPS sources and to deal with foreign formats. The Gelman and Hill replication also uses plyr and ggplot2, but check the original code for identical functions written in base R.

SEEALSO

@low-decarie
low-decarie / dual_dendogram_tile_plot
Last active July 21, 2023 22:17
Given a data matrix, this produces a tile plot with dendograms for each axis
dual_dendogram_tile_plot <- function(data.matrix, main="Title"){
#Dual dendrogram ############
x <- data.matrix
dd.col <- as.dendrogram(hclust(method="ward",dist(x)))
col.ord <- order.dendrogram(dd.col)
dd.row <- as.dendrogram(hclust(method="ward",dist(t(x))))
row.ord <- order.dendrogram(dd.row)
myboot<-function(data, stat, nreps, hist = TRUE) {
estimates<-get(stat)(data)
len<-length(estimates)
container<-matrix(NA, ncol = len , nrow = nreps)
nobs<-nrow(data)
for(i in 1:nreps) {
posdraws<-ceiling(runif(nobs)*nobs)
resample<-data[posdraws,]
container[i,]<-get(stat)(resample)
}