Skip to content

Instantly share code, notes, and snippets.

View datalorax's full-sized avatar

Daniel Anderson datalorax

View GitHub Profile
# Code from Richard McElreath's book, chapter 6
sppnames <- c( "afarensis","africanus","habilis","boisei",
"rudolfensis","ergaster","sapiens")
brainvolcc <- c( 438 , 452 , 612, 521, 752, 871, 1350 )
masskg <- c( 37.0 , 35.5 , 34.5 , 41.5 , 55.5 , 61.0 , 53.5 )
d <- data.frame( species=sppnames , brain=brainvolcc , mass=masskg )
## R code 6.2
m6.1 <- lm( brain ~ mass , data=d )
@datalorax
datalorax / equation_lm.R
Last active May 23, 2019 03:14
Converting a model into latex equation
equation_lm <- function(model) {
rhs <- colnames(model.matrix(model))[-1]
lhs <- all.vars(formula(model))[1]
lhs_eq <- paste(lhs, "= ")
betas <- paste0("\\beta_{", seq_along(rhs), "}(")
rhs_eq <- paste0(betas, rhs, ")")
rhs_eq <- paste("\\alpha +", paste(rhs_eq, collapse = " + "))
error <- "+ \\epsilon"
library(RSelenium)
library(rvest)
library(tidyverse)
theme_set(theme_minimal(15) +
theme(plot.title.position = "plot",
plot.caption = element_text(color = "gray40", size = 8)))
url <- "https://www.nytimes.com/interactive/2020/us/coronavirus-us-cases.html"
rd <- rsDriver(browser = "chrome", chromever = "81.0.4044.69")
library(tidyverse)
by_species <- iris %>%
group_by(Species) %>%
nest()
specific_models <- tibble(
Species = unique(iris$Species),
model = list(function(d) lm(Sepal.Length ~ Petal.Width + Petal.Length, d),
function(d) lm(Sepal.Length ~ Petal.Width, d),
library(colorspace)
library(rayshader)
library(tidyverse)
mse <- function(x, y, a, b) {
pred <- a + b*x
resid2 <- (y - pred)^2
1/length(y)*sum(resid2)
}
library(shiny)
library(shinyWidgets)
library(ggplot2)
library(equatiomatic)
library(gtsummary)
library(gt)
ui <- fluidPage(
titlePanel("equatiomatic w/Shiny"),
sidebarLayout(