Created
September 3, 2020 15:53
-
-
Save alexpghayes/ecbe813abd48269b7a76b7277b0d9404 to your computer and use it in GitHub Desktop.
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(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