Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created September 3, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpghayes/ecbe813abd48269b7a76b7277b0d9404 to your computer and use it in GitHub Desktop.
Save alexpghayes/ecbe813abd48269b7a76b7277b0d9404 to your computer and use it in GitHub Desktop.
library(readxl)
library(tidyverse)
library(caret)
library(brglm2)
df <- read_xlsx("~/../Desktop/190610-Data-All Studies.xlsx") %>%
filter(StudyNumber == 1) %>%
dplyr::mutate(
IsPhilosopher = map_lgl(Field, ~.x == "Philosophy")
) %>%
mutate_at(
vars(Knowledge, Field, Condition, IsPhilosopher),
as.factor
)
# use bias-restricted estimates because rank deficiency
fit <- glm(
Knowledge ~ Field * Condition,
data = df,
family = "binomial",
method = "brglmFit"
)
broom::tidy(fit, conf.int = TRUE) %>%
arrange(desc(abs(conf.low))) %>%
ggplot(aes(term, y = estimate, ymin = conf.low, ymax = conf.high)) +
geom_errorbar() +
coord_flip() +
labs(
title = "Confidence intervals for Experiment 1 coefficients",
y = "Logistic regression coefficient"
) +
theme_minimal() +
theme(
axis.title.y = element_blank()
)
ctrl <- trainControl(
method = "repeatedcv",
repeats = 10,
number = 10
)
train(
Knowledge ~ Field * Condition,
data = df,
method = "glm",
family = "binomial",
trControl = ctrl
)
train(
Knowledge ~ IsPhilosopher * Condition,
data = df,
method = "glm",
family = "binomial",
trControl = ctrl
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment