library(tidyverse)
library(lme4)
library(marginaleffects)
model <- lmer(weight ~ Time + I(Time^2) + Diet*Time + (1 | Chick), data = ChickWeight)
# This is a shortcut for plotting predictions automatically
plot_predictions(model, condition = "Time")
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: "Fancy causal quartet" | |
date: 2024-09-06 | |
author: "Andrew Heiss" | |
--- | |
```{r} | |
#| warning: false | |
#| message: false |
library(MASS)
library(tidyverse)
library(marginaleffects)
library(palmerpenguins)
# Make a categorical weight column
penguins <- penguins |>
drop_na(sex) |>
mutate(weight_cat = cut(
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(brms) | |
library(marginaleffects) | |
library(tidybayes) | |
library(ggh4x) | |
library(scales) | |
# Ordered logit model | |
ologit_priors <- c( | |
prior(student_t(1, 0, 3), class = Intercept), |
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: "Testing with lots of plots" | |
--- | |
```{r} | |
#| label: fun-generate-chunks | |
#| include: false | |
generate_chunk <- function(id) { | |
paste0( |
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: "Testing" | |
--- | |
```{r} | |
#| label: fun-generate-chunks | |
#| include: false | |
generate_chunk <- function(id) { | |
paste0( |
library(tidyverse)
library(marginaleffects)
library(gapminder)
gapminder_2007 <- gapminder |>
filter(year == 2007)
# Use log() in the model formula
model <- lm(lifeExp ~ log(gdpPercap), data = gapminder_2007)
library(tidyverse)
library(mlogit)
library(dfidx)
library(marginaleffects)
chocolate <- read_csv("https://www.andrewheiss.com/blog/2023/08/12/conjoint-multilevel-multinomial-guide/data/choco_candy.csv") %>%
mutate(
dark = case_match(dark, 0 ~ "Milk", 1 ~ "Dark"),
dark = factor(dark, levels = c("Milk", "Dark")),
library(tidyverse)
library(palmerpenguins)
penguins <- penguins |> drop_na()
# This splits the dataset into three smaller datasets behind the scenes, but
# then doesn't do anything with them. But secretly it's waiting to do things
# within the three groups (hence the "Groups: species [3]") note
penguins |>
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(tinytable) | |
inline_listify <- function(x) { | |
numbers <- seq_along(x) | |
prefixed <- paste0("(", numbers, ") ", x) | |
collapsed <- paste(prefixed, collapse = "; ") | |
return(collapsed) | |
} |
NewerOlder