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(ggplot2) | |
library(dplyr) | |
# start with current year | |
starting_year <- 2024 | |
# assume this many children born during the lifetime of each woman | |
children_per_woman <- 2.1 |
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
#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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# support vector machines # | |
data(quakes) | |
plot( quakes , col = as.factor( round( quakes$mag ) ) ) | |
this_df <- quakes | |
this_df[ , 'mag' ] <- as.factor( round( this_df[ , 'mag' ] ) ) | |
library(e1071) |
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(survey) | |
data(api) | |
x <- apistrat | |
x <- subset( x , comp.imp == 'Yes' ) | |
dstrat_before<-svydesign(id=~1,strata=~stype, weights=~pw, data=x, fpc=~fpc) |
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 necessary libraries | |
library(stringr) | |
library(foreign) | |
library(survey) | |
library(RCurl) | |
#set the temporary directory to download all files to! | |
setwd("s:/temp") |
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(RCurl) | |
setwd("R:\\Medical Expenditure Panel Survey\\Data") | |
#input all available MEPS public use file numbers | |
year <- c(1996:2008) | |
consolidated <- c(12,20,28,38,50,60,70,79,89,97,105,113,NA) | |
conditions <- c("06r",18,27,37,52,61,69,78,87,96,104,112,NA) | |
jobs <- c("07",19,25,32,40,56,63,74,83,91,100,108,116) | |
prpf <- c(24,47,47,47,47,57,66,76,88,95,103,111,119) |
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
#install RCurl on your version of R if you don't already have it | |
#just run this once | |
#install.packages("RCurl") | |
#program start | |
#load the RCurl package | |
library(RCurl) | |
#set your output folder - this is where the pdfs will get saved | |
setwd("R:/National Health Interview Survey/documentation") |
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(rvest) | |
baseurl <- "https://washingtondc.craigslist.org/search/doc/jjj" | |
raw_query_list <- | |
lapply( | |
paste0( baseurl , "?s=" , seq( 0 , 1469 , 120 ) ) , | |
xml2::read_html | |
) |
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
tf <- tempfile() | |
download.file( "https://www.ssa.gov/oact/babynames/state/namesbystate.zip" , tf , mode = 'wb' ) | |
z <- unzip( tf , exdir = tempdir() ) | |
state_files <- grep( "\\.TXT$" , z , value = TRUE ) | |
state_list <- lapply( state_files , read.table , header = FALSE , sep = ',' , stringsAsFactors = FALSE ) | |
w <- do.call(rbind,state_list) | |
names( w ) <- c( 'stateab' , 'sex' , 'year' , 'name' , 'count' ) | |
maxes <- with( w , tapply( count , list( year , stateab , sex ) , max ) ) | |
max_df <- reshape2::melt( maxes ) | |
names( max_df ) <- c( 'year' , 'stateab' , 'sex' , 'count' ) |
NewerOlder