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
# setup | |
library("survey") | |
data("api") | |
apiclus1$proportion <- apiclus1$pcttest/100 | |
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=apiclus1) | |
# confint(svymean(...) == svyciprop(..., method = "me") | |
confint(svymean(~ proportion, dclus1)) | |
## 2.5 % 97.5 % | |
## proportion 0.9852196 0.9943432 |
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
# Copyright (c) 2018 Thomas J. Leeper | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all |
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
* replication code: Causal Inference in Conjoint Analysis: | |
* Understanding Multidimensional Choices via Stated Preference Experiments | |
* Jens Hainmueller, Daniel Hopkins, Teppei Yamamoto | |
clear all | |
set more off | |
ssc install matmap | |
ssc install mat2txt |
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
stata_summary <- | |
function( | |
x, | |
... | |
) { | |
# summarize | |
mod <- x | |
x <- summary(x) | |
# find outcome variable |
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("pdftools") | |
# load files | |
files <- dir(pattern = "pdf$") | |
# setup metadata | |
year <- ifelse(grepl("\\d{4}", files), regmatches(files, regexpr("(?<=, )\\d{4}", files, perl = TRUE)), "") | |
journal <- unlist(lapply(files, function(x) { | |
if (grepl("(?<=\\().+(?=, \\d{4})", x, perl = TRUE)) { | |
regmatches(x, regexpr("(?<=\\().*?(?=, \\d{4})", x, perl = TRUE)) |
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
url <- "http://varianceexplained.org/files/Brauer2008_DataSet1.tds" | |
# Clean and tidy the data | |
d1 <- rio::import(url, format = "tsv") | |
d2 <- cbind(d1, setNames(do.call(rbind.data.frame,strsplit(d1$NAME, " ?\\|\\| ?"))[,-5], | |
c("name", "BP", "MF", "systematic_name"))) | |
d3 <- | |
subset( | |
within( | |
reshape(d2, |
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
# R and SQLite tutorial | |
# Steph Locke, Mango Solutions | |
# 2015-11-30 | |
library("RSQLite") | |
library("DBI") | |
dbListTables(datasetsDb())[1:2] | |
myDB <- dbConnect(SQLite(), "local.db") |
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("rtruncnorm") | |
library("prediction") | |
library("margins") | |
set.seed(14850) | |
n <- 300 | |
error <- 4 | |
ex <- data.frame( | |
d = rbinom(n,1,.5), | |
x = rnorm(n), | |
e = rnorm(n,0,error)) |
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
# ttable: a grammar of tables | |
# https://gist.github.com/leeper/f9cfbe6bd185763762e126a4d8d7c286 | |
# aggregate/summarize | |
# arrange | |
# annotation (metadata features) | |
# theme |
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
shrugp <- function(p) { | |
out <- symnum(p, cutpoints = c(0, 0.001, 0.01, 0.05, 0.10, 1.00), | |
symbols = c("(ツ)", "¯\\(ツ)/¯", "¯\\_(ツ)_/¯", "¯\\___(ツ)___/¯", "¯\\____(ツ)____/¯")) | |
as.character(out) | |
} | |
pvals <- c(0.09, 0.03, 0.002, 0.000001) | |
shrugp(pvals) | |
## [1] "¯\\___(ツ)___/¯" "¯\\_(ツ)_/¯" "¯\\(ツ)/¯" "(ツ)" |
NewerOlder