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
###################################################### | |
# SIMULATION FUNCTION TERM PAPER SOC 952, SPRING 2014 | |
###################################################### | |
# RETURN STANDARDIZED BIAS AND COVERAGE RATES | |
# These libraries have to be installed | |
library(data.table) | |
library(lavvan) |
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
# MY R FUNCTIONS | |
# AUTHOR: SEBASTIAN DAZA | |
# Jun 02, 2014, 10:35 AM | |
# LOOKING FOR VARIABLES #### | |
lookvar <- function(dat, varnames) { | |
n <- names(dat) | |
nn <- list() | |
for (i in 1:length(varnames)) { |
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
########### | |
# Example | |
########## | |
library(igraph) | |
actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David", | |
"Esmeralda"), | |
age=c(48,33,45,34,21), | |
gender=c("F","M","F","M","F")) |
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(acs) | |
rm(list=ls(all=TRUE)) | |
variables <- c("C17002_002", "C17002_003", "C17002_004", "C17002_005","C17002_006", "C17002_001") | |
dat <- acs.fetch(geo = geo.make(state = "WI", county = "*", tract = "*"), variable = variables) | |
p_output <- divide.acs(dat[,1] + dat[,2] + dat[,3] + dat[,4] + dat[,5], dat[,6], method = "proportion") | |
r_output <- divide.acs(dat[,1] + dat[,2] + dat[,3] + dat[,4] + dat[,5], dat[,6], method = "ratio") |
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
# EXAMPLES USING PACKAGE ACSR | |
# AUTHOR: SEBASTIAN DAZA | |
# March 23, 2015, 8:19 AM | |
# INSTALL LAST VERSION OF DATA.TABLE AND ACS PACKAGE (YOU HAVE TO INSTALL DEVTOOLS BEFORE!) | |
# I ASSUME ACS IS ALREADY INSTALLED! | |
install.packages("devtools") | |
devtools::install_github("Rdatatable/data.table", build_vignettes = FALSE) | |
# INSTALL MY PACKAGE |
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
# dat has to be a data.frame or data.table | |
# varnames should bea vector with the variable names you are looking for, e.g., c("hc", "hv"), or regular expressions | |
# the result would be a vector with variables names | |
lookvar <- function(dat, varnames) { | |
n <- names(dat) | |
nn <- list() | |
for (i in 1:length(varnames)) { | |
nn[[i]] <- grep(varnames[i],n) |
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
# AVERAGE PREDICTVE COMPARISON | |
# loading libraries | |
library(arm) | |
# data | |
dat <- read.csv("http://dl.getdropbox.com/u/18116710/example.csv") | |
# id: individual identifier | |
# wave: 1 to 7 |
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
mycoefplot <- function(coef) { | |
# reverse coefficients | |
coef <- apply(coef, 2, rev) | |
nvar <- length(rownames(coef)) | |
# dotplot | |
dotplot(1:nvar~coef[,1], | |
xlim=c(min(coef[,1]-2*coef[,2])-.02, max(coef[,1]+2*coef[,2])+.02), | |
xlab='Average predictive comparison', ylab=" ", |
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
# SAMPLING ERROR | |
serr <- function(n, deff=1, rr=1, N=NULL, cl=.95, p=0.5, relative=FALSE) { | |
# validation | |
if (sum(n==0)>=1) { | |
stop("n vector contains 0 values") | |
} |
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 data | |
load("ex.Rdata") | |
################################### | |
# example only using mice package | |
################################### | |
library(mice) | |
imp <- mice(ex, maxit = 0) |
OlderNewer