Skip to content

Instantly share code, notes, and snippets.

View vincentarelbundock's full-sized avatar

Vincent Arel-Bundock vincentarelbundock

View GitHub Profile
@vincentarelbundock
vincentarelbundock / modelsummary.ipynb
Last active April 20, 2021 14:28
`modelsummary` regression tables in a Jupyter notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(data.table)
library(tidyverse)
library(microbenchmark)
make_tibble <- function(...) {
treated_units <- sample(1:20000, 4000)
# year fixed effects
year <- tibble(
year = 1981:2010,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
remotes::install_github('vincentarelbundock/modelsummary')
library(modelsummary)
models <- list()
models[['OLS']] <- lm(mpg ~ factor(cyl), mtcars)
models[['Logit']] <- glm(am ~ factor(cyl), mtcars, family = binomial)
make_rows <- function(models) {
rows <- data.frame(term = 'factor(cyl)4', section = 'middle', position = 3)
library(testthat)
library(mice)
context("pool.r.squared")
data(nhanes)
imp <- mice::mice(nhanes, maxit = 2, m = 2, seed = 1, print = FALSE)
fit_mira <- with(data = imp, exp = lm(chl ~ age + bmi))
test_that("r.squared", {
url <- 'https://raw.githubusercontent.com/leeper/margins/master/R/find_terms_in_model.R'
source(url)
#' @rdname prediction
#' @export
prediction.fixest <-
function(model,
data = find_data(model, parent.frame()),
at = NULL,
type = "response",
---
title: "Test new version of `modelsummary`"
author: "Vincent Arel-Bundock"
date: "2020-05-26"
output: pdf_document
header-includes:
- \usepackage{booktabs}
- \usepackage{threeparttable}
---
draw_plot <- function(funs = list('S' = function(x) x, 'D' = function(x) 100 - x),
xlim = c(0, 100)) {
# data.frame of 1000 points to trace smooth functions
dat <- tibble(x = seq(xlim[1], xlim[2], length.out = 1000),
y1 = funs[[1]](x),
y2 = funs[[2]](x))
# find equilibrium and add it to data.frame
@vincentarelbundock
vincentarelbundock / munklak_sim.R
Created April 24, 2020 20:11
munklak simulation
library(lfe)
library(lme4)
library(MASS)
library(tidyverse)
library(modelsummary)
set.seed(290653)
sim <- function(Nobs = 100, Ngrp = 50, cor_x_u = .6, x_sd = .2, y_sd = 1, ...) {
group <- mvrnorm(Ngrp, c(0, 0), matrix(c(1, cor_x_u, cor_x_u, 1), ncol = 2)) %>%
data.frame %>% setNames(c('U', 'Ucor')) %>%
library(lme4)
library(gt)
library(modelsummary)
library(tidyverse)
# y dependent variable
# x regressor varies at the county-year level
# z regressor varies at the county level
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/plm/Crime.csv'