Skip to content

Instantly share code, notes, and snippets.

View sdaza's full-sized avatar

Sebastian Daza sdaza

View GitHub Profile
######################################################
# 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)
@sdaza
sdaza / samplesize.R
Last active December 30, 2015 22:49
Function for sample size and error
# 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")
}
@sdaza
sdaza / ape.R
Last active December 30, 2015 11:59
ape
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=" ",
@sdaza
sdaza / APCex.R
Last active December 29, 2015 08:19
Average predictive comparisons
# 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
@sdaza
sdaza / lookvar.R
Last active December 11, 2015 21:18
lookvar
# 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)