This file contains hidden or 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
| require(MCMCpack) | |
| ## the more recent polls, the better they are. | |
| ##http://es.wikipedia.org/wiki/Elecciones_presidenciales_de_Uruguay_de_2014 | |
| polls = NULL | |
| polls <- data.frame( rbind( | |
| Factum = c(52,37, 1004), | |
| Cifra = c(52, 35, 1000), | |
| Equipos = c(52, 39, 600), |
This file contains hidden or 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
| # caTools is handy because it provides write.gif function | |
| library(caTools) | |
| cols <- colorRampPalette(c("#00007F", "brown", "blue", "#007FFF", "green", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000", "magenta")) | |
| m <- 1200 # define size | |
| C <- complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), | |
| imag=rep(seq(-1.2,1.2, length.out=m), m ) ) | |
| C <- matrix(C,m,m) # reshape as square matrix | |
| Z <- 0 # initialize Z to zero | |
| X <- array(0, c(m,m,20)) # initialize output 3D array | |
| for (k in 1:20) { # loop with 20 iterations |
This file contains hidden or 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
| #Comments | |
| 1. All code is written with the original, vague priors. | |
| 2. Runs were made with the logicals compiled. | |
| 3. Note that inprod() could be used, but is much slower (in versions of BUGS up to 3.0.1): with no missing covariate information it should be more efficient. | |
| 4. Parameters that I monitored are highlighted in this fetching shade . | |
| 5. Initial valus are given: the burn-in was not our main interest, so they were set to make this small. | |
| 6. Comments on the no selection, fixed effect, apply to all models. Similarly, comments on fixed effect models also apply to the corresponding random effect model | |
| Data for all models in here |
This file contains hidden or 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 original R code is Bradley Boehmke | |
| # https://rpubs.com/bradleyboehmke/weather_graphic | |
| # Packages | |
| library(dplyr) | |
| library(tidyr) | |
| library(magrittr) | |
| library(ggplot2) | |
| "http://academic.udayton.edu/kissock/http/Weather/gsod95-current/BZBRSLIA.txt" %>% | |
| read.table() %>% data.frame %>% tbl_df -> data | |
| names(data) <- c("month", "day", "year", "temp") |
This file contains hidden or 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
| ## Exported as an SVG of 1200 width and 525 height | |
| poly_coords<- function(shapefile){ | |
| if (nrow(data.frame(shapefile$ID))< 1) | |
| { | |
| print ("No ID field in SpatialPolygon") | |
| }else{ |
This file contains hidden or 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
| require(dplyr) | |
| require(RCurl) | |
| require(reshape2) | |
| require(rvest) | |
| require(pipeR) | |
| getGoogleResults <- function (search.term, show = 10){ | |
| Trim <- function (x) gsub("^\\s+|\\s+$", "", x) | |
| packages = c('rvest','dplyr','pipeR','reshape2') |
This file contains hidden or 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(rvest) | |
| 'http://espn.go.com/sportsnation/teamrankings#table' %>>% | |
| html %>>% | |
| html_table() %>>% data.frame %>>% tbl_df -> data | |
| names(data) %<>% tolower() | |
| c('rank','team') -> names(data)[1:2] | |
| data$rank %>>% (gsub('\\.','',.)) %>>% as.numeric -> data$rank | |
| data[!is.na(data$rank),] -> data |
This file contains hidden or 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
| ################################################################################## | |
| ####################### SQLite Speed ##################################### | |
| ################################################################################## | |
| install.packages("sqldf") | |
| require(sqldf) | |
| #DataPath<-"C:/Data/NewTables/" | |
| #Datatbl<-list.files(DataPath) | |
| #Cwd<-getwd() | |
| #setwd(DataPath) | |
| #dat = lapply(Datatbl,read.csv, header = TRUE) |
This file contains hidden or 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
| # written by http://hannes.muehleisen.org/ | |
| # from http://stackoverflow.com/questions/16474696/read-system-tmp-dir-in-r | |
| gettmpdir <- | |
| function() { | |
| tm <- Sys.getenv(c('TMPDIR', 'TMP', 'TEMP')) | |
| d <- which(file.info(tm)$isdir & file.access(tm, 2) == 0) | |
| if (length(d) > 0) | |
| tm[[d[1]]] | |
| else if (.Platform$OS.type == 'windows') |
This file contains hidden or 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) | |
| #install.packages("lme4") | |
| library(lme4) | |
| library(doBy) | |
| library(mice) | |
| ############### ############### | |
| # MI adjustments for final estimates | |
| ############### ############### | |
| finalMI <- function(var,beta,m){ |