Show the code
library(tidyverse)
library(here)
theme_set(theme_bw(base_size = 12))
set.seed(1234)
This page shows examples of data generation for Emax model with and without covariates.
library(tidyverse)
library(here)
theme_set(theme_bw(base_size = 12))
set.seed(1234)
<- 20 # number of subjects
n <- 5 # effect at 0 concentration
E0 <- 10 # maximal effect
Emax <- 20 # concentration at half maximal effect
EC50 <- 2 # Hill coefficient
h
set.seed(130)
<- 50 * runif(n) # exposure
c.is
set.seed(130)
<- rnorm(n) # residual error
eps
<- E0 + ((Emax * c.is^h) / (c.is^h + EC50^h)) + eps
y.is
<- tibble(Conc = c.is, Y = y.is) d_example_emax_nocov
ggplot(d_example_emax_nocov, aes(Conc, Y)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess", se = F, col = "darkgrey") +
scale_x_continuous("Exposure", breaks = c(3, 10, 30, 100))
ggplot(d_example_emax_nocov, aes(Conc, Y)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess", se = F, col = "darkgrey") +
scale_x_log10("Exposure", breaks = c(3, 10, 30, 100))
Only one covariate (Prognostic factor positive/negative)
<- 2
Ngp <- 20 * Ngp
N <- as.factor(rep(c("A", "B"), each = 20))
GPid
# Set parameters
<- 5
E0 <- 15
EC50 <- 2
h <- .7
beta1
# Calc response
set.seed(12345)
<-
d_example_emax_cov tibble(GP = GPid) |>
mutate(
c.is = 50 * runif(N), eps = rnorm(N)
|>
) mutate(
Emax.i = ifelse(GP == "A", 10, 15)
|>
) mutate(y.is = E0 + ((Emax.i * c.is^h) / (c.is^h + EC50^h)) + eps) |>
mutate(Conc = c.is, Y = y.is)
ggplot(d_example_emax_cov, aes(Conc, Y)) +
geom_point(aes(colour = GP)) +
geom_smooth(aes(group = GP, colour = GP), se = F) +
scale_x_continuous("Exposure") +
theme(legend.position = "top")
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Only run in an interactive session so that the data is not saved every time the document is rendered (by setting eval: FALSE
).
write_csv(d_example_emax_nocov, here("data", "d_example_emax_nocov.csv"))
write_csv(d_example_emax_cov, here("data", "d_example_emax_cov.csv"))