compute_apar | R Documentation |
Compute adiposity peak (AP) and adiposity rebound (AR).
compute_apar(
fit,
from = c("predicted", "observed"),
start = 0.25,
end = 10,
step = 0.01,
filter = NULL
)
fit |
A model object from a statistical model
such as from a call |
from |
A string indicating the type of data to be used for the AP and AR computation, either "predicted" or "observed". Default is "predicted". |
start |
The start of the time window to compute AP and AR. |
end |
The end of the time window to compute AP and AR. |
step |
The step to increment the sequence. |
filter |
A string following |
A data.table
object.
library(eggla)
data("bmigrowth")
res <- egg_model(
formula = log(bmi) ~ age,
data = bmigrowth[bmigrowth[["sex"]] == 0, ],
id_var = "ID",
random_complexity = 1
)
head(compute_apar(fit = res, from = "predicted")[AP | AR])
# Comparing observed and predicted values
library(data.table)
library(ggplot2)
library(patchwork)
list_gg <- melt(
data = rbindlist(
l = lapply(
X = (function(.x) `names<-`(.x, .x))(c("predicted", "observed")),
FUN = compute_apar,
fit = res
),
idcol = "from"
)[
AP | AR
][
j = what := fifelse(paste(AP, AR) %in% paste(FALSE, TRUE), "AR", "AP")
],
id.vars = c("from", "egg_id", "what"),
measure.vars = c("egg_ageyears", "egg_bmi")
)[
j = list(gg = list({
dt <- dcast(data = .SD, formula = egg_id + what ~ from)
range_xy <- range(dt[, c("observed", "predicted")], na.rm = TRUE)
ggplot(data = dt) +
aes(x = observed, y = predicted, colour = what) +
geom_abline(intercept = 0, slope = 1) +
geom_segment(aes(xend = observed, yend = observed), alpha = 0.5) +
geom_point() +
scale_colour_manual(values = c("#E69F00FF", "#56B4E9FF")) +
labs(
x = sprintf("Observed: %s", sub(".*_", "", toupper(variable))),
y = sprintf("Predicted: %s", sub(".*_", "", toupper(variable))),
colour = NULL,
title = sub(".*_", "", toupper(variable))
) +
coord_cartesian(xlim = range_xy, ylim = range_xy)
})),
by = "variable"
]
wrap_plots(list_gg[["gg"]], guides = "collect")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.