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
#' Caterpillar plot with thick and thin CI | |
#' | |
#' Caterpillar plots are plotted combining all chains for each parameter. | |
#' | |
#' @param D Data frame whith the simulations or list of data frame with simulations. If a list of data frames with simulations is passed, the names of the models are the names of the objects in the list. | |
#' @param X data frame with two columns, Parameter and the value for the x location. Parameter must be a character vector with the same names that the parameters in the D object. | |
#' @param family Name of the family of parameters to plot, as given by a character vector or a regular expression. A family of parameters is considered to be any group of parameters with the same name but different numerical value between square brackets (as beta[1], beta[2], etc). | |
#' @param thick_ci Vector of length 2 with the quantiles of the thick band for the credible interval | |
#' @param thin_ci Vector of length 2 with the quantiles of the thin band for the credible interval | |
#' @param line Numerical value in |
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
#' Extract parameter point estimates | |
#' | |
#' @param D Data frame with the simulations or list of data frame with simulations. If a list of data frames with simulations is passed, the names of the models are the names of the objects in the list. | |
#' @param family Name of the family of parameters to plot, as given by a character vector or a regular expression. A family of parameters is considered to be any group of parameters with the same name but different numerical value between square brackets (as beta[1], beta[2], etc). | |
#' @param thick_ci Vector of length 2 with the quantiles of the thick band for the credible interval. | |
#' @param thin_ci Vector of length 2 with the quantiles of the thin band for the credible interval. | |
#' @param param_label_from Vector of strings (can be regular expressions) for the original paramater labels that you would like to replace in the plot lables using \code{param_label_to}. | |
#' @param param_label_to Vector of strings for paramater labels you would like to use. Must be both the sam |
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
#' Simple function to transform a dependent variable that in [0,1] rather than | |
#' (0, 1) to beta regression. Suggested by Smithson & Verkuilen (2006). | |
#' | |
#' @param y vector of the dependent variable that is in [0, 1]. | |
svTransform <- function(y) | |
{ | |
n <- length(y) | |
transformed <- (y * (n-1) + 0.5)/n | |
return(transformed) |
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
#' Convert text files in a directory to UTF-8 encoding | |
#' | |
#' @param dir a character string naming the directory where the files are located. | |
#' @param new_dir a character string naming the directory where you would like the | |
#' converted files to be placed. | |
#' | |
#' @importFrom dplyr %>% | |
utf8_convert <- function(dir, new_dir){ | |
all_files <- list.files(dir) |
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
######################################## | |
# Download GitHub users with more than 100 followers for Berlin, Brooklyn, | |
# and London | |
# Christopher Gandrud | |
# 20 October 2014 | |
######################################## | |
library(httr) | |
library(dplyr) | |
library(rjson) |
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
country | iso2c | year | credit | |
---|---|---|---|---|
Austria | AT | Jan 2007 | 100 | |
Austria | AT | Jan 2008 | 102.9 | |
Austria | AT | Jan 2009 | 109.8 | |
Austria | AT | Jan 2010 | 108.6 | |
Austria | AT | Jan 2011 | 107.1 | |
Austria | AT | Jan 2012 | 106.1 | |
Austria | AT | Jan 2013 | 103.8 | |
Belgium | BE | Jan 2007 | 100 | |
Belgium | BE | Jan 2008 | 101.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
#' Sets valid working directory from vector of possible directories | |
#' | |
#' @param character vector of possible working directores | |
set_valid_wd <- function(possible) { | |
for (i in possible) { | |
if (file.exists(i)) { | |
setwd(i) | |
message(sprintf('Working directory set as: %s', i)) | |
} |
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
#' Rescale a vector to be within 0 and 1 | |
#' | |
#' @param x a numeric vector to rescale | |
#' @param na.rm logical. Whether or not to remove NA (missing) values | |
range01 <- function(x, na.rm = T){ | |
(x - min(x, na.rm = na.rm)) / | |
(max(x, na.rm = na.rm) - min(x, na.rm = na.rm)) | |
} |
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
#' Convert a vector into a matrix with two columns | |
#' | |
#' @param x a vector | |
equal_columns <- function(x) { | |
round2 = function(x, digits) { | |
posneg = sign(x) | |
z = abs(x)*10 ^ digits | |
z = z + 0.5 | |
z = trunc(z) |
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
# Load RCurl package | |
library(RCurl) | |
addresses <- read.csv("~/links.csv") # Create a .csv file with all of the links you want to crawl | |
for (i in addresses) full.text <- getURL(i) | |
text.sub <- gsub("<.+?>", "", full.text) # Removes HTML tags | |
text <- data.frame(text.sub) |
OlderNewer