# %%
library(wooldridge)
library(dqrng)
library(collapse)
#> collapse 2.0.10, see ?`collapse-package` or ?`collapse-documentation`
#>
#> Attaching package: 'collapse'
#> The following object is masked from 'package:stats':
#>
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
#' Create matrix from vectors for rows, columns, and values | |
#' | |
#' Note the rows and columns can be anything (e.g. strings containing fips). | |
#' Internally, these are efficiently created to an index using | |
#' `indexthis::to_index` (with values 1, ..., n_unique). | |
#' | |
#' @param i Vector used for the row indices. | |
#' @param j Vector used for the column indices. | |
#' @param x Vector used for the values. | |
#' @param names Logical. If column and row names should be used. These |
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
# %% [markdown] | |
# --- | |
# format: gfm | |
# --- | |
# %% | |
using StatsBase, Statistics | |
using Random | |
# %% | |
""" |
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(tidyverse) | |
# %% | |
simulation <- function(n, p, k) { | |
trials = purrr::map_dbl(1:100000, function(b) { | |
# Take 100 shots and record if basket is made | |
shots = as.numeric(runif(n) < p) | |
# Observe streaks | |
hot_hand_shot_results = c() |
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(htmltools) | |
#* @serializer html | |
#* @get / | |
base = function() { | |
html <- tags$html( | |
tags$head( | |
tags$script(src='https://unpkg.com/htmx.org@1.9.10/dist/htmx.js') | |
), | |
tags$body( |
library(ggplot2)
library(kfbmisc)
x = seq(-pi, pi, 0.02)
df = data.frame(x = x, y = sin(x))
p = ggplot(df) +
geom_line(aes(x = x, y = y), linewidth = 1.5) +
labs(x = "$x$", y = "$\\sin(x)$") +
scale_x_continuous(
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
#' --- | |
#' title: "Demo showing R code chunks, VSCode, and quarto support" | |
#' format: gfm | |
#' --- | |
#' This script shows how to use .Rmd chunks in a plain text file. | |
#' With new changes to vscode-R extension, this is seamlessly integrated | |
#' into the dev experience. Additionally, knitr::spin() or quarto | |
#' can be used to generate a report directly from the .R file. |
library(fixest)
library(dqrng)
library(tictoc) # For timing
data(trade, package = "fixest")
tic("Initial feols")
est = feols(Euros ~ dist_km | Destination + Origin, data = trade)
toc()
#> Initial feols: 0.023 sec elapsed
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.3.1
theme_set(theme_bw())
# Sean 'Lahman' Baseball Database
library(Lahman)
data(Batting, package = "Lahman")
data(Pitching, package = "Lahman")
library(ggplot2)
(p1 <- ggplot(mtcars) +
geom_point(aes(x = mpg, y = wt, color = as.factor(cyl))) +
labs(
title = "Miles per gallon vs. weight",
subtitle = "Data from mtcars",
caption = "Source: mtcars",
color = NULL,
NewerOlder