Skip to content

Instantly share code, notes, and snippets.

View vincentarelbundock's full-sized avatar

Vincent Arel-Bundock vincentarelbundock

View GitHub Profile
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'
---
title: "COVID-19 Worldometer data"
output: html_notebook
---
This notebook pulls a table with useful information out of ![worldometer](https://www.worldometers.info/coronavirus/) and then makes a graph.
```{r}
library(WDI)
library(countrycode)
library(gghighlight)
library(tidyverse)
# load data
raw <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-03/game_goals.csv')
# 8 best scorers (there are 8 colors in scale_color_brewer Dark2)
best <- raw %>%
group_by(player) %>%
summarize(goals = sum(goals)) %>%
library(tidyverse)
example <- tibble(id = 1:500,
A = sample(TRUE:FALSE, 500, replace = TRUE),
B = sample(TRUE:FALSE, 500, replace = TRUE),
C = sample(TRUE:FALSE, 500, replace = TRUE),
D = sample(TRUE:FALSE, 500, replace = TRUE),
E = sample(TRUE:FALSE, 500, replace = TRUE),
F = sample(TRUE:FALSE, 500, replace = TRUE))