# Example 1
set.seed(1)
dat_rater <- expand.grid(
id = factor(sprintf("s%02d", 1:8)),
method = factor(c("Device_A", "Device_B")),
time = factor(c("Rater_1", "Rater_2", "Rater_3")),
KEEP.OUT.ATTRS = FALSE
)
subj_eff <- rnorm(nlevels(dat_rater$id), sd = 1)[dat_rater$id]
method_shift <- c(Device_A = 0, Device_B = 0.25)[dat_rater$method]
rater_shift <- c(Rater_1 = 0, Rater_2 = 0.15, Rater_3 = -0.10)[dat_rater$time]
interaction_shift <- ifelse(
dat_rater$method == "Device_B" & dat_rater$time == "Rater_3",
0.12, 0
)
dat_rater$y <- subj_eff + method_shift + rater_shift +
interaction_shift + rnorm(nrow(dat_rater), sd = 0.25)
fit_rater <- cia_rm(
dat_rater,
response = "y",
subject = "id",
method = "method",
time = "time",
homogeneous = TRUE
)
print(fit_rater)
summary(fit_rater)
estimate(fit_rater)
tidy(fit_rater)
plot(fit_rater)
# Example 2
set.seed(2)
dat_time <- expand.grid(
id = factor(sprintf("s%02d", 1:10)),
method = factor(c("Assay_A", "Assay_B", "Assay_C", "Assay_D")),
time = factor(
c("baseline", "week2", "month1", "month2", "month3"),
levels = c("baseline", "week2", "month1", "month2", "month3")
),
KEEP.OUT.ATTRS = FALSE
)
subj_eff <- rnorm(nlevels(dat_time$id), sd = 0.9)[dat_time$id]
method_shift <- c(Assay_A = 0, Assay_B = 0.20, Assay_C = -0.10, Assay_D = 0.35)[dat_time$method]
time_shift <- c(
baseline = 0, week2 = 0.10, month1 = 0.22, month2 = 0.32, month3 = 0.42
)[dat_time$time]
interaction_shift <- ifelse(dat_time$method == "Assay_B" & dat_time$time == "month3", 0.10, 0) +
ifelse(dat_time$method == "Assay_D" & dat_time$time == "month2", -0.08, 0)
dat_time$y <- subj_eff + method_shift + time_shift +
interaction_shift + rnorm(nrow(dat_time), sd = 0.30)
fit_time <- cia_rm(
dat_time,
response = "y",
subject = "id",
method = "method",
time = "time",
ci = TRUE
)
print(fit_time)
plot(fit_time)
# Example 3
set.seed(3)
dat_days <- expand.grid(
id = factor(sprintf("s%02d", 1:12)),
method = factor(c("Sensor_A", "Sensor_B", "Sensor_C")),
time = 1:15,
KEEP.OUT.ATTRS = FALSE
)
subj_eff <- rnorm(nlevels(dat_days$id), sd = 0.8)[dat_days$id]
method_shift <- c(Sensor_A = 0, Sensor_B = 0.15, Sensor_C = -0.08)[dat_days$method]
day_trend <- 0.05 * dat_days$time
interaction_shift <- ifelse(dat_days$method == "Sensor_B", 0.01 * dat_days$time, 0) +
ifelse(dat_days$method == "Sensor_C", -0.005 * dat_days$time, 0)
dat_days$y <- subj_eff + method_shift + day_trend +
interaction_shift + rnorm(nrow(dat_days), sd = 0.22)
fit_days <- cia_rm(
dat_days,
response = "y",
subject = "id",
method = "method",
time = "time",
ci = TRUE
)
plot(fit_days, facet_by_pair = TRUE)
Run the code above in your browser using DataLab