Skip to content

Instantly share code, notes, and snippets.

@chelseaparlett
Created December 15, 2021 22:12
Show Gist options
  • Save chelseaparlett/869c7dc960573c2982f09897482faf13 to your computer and use it in GitHub Desktop.
Save chelseaparlett/869c7dc960573c2982f09897482faf13 to your computer and use it in GitHub Desktop.
#libs--------------
library(grid)
library(tidyverse)
library(ggdark)
#funs--------------
irt <- function(a,b,c){
theta <- seq(-10,10, length = 500)
exponent <- exp(a*(theta-b))
phat <- c + (1-c)*(exponent/(1 + exponent))
return(data.frame(p = phat, theta = theta,
a = a, b = b, c = c))
}
#difficulty----
diff_df <- lapply(seq(-5,5,by = 1), function(x) irt(1,x,0))
diff_df <- do.call(rbind, diff_df)
ggplot(diff_df, aes(x = theta, y = p, color = factor(b))) +
geom_line(size = 1) +
dark_theme_grey() +
scale_y_continuous(limits = c(0,1),
breaks = c(0,0.5,1)) +
scale_x_continuous(limits = c(-10,10)) +
scale_color_discrete(name = "Difficulty") +
theme(panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
axis.title = element_text(size = 20),
axis.text = element_text(size = 15),
plot.title = element_text(size = 25)) +
labs(x = "Latent Trait Value",
y = "Predicted Probability",
title = "Logistic Curves for Items\nWith Different Difficulties")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment