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) | |
library(palmerpenguins) # for `penguins` data set | |
# fit a model for each variable (bill length, bill depth, flipper length) | |
penguin_models <- penguins %>% | |
pivot_longer(c(bill_length_mm, bill_depth_mm, flipper_length_mm), | |
names_to = "outcome_name", | |
values_to = "outcome") %>% | |
group_by(outcome_name) %>% | |
summarise(model = list(lm(outcome ~ species, data = cur_data()))) |
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) | |
library(palmerpenguins) # for `penguins` data set | |
penguin_model_formulas <- tribble( | |
~name, ~formula, | |
"depth only", "bill_length_mm ~ bill_depth_mm", | |
"species only", "bill_length_mm ~ species", | |
"depth and species", "bill_length_mm ~ bill_depth_mm + species", | |
) |
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
# example_geo_data.R: example of spatial data which may be desirable to | |
# overlay on a map. | |
# Cameron Patrick <cameron.patrick@unimelb.edu.au>, 22 Jan 2022. | |
library(tidyverse) | |
library(rnaturalearth) | |
library(ragg) | |
# You will also need the natural earth data: | |
# remotes::install_github("ropensci/rnaturalearthhires") |
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(emmeans) | |
data(mtcars) | |
# in the example here, all models give the same point estimates and similar | |
# SEs because there is only a single, categorical, variable in the model. | |
# if you add a continuous predictor, they will no longer, because the relationship | |
# assumed by the model will be different for the three models! | |
m <- glm(am ~ vs, data = mtcars, family = binomial) | |
em1 <- emmeans(m, "vs") |
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) | |
library(lubridate) | |
library(glue) | |
library(jsonlite) | |
library(cowplot) | |
# thanks to u/doubleunplussed on reddit for this dataset | |
json_url <- "https://pastebin.com/raw/gxZAUJwd" | |
ib_rate_data_orig <- fromJSON(json_url) |
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
# Using emmeans with metafor objects - "quick and dirty reference grid" | |
# usage: | |
# emmeans(qdrg_metafor(my_metafor_object), "categorical_var") | |
qdrg_metafor <- function(object) { | |
coefs <- coef(object) | |
names(coefs)[1] <- "(Intercept)" | |
vcovs <- vcov(object) | |
rownames(vcovs)[1] <- "(Intercept)" | |
colnames(vcovs)[1] <- "(Intercept)" | |
qdrg( |
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(dplyr) | |
library(glmmTMB) | |
nobs <- 100 | |
ngroup <- 5 | |
dat <- tibble( | |
x = sample(1:3, size = nobs, replace = TRUE, prob = c(0.15, 0.5, 0.35)), | |
y = runif(nobs), | |
z = case_when( | |
x == 1 ~ 0, |
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) | |
library(ggrepel) | |
library(ragg) | |
library(showtext) | |
showtext_auto() | |
font_add("AVHershey Complex Medium", "AVHersheyComplexMedium.ttf") | |
data(Animals, package = "MASS") |
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: "CLT rule of thumb demo" | |
author: "Cameron Patrick" | |
date: "2024-03-15" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set( | |
echo = TRUE, |