dat2 <- KHCE
l <- lapply(
split(ADLB, ADLB$ID),
function(x) coef(lm(AVAL ~ ADAY, data = x))[2])
new_slopes <- do.call(rbind, l)
new_slopes <- as.data.frame(new_slopes)
names(new_slopes) <- "LINEAR"
new_slopes$ID <- as.numeric(row.names(new_slopes))
dat2 <- merge(KHCE, new_slopes, by = "ID", all.x = TRUE)
dat2$AVAL0[dat2$PARAMCD == "eGFR"] <- dat2$LINEAR[dat2$PARAMCD == "eGFR"]
dat2$AVAL0[is.na(dat2$AVAL0)] <- 0
dat2 <- as_hce(dat2)
calcWO(dat2)
plot(dat2, last_outcome = "eGFR slope", remove_outliers = F, continuous_grid_spacing_x =.1) # Modifies the grid
plot(dat2, last_outcome = "eGFR slope", remove_outliers = T, continuous_grid_spacing_x =.1) # does not have any effect