Skip to content

Instantly share code, notes, and snippets.

library(downloader)
# install.packages( c("MonetDB.R", "MonetDBLite" , "survey" , "SAScii" , "descr" , "downloader" , "digest" , "stringr" , "R.utils" , "RCurl" ) , repos=c("http://dev.monetdb.org/Assets/R/", "http://cran.rstudio.com/"))
library(SAScii) # load the SAScii package (imports ascii data with a SAS script)
library(RCurl) # load RCurl package (downloads https files)
library(stringr) # load stringr package (manipulates character strings easily)
library(downloader) # downloads and then runs the source() function on scripts from github
library(MonetDB.R) # load the MonetDB.R package (connects r to a monet database)
@ajdamico
ajdamico / La_rs_bughunt.R
Created February 22, 2016 20:34
La_rs bughunt
# # # # # # # # # # # # # # # # #
# # set the working directory # #
# # # # # # # # # # # # # # # # #
# setwd( "C:/My Directory/SWMAP/" )
# # # # # # # # # # # # # # # #
# # example survey data set # #
# # # # # # # # # # # # # # # #
@ajdamico
ajdamico / rare events in survey sampling.R
Last active November 29, 2015 12:03
survey research does a lousy job of estimating prevalence rates for unlikely events
xl <- seq( 0 , 10000 , 100 )
my_title <- 'if we randomly choose X people from some population and determine that none have a disease,\nwe can be 95% confident that the population prevalence rate is below Y% for this particular affliction.'
plot( xl , qbeta(1 - 0.05, 1 , xl ) , ylim=c(0,.01),axes=F,xlab="",ylab="",main="\nhow rare is a rare disease?\n\nsurvey research does a lousy job of estimating prevalence rates for unlikely events")
axis(2, at=seq(0,.01,.001), lab=paste0(seq(0,.01,.001)*100,"%"), las=TRUE)
axis(1, at=seq(0,10000,1000), lab=prettyNum(seq(0,10000,1000),big.mark=","), las=TRUE)
text( 3500 , 0.0075 , label = my_title , cex = 1.5, adj=c(0,0))
z <- data.frame( x = 0:100000 , y = qbeta(1 - 0.05, 1 , 0:100000 ) )
@ajdamico
ajdamico / wwow.R
Created December 7, 2014 19:00
world without water
# setwd( "C:/My Directory/wwow/" )
path.to.7z <- normalizePath( "C:/Program Files (x86)/7-zip/7z.exe" )
library(stringr)
library(downloader)
library(raster)
library(rasterVis)
source_url(
@ajdamico
ajdamico / puma of my childhood.R
Created January 20, 2013 03:28
the puma of my childhood
# install mapping packages
install.packages( c( 'sp' , 'rgdal' ) )
# load necessary libraries
require(sp)
require(rgdal)
# create a temporary file and directory
tf <- tempfile() ; td <- tempdir()
@ajdamico
ajdamico / nona.R
Created June 28, 2012 01:22
binary operators that never return missing values - how to remove NA values from logical tests
#create the remove NA function
no.na <-
function( x , value = FALSE ){
x[ is.na( x ) ] <- value
x
}
@ajdamico
ajdamico / most recent 100 books posted to paperbackswap.R
Created May 5, 2012 22:48
webscrape the ISBN-10 values of the 100 most recent books posted to paperbackswap.com
library(XML)
url <- "http://www.paperbackswap.com/api/v1/index.php?RequestType=RecentlyPosted&Limit=100"
u <- xmlParse( url )
v <- getNodeSet( u , "/Response/Books/Book/ISBN-10" )
w <- sapply( v , xmlValue )
@ajdamico
ajdamico / let it be.R
Created March 6, 2012 04:44
let R sing the beatles
title = "Let it be"
wow = "words of wisdom"
Verse.1 =
c( "When I find myself in times of trouble" ,
"Mother Mary comes to me" ,
paste( "Speaking" , wow ) ,
title )
@ajdamico
ajdamico / using R to replicate the NHIS Multiple Imputation technique.R
Created February 12, 2012 00:13
replicate the national health interview survey's multiply imputed income technique using R instead of SUDAAN
#page 118 of the NHIS document
#ftp://ftp.cdc.gov/pub/health_statistics/nchs/dataset_documentation/nhis/2010/srvydesc.pdf
#displays the R code to load the persons file into R as a survey object
#the code below creates a slightly different survey object, one that includes appropriately-imputed income.
#this R code:
# reads the year 2000 personsx file into R
# reads in all five imputed income files
# merges the 2000 personsx file with the five imputed income files
@ajdamico
ajdamico / listlabeling.R
Created October 31, 2011 21:52
roger peng's listlabeling challenge
#roger peng's listlabeling challenge from
#http://simplystatistics.tumblr.com/post/11988685443/computing-on-the-language
#create three example variables for a list
x <- 1
y <- 2
z <- "hello"
#create the function
makeList <- function(...) {